backend.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. name: backend
  2. on:
  3. push:
  4. branches:
  5. - master
  6. pull_request:
  7. # Cancel in progress workflows on pull_requests.
  8. # https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
  9. concurrency:
  10. group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  11. cancel-in-progress: true
  12. # hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
  13. env:
  14. SEGMENT_DOWNLOAD_TIMEOUT_MINS: 3
  15. jobs:
  16. files-changed:
  17. name: detect what files changed
  18. runs-on: ubuntu-22.04
  19. timeout-minutes: 3
  20. # Map a step output to a job output
  21. outputs:
  22. api_docs: ${{ steps.changes.outputs.api_docs }}
  23. backend: ${{ steps.changes.outputs.backend_all }}
  24. backend_dependencies: ${{ steps.changes.outputs.backend_dependencies }}
  25. backend_any_type: ${{ steps.changes.outputs.backend_any_type }}
  26. migration_lockfile: ${{ steps.changes.outputs.migration_lockfile }}
  27. steps:
  28. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  29. - name: Check for backend file changes
  30. uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
  31. id: changes
  32. with:
  33. token: ${{ github.token }}
  34. filters: .github/file-filters.yml
  35. api-docs:
  36. if: needs.files-changed.outputs.api_docs == 'true'
  37. needs: files-changed
  38. name: api docs test
  39. runs-on: ubuntu-22.04
  40. steps:
  41. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  42. - uses: getsentry/action-setup-volta@e4939d337b83760d13a9d7030a6f68c9d0ee7581 # v2.0.0
  43. - name: Setup sentry python env
  44. uses: ./.github/actions/setup-sentry
  45. id: setup
  46. with:
  47. snuba: true
  48. - name: Run API docs tests
  49. # install ts-node for ts build scripts to execute properly without potentially installing
  50. # conflicting deps when running scripts locally
  51. # see: https://github.com/getsentry/sentry/pull/32328/files
  52. run: |
  53. yarn add ts-node && make test-api-docs
  54. backend-test:
  55. if: needs.files-changed.outputs.backend == 'true'
  56. needs: files-changed
  57. name: backend test
  58. runs-on: ubuntu-22.04
  59. timeout-minutes: 60
  60. permissions:
  61. contents: read
  62. id-token: write
  63. strategy:
  64. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  65. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  66. fail-fast: false
  67. matrix:
  68. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  69. instance: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  70. pg-version: ['14']
  71. env:
  72. # XXX: `MATRIX_INSTANCE_TOTAL` must be hardcoded to the length of `strategy.matrix.instance`.
  73. # If this increases, make sure to also increase `flags.backend.after_n_builds` in `codecov.yml`.
  74. MATRIX_INSTANCE_TOTAL: 11
  75. steps:
  76. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  77. with:
  78. # Avoid codecov error message related to SHA resolution:
  79. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  80. fetch-depth: '2'
  81. - name: Setup sentry env
  82. uses: ./.github/actions/setup-sentry
  83. id: setup
  84. with:
  85. redis_cluster: true
  86. kafka: true
  87. snuba: true
  88. symbolicator: true
  89. # Right now, we run so few bigtable related tests that the
  90. # overhead of running bigtable in all backend tests
  91. # is way smaller than the time it would take to run in its own job.
  92. bigtable: true
  93. pg-version: ${{ matrix.pg-version }}
  94. - name: Run backend test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  95. run: |
  96. make test-python-ci
  97. - name: Collect test data
  98. uses: ./.github/actions/collect-test-data
  99. if: ${{ !cancelled() }}
  100. with:
  101. artifact_path: .artifacts/pytest.json
  102. gcs_bucket: ${{ secrets.COLLECT_TEST_DATA_GCS_BUCKET }}
  103. gcp_project_id: ${{ secrets.COLLECT_TEST_DATA_GCP_PROJECT_ID }}
  104. workload_identity_provider: ${{ secrets.SENTRY_GCP_DEV_WORKLOAD_IDENTITY_POOL }}
  105. service_account_email: ${{ secrets.COLLECT_TEST_DATA_SERVICE_ACCOUNT_EMAIL }}
  106. matrix_instance_number: ${{ steps.setup.outputs.matrix-instance-number }}
  107. # Upload coverage data even if running the tests step fails since
  108. # it reduces large coverage fluctuations
  109. - name: Handle artifacts
  110. if: ${{ always() }}
  111. uses: ./.github/actions/artifacts
  112. with:
  113. token: ${{ secrets.CODECOV_TOKEN }}
  114. backend-migration-tests:
  115. if: needs.files-changed.outputs.backend == 'true'
  116. needs: files-changed
  117. name: backend migration tests
  118. runs-on: ubuntu-22.04
  119. timeout-minutes: 30
  120. strategy:
  121. matrix:
  122. pg-version: ['14']
  123. steps:
  124. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  125. with:
  126. # Avoid codecov error message related to SHA resolution:
  127. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  128. fetch-depth: '2'
  129. - name: Setup sentry env
  130. uses: ./.github/actions/setup-sentry
  131. id: setup
  132. with:
  133. snuba: true
  134. pg-version: ${{ matrix.pg-version }}
  135. - name: run tests
  136. run: |
  137. PYTEST_ADDOPTS="$PYTEST_ADDOPTS -m migrations --migrations --reruns 0" make test-python-ci
  138. # Upload coverage data even if running the tests step fails since
  139. # it reduces large coverage fluctuations
  140. - name: Handle artifacts
  141. if: ${{ always() }}
  142. uses: ./.github/actions/artifacts
  143. with:
  144. token: ${{ secrets.CODECOV_TOKEN }}
  145. cli:
  146. if: needs.files-changed.outputs.backend == 'true'
  147. needs: files-changed
  148. name: cli test
  149. runs-on: ubuntu-22.04
  150. timeout-minutes: 10
  151. strategy:
  152. matrix:
  153. pg-version: ['14']
  154. steps:
  155. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  156. - name: Setup sentry env
  157. uses: ./.github/actions/setup-sentry
  158. id: setup
  159. with:
  160. pg-version: ${{ matrix.pg-version }}
  161. - name: Run test
  162. run: |
  163. make test-cli
  164. # Upload coverage data even if running the tests step fails since
  165. # it reduces large coverage fluctuations
  166. - name: Handle artifacts
  167. if: ${{ always() }}
  168. uses: ./.github/actions/artifacts
  169. with:
  170. token: ${{ secrets.CODECOV_TOKEN }}
  171. requirements:
  172. if: needs.files-changed.outputs.backend_dependencies == 'true'
  173. needs: files-changed
  174. name: requirements check
  175. runs-on: ubuntu-22.04
  176. timeout-minutes: 3
  177. steps:
  178. - uses: getsentry/action-github-app-token@d4b5da6c5e37703f8c3b3e43abb5705b46e159cc # v3.0.0
  179. id: token
  180. continue-on-error: true
  181. with:
  182. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  183. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  184. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  185. - uses: getsentry/action-setup-venv@a133e6fd5fa6abd3f590a1c106abda344f5df69f # v2.1.0
  186. with:
  187. python-version: 3.11.9
  188. cache-dependency-path: requirements-dev-frozen.txt
  189. install-cmd: python3 -m tools.hack_pip && pip install -q --constraint requirements-dev-frozen.txt pip-tools
  190. - name: check requirements
  191. run: |
  192. python -S -m tools.freeze_requirements
  193. if ! git diff --exit-code; then
  194. echo $'\n\nrun `make freeze-requirements` locally to update requirements'
  195. exit 1
  196. fi
  197. - name: apply any requirements changes
  198. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  199. uses: getsentry/action-github-commit@31f6706ca1a7b9ad6d22c1b07bf3a92eabb05632 # v2.0.0
  200. with:
  201. github-token: ${{ steps.token.outputs.token }}
  202. message: ':snowflake: re-freeze requirements'
  203. migration:
  204. if: needs.files-changed.outputs.migration_lockfile == 'true'
  205. needs: files-changed
  206. name: check migration
  207. runs-on: ubuntu-22.04
  208. strategy:
  209. matrix:
  210. pg-version: ['14']
  211. steps:
  212. - name: Checkout sentry
  213. uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  214. - name: Setup sentry env
  215. uses: ./.github/actions/setup-sentry
  216. id: setup
  217. with:
  218. pg-version: ${{ matrix.pg-version }}
  219. - name: Migration & lockfile checks
  220. env:
  221. SENTRY_LOG_LEVEL: ERROR
  222. PGPASSWORD: postgres
  223. run: |
  224. ./.github/workflows/scripts/migration-check.sh
  225. monolith-dbs:
  226. if: needs.files-changed.outputs.backend == 'true'
  227. needs: files-changed
  228. name: monolith-dbs test
  229. runs-on: ubuntu-22.04
  230. timeout-minutes: 20
  231. permissions:
  232. contents: read
  233. id-token: write
  234. steps:
  235. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  236. with:
  237. # Avoid codecov error message related to SHA resolution:
  238. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  239. fetch-depth: '2'
  240. - name: Setup sentry env
  241. uses: ./.github/actions/setup-sentry
  242. id: setup
  243. - name: Run test
  244. run: |
  245. make test-monolith-dbs
  246. - name: Collect test data
  247. uses: ./.github/actions/collect-test-data
  248. if: ${{ !cancelled() }}
  249. with:
  250. artifact_path: .artifacts/pytest.monolith-dbs.json
  251. gcs_bucket: ${{ secrets.COLLECT_TEST_DATA_GCS_BUCKET }}
  252. gcp_project_id: ${{ secrets.COLLECT_TEST_DATA_GCP_PROJECT_ID }}
  253. workload_identity_provider: ${{ secrets.SENTRY_GCP_DEV_WORKLOAD_IDENTITY_POOL }}
  254. service_account_email: ${{ secrets.COLLECT_TEST_DATA_SERVICE_ACCOUNT_EMAIL }}
  255. # Upload coverage data even if running the tests step fails since
  256. # it reduces large coverage fluctuations
  257. - name: Handle artifacts
  258. if: ${{ always() }}
  259. uses: ./.github/actions/artifacts
  260. with:
  261. token: ${{ secrets.CODECOV_TOKEN }}
  262. typing:
  263. if: needs.files-changed.outputs.backend == 'true'
  264. needs: files-changed
  265. name: backend typing
  266. runs-on: ubuntu-22.04
  267. timeout-minutes: 20
  268. steps:
  269. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  270. - uses: getsentry/action-setup-venv@a133e6fd5fa6abd3f590a1c106abda344f5df69f # v2.1.0
  271. with:
  272. python-version: 3.11.9
  273. cache-dependency-path: requirements-dev-frozen.txt
  274. install-cmd: python3 -m tools.hack_pip && pip install -r requirements-dev-frozen.txt
  275. - name: setup sentry (lite)
  276. run: |
  277. python3 -m tools.fast_editable --path .
  278. sentry init
  279. - run: mypy
  280. id: run
  281. - uses: getsentry/action-github-app-token@d4b5da6c5e37703f8c3b3e43abb5705b46e159cc # v3.0.0
  282. id: token
  283. continue-on-error: true
  284. with:
  285. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  286. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  287. # only if `mypy` succeeds should we try and trim the blocklist
  288. - run: python3 -m tools.mypy_helpers.make_module_ignores
  289. id: regen-blocklist
  290. - run: git diff --exit-code
  291. - run: |
  292. # mypy does not have granular codes so don't allow specific messages to regress
  293. ! grep "'Settings' object has no attribute" .artifacts/mypy-all
  294. ! grep 'Cannot override class variable' .artifacts/mypy-all
  295. ! grep 'Exception type must be derived from BaseException' .artifacts/mypy-all
  296. ! grep 'Incompatible default for argument' .artifacts/mypy-all
  297. ! grep 'Incompatible return value type (got "HttpResponseBase"' .artifacts/mypy-all
  298. ! grep 'Incompatible types in "yield"' .artifacts/mypy-all
  299. ! grep 'Module "sentry.*has no attribute' .artifacts/mypy-all
  300. ! grep 'base class .* defined the type as.*Permission' .artifacts/mypy-all
  301. ! grep 'does not explicitly export attribute' .artifacts/mypy-all
  302. - name: apply blocklist changes
  303. if: |
  304. steps.token.outcome == 'success' &&
  305. steps.run.outcome == 'success' &&
  306. steps.regen-blocklist.outcome == 'success' &&
  307. github.ref != 'refs/heads/master' &&
  308. always()
  309. uses: getsentry/action-github-commit@31f6706ca1a7b9ad6d22c1b07bf3a92eabb05632 # v2.0.0
  310. with:
  311. github-token: ${{ steps.token.outputs.token }}
  312. message: ':knife: regenerate mypy module blocklist'
  313. # This check runs once all dependent jobs have passed
  314. # It symbolizes that all required Backend checks have succesfully passed (Or skipped)
  315. # This step is the only required backend check
  316. backend-required-check:
  317. needs:
  318. [
  319. api-docs,
  320. backend-test,
  321. backend-migration-tests,
  322. cli,
  323. files-changed,
  324. requirements,
  325. migration,
  326. monolith-dbs,
  327. typing,
  328. ]
  329. name: Backend
  330. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  331. if: always()
  332. runs-on: ubuntu-22.04
  333. steps:
  334. # If any jobs we depend on fail, we will fail since this is a required check
  335. # NOTE: A timeout is considered a failure
  336. - name: Check for failures
  337. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  338. run: |
  339. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1