pre-commit.yml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. name: pre-commit
  2. on:
  3. push:
  4. branches:
  5. - master
  6. pull_request:
  7. # Cancel in progress workflows on pull_requests.
  8. # https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
  9. concurrency:
  10. group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  11. cancel-in-progress: true
  12. defaults:
  13. run:
  14. # the default default is:
  15. # bash --noprofile --norc -eo pipefail {0}
  16. shell: bash --noprofile --norc -eo pipefail -ux {0}
  17. # hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
  18. env:
  19. SEGMENT_DOWNLOAD_TIMEOUT_MINS: 3
  20. jobs:
  21. lint:
  22. name: pre-commit lint
  23. runs-on: ubuntu-20.04
  24. timeout-minutes: 10
  25. steps:
  26. - uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
  27. id: token
  28. with:
  29. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  30. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  31. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  32. - name: Get changed files
  33. id: changes
  34. uses: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
  35. with:
  36. token: ${{ steps.token.outputs.token }}
  37. # Enable listing of files matching each filter.
  38. # Paths to files will be available in `${FILTER_NAME}_files` output variable.
  39. list-files: json
  40. # It doesn't make sense to lint deleted files.
  41. # Therefore we specify we are only interested in added or modified files.
  42. filters: |
  43. all:
  44. - added|modified: '**/*'
  45. - uses: getsentry/action-setup-venv@9e3bbae3836b1b6f129955bf55a19e1d99a61c67 # v1.0.5
  46. with:
  47. python-version: 3.8.16
  48. cache-dependency-path: |
  49. requirements-dev.txt
  50. requirements-dev-frozen.txt
  51. install-cmd: pip install -r requirements-dev.txt -c requirements-dev-frozen.txt
  52. - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  53. with:
  54. path: ~/.cache/pre-commit
  55. key: cache-epoch-1|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
  56. - name: Setup pre-commit
  57. # We don't use make setup-git because we're only interested in installing
  58. # requirements-dev.txt as a fast path.
  59. # We don't need pre-commit install --install-hooks since we're just interested
  60. # in running the hooks.
  61. run: |
  62. pre-commit install-hooks
  63. - name: Run pre-commit on PR commits
  64. run: |
  65. jq '.[]' --raw-output <<< '${{steps.changes.outputs.all_files}}' |
  66. # Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
  67. xargs pre-commit run --files
  68. - name: Apply any pre-commit fixed files
  69. if: startsWith(github.ref, 'refs/pull')
  70. uses: getsentry/action-github-commit@748c31dd78cffe76f51bef49a0be856b6effeda7 # v1.1.0
  71. with:
  72. github-token: ${{ steps.token.outputs.token }}
  73. message: ':hammer_and_wrench: apply pre-commit fixes'