backend-lint.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. # Note this uses a different cache key than other backend-based workflows because this workflows dependencies are different
  58. key: |
  59. precommit-${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}-${{ hashFiles('requirements-pre-commit.txt') }}
  60. restore-keys: |
  61. precommit-${{ runner.os }}-py${{ steps.python-version.outputs.python-version }}-pip${{ steps.pip.outputs.pip-version }}
  62. - name: Setup pre-commit
  63. if: steps.changes.outputs.backend == 'true'
  64. env:
  65. SENTRY_NO_VIRTUALENV_CREATION: 1
  66. run: |
  67. make setup-git
  68. - uses: getsentry/paths-filter@v2
  69. id: files
  70. with:
  71. # Enable listing of files matching each filter.
  72. # Paths to files will be available in `${FILTER_NAME}_files` output variable.
  73. # Paths will be escaped and space-delimited.
  74. # Output is usable as command line argument list in linux shell
  75. list-files: shell
  76. # It doesn't make sense to lint deleted files.
  77. # Therefore we specify we are only interested in added or modified files.
  78. filters: |
  79. all:
  80. - added|modified: '**/*.py'
  81. - added|modified: 'requirements-base.txt'
  82. - name: Run pre-commit on changed files
  83. if: steps.changes.outputs.backend == 'true'
  84. run: |
  85. # Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
  86. # XXX: there is a very small chance that it'll expand to exceed Linux's limits
  87. # `getconf ARG_MAX` - max # bytes of args + environ for exec()
  88. pre-commit run --files ${{ steps.files.outputs.all_files }}
  89. # If working tree is dirty, commit and update if we have a token
  90. - name: Apply any pre-commit fixed files
  91. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && steps.changes.outputs.backend == 'true' && always()
  92. uses: getsentry/action-github-commit@main
  93. with:
  94. github-token: ${{ steps.token.outputs.token }}
  95. - name: Handle artifacts
  96. uses: ./.github/actions/artifacts