|
1 |
| -# GitHub Action that uses Black to reformat the Python code in an incoming pull request. |
2 |
| -# If all Python code in the pull request is complient with Black then this Action does nothing. |
3 |
| -# Othewrwise, Black is run and its changes are committed back to the incoming pull request. |
| 1 | +# GitHub Action that uses Black to reformat Python code (if needed) when doing a git push. |
| 2 | +# If all Python code in the repo is complient with Black then this Action does nothing. |
| 3 | +# Otherwise, Black is run and its changes are committed to the repo. |
4 | 4 | # https://github.com/cclauss/autoblack
|
5 | 5 |
|
6 |
| -name: autoblack |
7 |
| -on: [pull_request] |
| 6 | +name: autoblack_push |
| 7 | +on: [push] |
8 | 8 | jobs:
|
9 | 9 | build:
|
10 | 10 | runs-on: ubuntu-latest
|
11 |
| - strategy: |
12 |
| - max-parallel: 1 |
13 |
| - matrix: |
14 |
| - python-version: [3.7] |
15 | 11 | steps:
|
16 | 12 | - uses: actions/checkout@v1
|
17 |
| - - name: Set up Python ${{ matrix.python-version }} |
18 |
| - uses: actions/setup-python@v1 |
19 |
| - with: |
20 |
| - python-version: ${{ matrix.python-version }} |
21 |
| - - name: Install psf/black |
22 |
| - run: pip install black |
23 |
| - - name: Run black --check . |
24 |
| - run: black --check . |
25 |
| - - name: If needed, commit black changes to the pull request |
| 13 | + - uses: actions/setup-python@v1 |
| 14 | + - run: pip install black |
| 15 | + - run: black --check . |
| 16 | + - name: If needed, commit black changes to a new pull request |
26 | 17 | if: failure()
|
27 | 18 | run: |
|
28 | 19 | black .
|
29 |
| - git config --global user.name 'autoblack' |
30 |
| - git config --global user.email 'cclauss@users.noreply.github.com' |
| 20 | + git config --global user.name github-actions |
| 21 | + git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com' |
31 | 22 | git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
|
32 |
| - git checkout $GITHUB_HEAD_REF |
33 |
| - git commit -am "fixup: Format Python code with psf/black" |
34 |
| - git push |
| 23 | + git commit -am "fixup! Format Python code with psf/black push" |
| 24 | + git push --force origin HEAD:$GITHUB_REF |
0 commit comments