backend.yml 14 KB

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