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:
|
2020-03-13 08:23:38 +00:00
|
|
|
- uses: actions/checkout@v1 # Use v1, NOT v2
|
2020-05-16 06:49:56 +00:00
|
|
|
- uses: actions/setup-python@v2
|
2020-07-06 03:18:18 +00:00
|
|
|
- run: pip install black isort
|
2019-11-14 18:59:43 +00:00
|
|
|
- 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 .
|
2020-07-06 07:44:19 +00:00
|
|
|
isort --profile black .
|
2019-11-14 18:59:43 +00:00
|
|
|
git config --global user.name github-actions
|
2020-09-30 08:38:00 +00:00
|
|
|
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
|