backend-lint.yml 4.1 KB

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