backend-lint.yml 3.4 KB

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