2019-11-14 18:59:43 +00:00
|
|
|
# GitHub Action that uses Black to reformat Python code (if needed) when doing a git push.
|
2019-11-28 18:53:37 +00:00
|
|
|
# If all Python code in the repo is compliant with Black then this Action does nothing.
|
2019-11-14 18:59:43 +00:00
|
|
|
# Otherwise, Black is run and its changes are committed to the repo.
|
2019-10-31 17:45:01 +00:00
|
|
|
# https://github.com/cclauss/autoblack
|
|
|
|
|
2019-11-14 18:59:43 +00:00
|
|
|
name: autoblack_push
|
|
|
|
on: [push]
|
2019-10-31 17:45:01 +00:00
|
|
|
jobs:
|
|
|
|
build:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v1
|
2019-11-14 18:59:43 +00:00
|
|
|
- uses: actions/setup-python@v1
|
|
|
|
- run: pip install black
|
|
|
|
- run: black --check .
|
|
|
|
- name: If needed, commit black changes to a new pull request
|
2019-10-31 17:45:01 +00:00
|
|
|
if: failure()
|
|
|
|
run: |
|
|
|
|
black .
|
2019-11-14 18:59:43 +00:00
|
|
|
git config --global user.name github-actions
|
|
|
|
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
|
2019-10-31 17:45:01 +00:00
|
|
|
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
|
2019-11-14 18:59:43 +00:00
|
|
|
git commit -am "fixup! Format Python code with psf/black push"
|
|
|
|
git push --force origin HEAD:$GITHUB_REF
|