commit-format.yml 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # This is a basic workflow to help you get started with Actions
  2. name: Commit Format and Import Sort
  3. # Controls when the action will run.
  4. on:
  5. # Triggers the workflow on push or pull request events but only for the master branch
  6. pull_request:
  7. branches: [ master ]
  8. # push:
  9. # branches: [ master ]
  10. # A workflow run is made up of one or more jobs that can run sequentially or in parallel
  11. jobs:
  12. check:
  13. runs-on: ubuntu-latest
  14. steps:
  15. - uses: actions/checkout@v2
  16. with: # https://github.com/stefanzweifel/git-auto-commit-action#checkout-the-correct-branch
  17. ref: ${{ github.head_ref }}
  18. - uses: actions/setup-python@v2
  19. - run: pip install black isort
  20. - run: black --check .
  21. - run: isort --check .
  22. - name: Commit isort changes to pull request
  23. if: failure()
  24. run: |
  25. git config --global user.name 'ndbeals'
  26. git config --global user.email 'ndbeals@users.noreply.github.com'
  27. git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
  28. isort .
  29. black .
  30. echo ready to commit
  31. git commit -am "Code formatted with black, imports sorted with isort"
  32. git status
  33. echo ready to push
  34. git push