|
| 1 | +# GitHub Action that uses Black to reformat all Python code and submits a PR |
| 2 | +# in regular intervals. Inspired by: https://github.com/cclauss/autoblack |
| 3 | + |
| 4 | +name: autoblack |
| 5 | +on: |
| 6 | + workflow_dispatch: # allow manual trigger |
| 7 | + schedule: |
| 8 | + - cron: '0 8 * * 5' # every Friday at 8am UTC |
| 9 | + |
| 10 | +jobs: |
| 11 | + autoblack: |
| 12 | + if: github.repository_owner == 'explosion' |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v2 |
| 16 | + with: |
| 17 | + ref: ${{ github.head_ref }} |
| 18 | + - uses: actions/setup-python@v2 |
| 19 | + - run: pip install black |
| 20 | + - name: Auto-format code if needed |
| 21 | + run: black thinc |
| 22 | + # We can't run black --check here because that returns a non-zero excit |
| 23 | + # code and makes GitHub think the action failed |
| 24 | + - name: Check for modified files |
| 25 | + id: git-check |
| 26 | + run: echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi) |
| 27 | + - name: Create Pull Request |
| 28 | + if: steps.git-check.outputs.modified == 'true' |
| 29 | + uses: peter-evans/create-pull-request@v3 |
| 30 | + with: |
| 31 | + title: Auto-format code with black |
| 32 | + labels: meta |
| 33 | + commit-message: Auto-format code with black |
| 34 | + committer: GitHub <[email protected]> |
| 35 | + author: explosion-bot <[email protected]> |
| 36 | + body: _This PR is auto-generated._ |
| 37 | + branch: autoblack |
| 38 | + delete-branch: true |
| 39 | + draft: false |
| 40 | + - name: Check outputs |
| 41 | + if: steps.git-check.outputs.modified == 'true' |
| 42 | + run: | |
| 43 | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" |
| 44 | + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" |
0 commit comments