backend-lint.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. name: backend lint
  2. on:
  3. push:
  4. branches:
  5. - master
  6. - releases/**
  7. pull_request:
  8. jobs:
  9. lint:
  10. name: backend lint
  11. runs-on: ubuntu-20.04
  12. timeout-minutes: 10
  13. steps:
  14. - uses: actions/checkout@v2
  15. - name: Internal github app token
  16. id: token
  17. uses: getsentry/action-github-app-token@v1
  18. continue-on-error: true
  19. with:
  20. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  21. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  22. # If we make these jobs "required" to merge on GH, then on every PR, GitHub automatically
  23. # creates a status check in the "pending" state. This means that the workflow needs to run
  24. # for every PR in order to update the status checks.
  25. #
  26. # In order to optimize CI usage, we want the tests to only run when python files change,
  27. # since frontend changes should have no effect on these test suites. We cannot use GH workflow
  28. # path filters because entire workflow would be skipped vs skipping individual jobs which
  29. # would still allow this status check to pass.
  30. - name: Check for python file changes
  31. uses: getsentry/paths-filter@v2
  32. id: changes
  33. with:
  34. token: ${{ github.token }}
  35. filters: .github/file-filters.yml
  36. - name: Set python version output
  37. id: python-version
  38. if: steps.changes.outputs.backend == 'true'
  39. run: |
  40. echo "::set-output name=python-version::$(cat .python-version)"
  41. # Until GH composite actions can use `uses`, we need to setup python here
  42. - uses: actions/setup-python@v2
  43. if: steps.changes.outputs.backend == 'true'
  44. env:
  45. PIP_DISABLE_PIP_VERSION_CHECK: on
  46. with:
  47. python-version: ${{ steps.python-version.outputs.python-version }}
  48. - name: Setup pip
  49. uses: ./.github/actions/setup-pip
  50. if: steps.changes.outputs.backend == 'true'
  51. id: pip
  52. - name: pip cache
  53. uses: actions/cache@v2
  54. if: steps.changes.outputs.backend == 'true'
  55. with:
  56. path: ${{ steps.pip.outputs.pip-cache-dir }}
  57. key: ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ hashFiles('**/requirements-*.txt') }}
  58. restore-keys: |
  59. ${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}
  60. - name: Setup pre-commit
  61. if: steps.changes.outputs.backend == 'true'
  62. env:
  63. SENTRY_NO_VIRTUALENV_CREATION: 1
  64. run: |
  65. make setup-git
  66. - uses: getsentry/paths-filter@v2
  67. id: files
  68. with:
  69. # Enable listing of files matching each filter.
  70. # Paths to files will be available in `${FILTER_NAME}_files` output variable.
  71. # Paths will be escaped and space-delimited.
  72. # Output is usable as command line argument list in linux shell
  73. list-files: shell
  74. # It doesn't make sense to lint deleted files.
  75. # Therefore we specify we are only interested in added or modified files.
  76. filters: |
  77. all:
  78. - added|modified: '**/*.py'
  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