backend.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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-20.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. plugins: ${{ steps.changes.outputs.plugins }}
  28. steps:
  29. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  30. - name: Check for backend file changes
  31. uses: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
  32. id: changes
  33. with:
  34. token: ${{ github.token }}
  35. filters: .github/file-filters.yml
  36. api-docs:
  37. if: needs.files-changed.outputs.api_docs == 'true'
  38. needs: files-changed
  39. name: api docs test
  40. runs-on: ubuntu-20.04
  41. steps:
  42. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  43. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  44. - name: Setup sentry python env
  45. uses: ./.github/actions/setup-sentry
  46. id: setup
  47. with:
  48. snuba: true
  49. - name: Run API docs tests
  50. # install ts-node for ts build scripts to execute properly without potentially installing
  51. # conflicting deps when running scripts locally
  52. # see: https://github.com/getsentry/sentry/pull/32328/files
  53. run: |
  54. yarn add ts-node && make test-api-docs
  55. backend-test:
  56. if: needs.files-changed.outputs.backend == 'true'
  57. needs: files-changed
  58. name: backend test
  59. runs-on: ubuntu-20.04
  60. timeout-minutes: 40
  61. strategy:
  62. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  63. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  64. fail-fast: false
  65. matrix:
  66. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  67. instance: [0, 1, 2, 3, 4, 5, 6]
  68. pg-version: ['14']
  69. env:
  70. # XXX: `MATRIX_INSTANCE_TOTAL` must be hardcoded to the length of `strategy.matrix.instance`.
  71. # If this increases, make sure to also increase `flags.backend.after_n_builds` in `codecov.yml`.
  72. MATRIX_INSTANCE_TOTAL: 7
  73. steps:
  74. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  75. with:
  76. # Avoid codecov error message related to SHA resolution:
  77. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  78. fetch-depth: '2'
  79. - name: Update environment for silo databases
  80. if: |
  81. contains( github.event.pull_request.labels.*.name, 'Trigger: Silo db' )
  82. run: |
  83. echo "SENTRY_USE_SPLIT_DBS=1" >> "$GITHUB_ENV"
  84. - name: Setup sentry env
  85. uses: ./.github/actions/setup-sentry
  86. id: setup
  87. with:
  88. snuba: 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. # Upload coverage data even if running the tests step fails since
  98. # it reduces large coverage fluctuations
  99. - name: Handle artifacts
  100. if: ${{ always() }}
  101. uses: ./.github/actions/artifacts
  102. with:
  103. token: ${{ secrets.CODECOV_TOKEN }}
  104. backend-migration-tests:
  105. if: needs.files-changed.outputs.backend == 'true'
  106. needs: files-changed
  107. name: backend migration tests
  108. runs-on: ubuntu-20.04
  109. timeout-minutes: 30
  110. strategy:
  111. matrix:
  112. pg-version: ['14']
  113. steps:
  114. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  115. with:
  116. # Avoid codecov error message related to SHA resolution:
  117. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  118. fetch-depth: '2'
  119. - name: Update environment for silo databases
  120. id: silo_env
  121. if: |
  122. contains( github.event.pull_request.labels.*.name, 'Trigger: Silo db' )
  123. run: |
  124. echo "SENTRY_USE_SPLIT_DBS=1" >> "$GITHUB_ENV"
  125. - name: Setup sentry env
  126. uses: ./.github/actions/setup-sentry
  127. id: setup
  128. with:
  129. snuba: true
  130. pg-version: ${{ matrix.pg-version }}
  131. - name: run tests
  132. run: |
  133. MIGRATIONS_TEST_MIGRATE=1 PYTEST_ADDOPTS="$PYTEST_ADDOPTS -m migrations" make test-python-ci
  134. # Upload coverage data even if running the tests step fails since
  135. # it reduces large coverage fluctuations
  136. - name: Handle artifacts
  137. if: ${{ always() }}
  138. uses: ./.github/actions/artifacts
  139. with:
  140. token: ${{ secrets.CODECOV_TOKEN }}
  141. cli:
  142. if: needs.files-changed.outputs.backend == 'true'
  143. needs: files-changed
  144. name: cli test
  145. runs-on: ubuntu-20.04
  146. timeout-minutes: 10
  147. strategy:
  148. matrix:
  149. pg-version: ['14']
  150. steps:
  151. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  152. - name: Update environment for silo databases
  153. if: |
  154. contains( github.event.pull_request.labels.*.name, 'Trigger: Silo db' )
  155. run: |
  156. echo "SENTRY_USE_SPLIT_DBS=1" >> "$GITHUB_ENV"
  157. - name: Setup sentry env
  158. uses: ./.github/actions/setup-sentry
  159. id: setup
  160. with:
  161. pg-version: ${{ matrix.pg-version }}
  162. - name: Run test
  163. run: |
  164. make test-cli
  165. # Upload coverage data even if running the tests step fails since
  166. # it reduces large coverage fluctuations
  167. - name: Handle artifacts
  168. if: ${{ always() }}
  169. uses: ./.github/actions/artifacts
  170. with:
  171. token: ${{ secrets.CODECOV_TOKEN }}
  172. requirements:
  173. if: needs.files-changed.outputs.backend_dependencies == 'true'
  174. needs: files-changed
  175. name: requirements check
  176. runs-on: ubuntu-20.04
  177. timeout-minutes: 3
  178. steps:
  179. - uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
  180. id: token
  181. continue-on-error: true
  182. with:
  183. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  184. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  185. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  186. - uses: getsentry/action-setup-venv@9e3bbae3836b1b6f129955bf55a19e1d99a61c67 # v1.0.5
  187. with:
  188. python-version: 3.8.16
  189. cache-depedency: requirements-dev-frozen.txt
  190. install-cmd: pip install -q --constraint requirements-dev-frozen.txt pip-tools
  191. - name: check requirements
  192. run: |
  193. python -S -m tools.freeze_requirements
  194. if ! git diff --exit-code; then
  195. echo $'\n\nrun `make freeze-requirements` locally to update requirements'
  196. exit 1
  197. fi
  198. - name: apply any requirements changes
  199. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  200. uses: getsentry/action-github-commit@748c31dd78cffe76f51bef49a0be856b6effeda7 # v1.1.0
  201. with:
  202. github-token: ${{ steps.token.outputs.token }}
  203. message: ':snowflake: re-freeze requirements'
  204. migration:
  205. if: needs.files-changed.outputs.migration_lockfile == 'true'
  206. needs: files-changed
  207. name: check migration
  208. runs-on: ubuntu-20.04
  209. strategy:
  210. matrix:
  211. pg-version: ['14']
  212. steps:
  213. - name: Checkout sentry
  214. uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  215. - name: Setup sentry env
  216. uses: ./.github/actions/setup-sentry
  217. id: setup
  218. with:
  219. pg-version: ${{ matrix.pg-version }}
  220. - name: Migration & lockfile checks
  221. env:
  222. SENTRY_LOG_LEVEL: ERROR
  223. PGPASSWORD: postgres
  224. run: |
  225. ./.github/workflows/scripts/migration-check.sh
  226. plugins:
  227. if: needs.files-changed.outputs.plugins == 'true'
  228. needs: files-changed
  229. name: plugins test
  230. runs-on: ubuntu-20.04
  231. timeout-minutes: 10
  232. steps:
  233. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  234. - name: Update environment for silo databases
  235. if: |
  236. contains( github.event.pull_request.labels.*.name, 'Trigger: Silo db' )
  237. run: |
  238. echo "SENTRY_USE_SPLIT_DBS=1" >> "$GITHUB_ENV"
  239. - name: Setup sentry env
  240. uses: ./.github/actions/setup-sentry
  241. id: setup
  242. with:
  243. snuba: true
  244. - name: Run test
  245. run: |
  246. make test-plugins
  247. relay:
  248. if: needs.files-changed.outputs.backend == 'true'
  249. needs: files-changed
  250. name: relay test
  251. runs-on: ubuntu-20.04
  252. timeout-minutes: 30
  253. steps:
  254. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  255. with:
  256. # Avoid codecov error message related to SHA resolution:
  257. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  258. fetch-depth: '2'
  259. - name: Update environment for silo databases
  260. if: |
  261. contains( github.event.pull_request.labels.*.name, 'Trigger: Silo db' )
  262. run: |
  263. echo "SENTRY_USE_SPLIT_DBS=1" >> "$GITHUB_ENV"
  264. - name: Setup sentry env
  265. uses: ./.github/actions/setup-sentry
  266. id: setup
  267. with:
  268. snuba: true
  269. kafka: true
  270. - name: Pull relay image
  271. run: |
  272. # pull relay we'll run and kill it for each test
  273. docker pull us.gcr.io/sentryio/relay:nightly
  274. docker ps -a
  275. - name: Run test
  276. run: |
  277. make test-relay-integration
  278. # Upload coverage data even if running the tests step fails since
  279. # it reduces large coverage fluctuations
  280. - name: Handle artifacts
  281. if: ${{ always() }}
  282. uses: ./.github/actions/artifacts
  283. with:
  284. token: ${{ secrets.CODECOV_TOKEN }}
  285. snuba:
  286. if: needs.files-changed.outputs.backend == 'true'
  287. needs: files-changed
  288. name: snuba test
  289. runs-on: ubuntu-20.04
  290. timeout-minutes: 45
  291. strategy:
  292. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  293. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  294. fail-fast: false
  295. matrix:
  296. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  297. instance: [0, 1, 2, 3]
  298. env:
  299. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  300. MATRIX_INSTANCE_TOTAL: 4
  301. steps:
  302. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  303. with:
  304. # Avoid codecov error message related to SHA resolution:
  305. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  306. fetch-depth: '2'
  307. - name: Update environment for silo databases
  308. if: |
  309. contains( github.event.pull_request.labels.*.name, 'Trigger: Silo db' )
  310. run: |
  311. echo "SENTRY_USE_SPLIT_DBS=1" >> "$GITHUB_ENV"
  312. - name: Setup sentry env
  313. uses: ./.github/actions/setup-sentry
  314. id: setup
  315. with:
  316. snuba: true
  317. kafka: true
  318. - name: Run snuba test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  319. run: |
  320. make test-snuba
  321. # Upload coverage data even if running the tests step fails since
  322. # it reduces large coverage fluctuations
  323. - name: Handle artifacts
  324. if: ${{ always() }}
  325. uses: ./.github/actions/artifacts
  326. with:
  327. token: ${{ secrets.CODECOV_TOKEN }}
  328. symbolicator:
  329. if: needs.files-changed.outputs.backend == 'true'
  330. needs: files-changed
  331. name: symbolicator test
  332. runs-on: ubuntu-20.04
  333. timeout-minutes: 20
  334. steps:
  335. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  336. with:
  337. # Avoid codecov error message related to SHA resolution:
  338. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  339. fetch-depth: '2'
  340. - name: Setup sentry env
  341. uses: ./.github/actions/setup-sentry
  342. id: setup
  343. with:
  344. snuba: true
  345. kafka: true
  346. - name: Start symbolicator
  347. run: |
  348. echo $PWD
  349. docker run \
  350. -d \
  351. -v $PWD/config/symbolicator/:/etc/symbolicator \
  352. --network host \
  353. --name symbolicator \
  354. us.gcr.io/sentryio/symbolicator:nightly \
  355. run -c /etc/symbolicator/config.yml
  356. docker ps -a
  357. - name: Run test
  358. run: |
  359. make test-symbolicator
  360. # Upload coverage data even if running the tests step fails since
  361. # it reduces large coverage fluctuations
  362. - name: Handle artifacts
  363. if: ${{ always() }}
  364. uses: ./.github/actions/artifacts
  365. with:
  366. token: ${{ secrets.CODECOV_TOKEN }}
  367. typing:
  368. if: needs.files-changed.outputs.backend == 'true'
  369. needs: files-changed
  370. name: backend typing
  371. runs-on: ubuntu-20.04
  372. timeout-minutes: 20
  373. steps:
  374. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  375. - uses: getsentry/action-setup-venv@9e3bbae3836b1b6f129955bf55a19e1d99a61c67 # v1.0.5
  376. with:
  377. python-version: 3.8.16
  378. cache-dependency-path: requirements-dev-frozen.txt
  379. install-cmd: pip install -r requirements-dev-frozen.txt
  380. - name: setup sentry (lite)
  381. run: |
  382. SENTRY_LIGHT_BUILD=1 pip install --no-deps -e .
  383. sentry init
  384. - run: make backend-typing
  385. id: run
  386. - uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
  387. id: token
  388. continue-on-error: true
  389. with:
  390. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  391. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  392. # only if `backend-typing` succeeds should we try and trim the blocklist
  393. - run: |
  394. python3 -m tools.mypy_helpers.make_module_ignores
  395. git diff --exit-code
  396. - name: apply blocklist changes
  397. if: steps.token.outcome == 'success' && steps.run.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  398. uses: getsentry/action-github-commit@748c31dd78cffe76f51bef49a0be856b6effeda7 # v1.1.0
  399. with:
  400. github-token: ${{ steps.token.outputs.token }}
  401. message: ':knife: regenerate mypy module blocklist'
  402. # This check runs once all dependent jobs have passed
  403. # It symbolizes that all required Backend checks have succesfully passed (Or skipped)
  404. # This step is the only required backend check
  405. backend-required-check:
  406. needs:
  407. [
  408. api-docs,
  409. backend-test,
  410. backend-migration-tests,
  411. cli,
  412. files-changed,
  413. requirements,
  414. migration,
  415. plugins,
  416. relay,
  417. snuba,
  418. symbolicator,
  419. typing,
  420. ]
  421. name: Backend
  422. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  423. if: always()
  424. runs-on: ubuntu-20.04
  425. steps:
  426. # If any jobs we depend on fail, we will fail since this is a required check
  427. # NOTE: A timeout is considered a failure
  428. - name: Check for failures
  429. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  430. run: |
  431. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1