backend-lint.yml 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. name: backend lint
  2. on:
  3. push:
  4. branches:
  5. - master
  6. pull_request:
  7. jobs:
  8. lint:
  9. name: backend lint
  10. runs-on: ubuntu-18.04
  11. timeout-minutes: 10
  12. strategy:
  13. matrix:
  14. python-version: [3.8.12]
  15. steps:
  16. - uses: actions/checkout@v2
  17. - name: Internal github app token
  18. id: token
  19. uses: getsentry/action-github-app-token@v1
  20. continue-on-error: true
  21. with:
  22. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  23. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  24. # If we make these jobs "required" to merge on GH, then on every PR, GitHub automatically
  25. # creates a status check in the "pending" state. This means that the workflow needs to run
  26. # for every PR in order to update the status checks.
  27. #
  28. # In order to optimize CI usage, we want the tests to only run when python files change,
  29. # since frontend changes should have no effect on these test suites. We cannot use GH workflow
  30. # path filters because entire workflow would be skipped vs skipping individual jobs which
  31. # would still allow this status check to pass.
  32. - name: Check for python file changes
  33. uses: getsentry/paths-filter@v2
  34. id: changes
  35. with:
  36. token: ${{ github.token }}
  37. filters: .github/file-filters.yml
  38. - name: Setup Python ${{ matrix.python-version }}
  39. uses: ./.github/actions/setup-python
  40. if: steps.changes.outputs.backend == 'true'
  41. with:
  42. python-version: ${{ matrix.python-version }}
  43. # Note this uses a different cache key than other backend-based workflows because this workflows dependencies are different
  44. cache-files-hash: ${{ hashFiles('requirements-pre-commit.txt') }}
  45. - name: Setup pre-commit
  46. if: steps.changes.outputs.backend == 'true'
  47. env:
  48. SENTRY_NO_VIRTUALENV_CREATION: 1
  49. run: |
  50. make setup-git
  51. - uses: getsentry/paths-filter@v2
  52. id: files
  53. with:
  54. # Enable listing of files matching each filter.
  55. # Paths to files will be available in `${FILTER_NAME}_files` output variable.
  56. # Paths will be escaped and space-delimited.
  57. # Output is usable as command line argument list in linux shell
  58. list-files: shell
  59. # It doesn't make sense to lint deleted files.
  60. # Therefore we specify we are only interested in added or modified files.
  61. filters: |
  62. all:
  63. - added|modified: '**/*.py'
  64. - added|modified: 'requirements-base.txt'
  65. - name: Run pre-commit on changed files
  66. if: steps.changes.outputs.backend == 'true'
  67. run: |
  68. # Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
  69. # XXX: there is a very small chance that it'll expand to exceed Linux's limits
  70. # `getconf ARG_MAX` - max # bytes of args + environ for exec()
  71. pre-commit run --files ${{ steps.files.outputs.all_files }}
  72. # If working tree is dirty, commit and update if we have a token
  73. - name: Apply any pre-commit fixed files
  74. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && steps.changes.outputs.backend == 'true' && always()
  75. uses: getsentry/action-github-commit@main
  76. with:
  77. github-token: ${{ steps.token.outputs.token }}
  78. - name: Handle artifacts
  79. uses: ./.github/actions/artifacts