mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 05:21:09 +00:00
0a42ae9095
* Fix all errors mentioned in pre-commit run: - Fix end of file - Remove trailing whitespace - Fix files with black - Fix imports with isort * Fix errors
26 lines
1.0 KiB
YAML
26 lines
1.0 KiB
YAML
# GitHub Action that uses Black to reformat Python code (if needed) when doing a git push.
|
|
# If all Python code in the repo is compliant with Black then this Action does nothing.
|
|
# Otherwise, Black is run and its changes are committed to the repo.
|
|
# https://github.com/cclauss/autoblack
|
|
|
|
name: autoblack_push
|
|
on: [push]
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v1 # Use v1, NOT v2
|
|
- uses: actions/setup-python@v2
|
|
- run: pip install black isort
|
|
- run: black --check .
|
|
- name: If needed, commit black changes to a new pull request
|
|
if: failure()
|
|
run: |
|
|
black .
|
|
isort --profile black .
|
|
git config --global user.name github-actions
|
|
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
|
|
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
|
|
git commit -am "fixup! Format Python code with psf/black push"
|
|
git push --force origin HEAD:$GITHUB_REF
|