backend.yml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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]
  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: 6
  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@bec0adb2924f8c19a9f84c18c83d375caf02ca38 # main
  201. with:
  202. github-token: ${{ steps.token.outputs.token }}
  203. message: ':snowflake: re-freeze requirements'
  204. lint:
  205. if: needs.files-changed.outputs.backend == 'true'
  206. needs: files-changed
  207. name: backend lint
  208. runs-on: ubuntu-20.04
  209. timeout-minutes: 10
  210. steps:
  211. - uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
  212. id: token
  213. continue-on-error: true
  214. with:
  215. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  216. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  217. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  218. - uses: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
  219. id: files
  220. with:
  221. # Enable listing of files matching each filter.
  222. # Paths to files will be available in `${FILTER_NAME}_files` output variable.
  223. # Paths will be escaped and space-delimited.
  224. # Output is usable as command line argument list in linux shell
  225. list-files: shell
  226. # It doesn't make sense to lint deleted files.
  227. # Therefore we specify we are only interested in added or modified files.
  228. filters: |
  229. all:
  230. - added|modified: '**/*.py'
  231. - added|modified: 'requirements-*.txt'
  232. - uses: getsentry/action-setup-venv@9e3bbae3836b1b6f129955bf55a19e1d99a61c67 # v1.0.5
  233. with:
  234. python-version: 3.8.16
  235. cache-dependency-path: |
  236. requirements-dev.txt
  237. requirements-dev-frozen.txt
  238. install-cmd: pip install -r requirements-dev.txt -c requirements-dev-frozen.txt
  239. - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  240. with:
  241. path: ~/.cache/pre-commit
  242. key: cache-epoch-1|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
  243. - name: Setup pre-commit
  244. # We don't use make setup-git because we're only interested in installing
  245. # requirements-dev.txt as a fast path.
  246. # We don't need pre-commit install --install-hooks since we're just interested
  247. # in running the hooks.
  248. run: |
  249. pre-commit install-hooks
  250. - name: Run pre-commit on changed files
  251. run: |
  252. # Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
  253. # XXX: there is a very small chance that it'll expand to exceed Linux's limits
  254. # `getconf ARG_MAX` - max # bytes of args + environ for exec()
  255. pre-commit run --files ${{ steps.files.outputs.all_files }}
  256. - name: Apply any pre-commit fixed files
  257. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  258. uses: getsentry/action-github-commit@bec0adb2924f8c19a9f84c18c83d375caf02ca38 # main
  259. with:
  260. github-token: ${{ steps.token.outputs.token }}
  261. message: ':hammer_and_wrench: apply pre-commit fixes'
  262. migration:
  263. if: needs.files-changed.outputs.migration_lockfile == 'true'
  264. needs: files-changed
  265. name: check migration
  266. runs-on: ubuntu-20.04
  267. strategy:
  268. matrix:
  269. pg-version: ['14']
  270. steps:
  271. - name: Checkout sentry
  272. uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  273. - name: Setup sentry env
  274. uses: ./.github/actions/setup-sentry
  275. id: setup
  276. with:
  277. pg-version: ${{ matrix.pg-version }}
  278. - name: Migration & lockfile checks
  279. env:
  280. SENTRY_LOG_LEVEL: ERROR
  281. PGPASSWORD: postgres
  282. run: |
  283. ./.github/workflows/scripts/migration-check.sh
  284. plugins:
  285. if: needs.files-changed.outputs.plugins == 'true'
  286. needs: files-changed
  287. name: plugins test
  288. runs-on: ubuntu-20.04
  289. timeout-minutes: 10
  290. steps:
  291. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  292. - name: Update environment for silo databases
  293. if: |
  294. contains( github.event.pull_request.labels.*.name, 'Trigger: Silo db' )
  295. run: |
  296. echo "SENTRY_USE_SPLIT_DBS=1" >> "$GITHUB_ENV"
  297. - name: Setup sentry env
  298. uses: ./.github/actions/setup-sentry
  299. id: setup
  300. with:
  301. snuba: true
  302. - name: Run test
  303. run: |
  304. make test-plugins
  305. relay:
  306. if: needs.files-changed.outputs.backend == 'true'
  307. needs: files-changed
  308. name: relay test
  309. runs-on: ubuntu-20.04
  310. timeout-minutes: 30
  311. steps:
  312. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  313. with:
  314. # Avoid codecov error message related to SHA resolution:
  315. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  316. fetch-depth: '2'
  317. - name: Setup sentry env
  318. uses: ./.github/actions/setup-sentry
  319. id: setup
  320. with:
  321. snuba: true
  322. kafka: true
  323. - name: Pull relay image
  324. run: |
  325. # pull relay we'll run and kill it for each test
  326. docker pull us.gcr.io/sentryio/relay:nightly
  327. docker ps -a
  328. - name: Run test
  329. run: |
  330. make test-relay-integration
  331. # Upload coverage data even if running the tests step fails since
  332. # it reduces large coverage fluctuations
  333. - name: Handle artifacts
  334. if: ${{ always() }}
  335. uses: ./.github/actions/artifacts
  336. with:
  337. token: ${{ secrets.CODECOV_TOKEN }}
  338. snuba:
  339. if: needs.files-changed.outputs.backend == 'true'
  340. needs: files-changed
  341. name: snuba test
  342. runs-on: ubuntu-20.04
  343. timeout-minutes: 30
  344. strategy:
  345. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  346. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  347. fail-fast: false
  348. matrix:
  349. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  350. instance: [0, 1, 2]
  351. env:
  352. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  353. MATRIX_INSTANCE_TOTAL: 3
  354. steps:
  355. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  356. with:
  357. # Avoid codecov error message related to SHA resolution:
  358. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  359. fetch-depth: '2'
  360. - name: Update environment for silo databases
  361. if: |
  362. contains( github.event.pull_request.labels.*.name, 'Trigger: Silo db' )
  363. run: |
  364. echo "SENTRY_USE_SPLIT_DBS=1" >> "$GITHUB_ENV"
  365. - name: Setup sentry env
  366. uses: ./.github/actions/setup-sentry
  367. id: setup
  368. with:
  369. snuba: true
  370. kafka: true
  371. - name: Run snuba test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  372. run: |
  373. make test-snuba
  374. # Upload coverage data even if running the tests step fails since
  375. # it reduces large coverage fluctuations
  376. - name: Handle artifacts
  377. if: ${{ always() }}
  378. uses: ./.github/actions/artifacts
  379. with:
  380. token: ${{ secrets.CODECOV_TOKEN }}
  381. symbolicator:
  382. if: needs.files-changed.outputs.backend == 'true'
  383. needs: files-changed
  384. name: symbolicator test
  385. runs-on: ubuntu-20.04
  386. timeout-minutes: 20
  387. steps:
  388. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  389. with:
  390. # Avoid codecov error message related to SHA resolution:
  391. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  392. fetch-depth: '2'
  393. - name: Setup sentry env
  394. uses: ./.github/actions/setup-sentry
  395. id: setup
  396. with:
  397. snuba: true
  398. kafka: true
  399. - name: Start symbolicator
  400. run: |
  401. echo $PWD
  402. docker run \
  403. -d \
  404. -v $PWD/config/symbolicator/:/etc/symbolicator \
  405. --network host \
  406. --name symbolicator \
  407. us.gcr.io/sentryio/symbolicator:nightly \
  408. run -c /etc/symbolicator/config.yml
  409. docker ps -a
  410. - name: Run test
  411. run: |
  412. make test-symbolicator
  413. # Upload coverage data even if running the tests step fails since
  414. # it reduces large coverage fluctuations
  415. - name: Handle artifacts
  416. if: ${{ always() }}
  417. uses: ./.github/actions/artifacts
  418. with:
  419. token: ${{ secrets.CODECOV_TOKEN }}
  420. typing:
  421. if: needs.files-changed.outputs.backend == 'true'
  422. needs: files-changed
  423. name: backend typing
  424. runs-on: ubuntu-20.04
  425. timeout-minutes: 20
  426. steps:
  427. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  428. - uses: getsentry/action-setup-venv@9e3bbae3836b1b6f129955bf55a19e1d99a61c67 # v1.0.5
  429. with:
  430. python-version: 3.8.16
  431. cache-dependency-path: requirements-dev-frozen.txt
  432. install-cmd: pip install -r requirements-dev-frozen.txt
  433. - name: setup sentry (lite)
  434. run: |
  435. SENTRY_LIGHT_BUILD=1 pip install --no-deps -e .
  436. sentry init
  437. - run: make backend-typing
  438. id: run
  439. - uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
  440. id: token
  441. continue-on-error: true
  442. with:
  443. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  444. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  445. # only if `backend-typing` succeeds should we try and trim the blocklist
  446. - run: |
  447. python3 -m tools.mypy_helpers.make_module_ignores
  448. git diff --exit-code
  449. - name: apply blocklist changes
  450. if: steps.token.outcome == 'success' && steps.run.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  451. uses: getsentry/action-github-commit@bec0adb2924f8c19a9f84c18c83d375caf02ca38 # main
  452. with:
  453. github-token: ${{ steps.token.outputs.token }}
  454. message: ':knife: regenerate mypy module blocklist'
  455. # This check runs once all dependant jobs have passed
  456. # It symbolizes that all required Backend checks have succesfully passed (Or skipped)
  457. # This check is the only required Github check
  458. backend-required-check:
  459. needs:
  460. [
  461. api-docs,
  462. backend-test,
  463. backend-migration-tests,
  464. cli,
  465. files-changed,
  466. lint,
  467. requirements,
  468. migration,
  469. plugins,
  470. relay,
  471. snuba,
  472. symbolicator,
  473. typing,
  474. ]
  475. name: Backend
  476. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  477. if: always()
  478. runs-on: ubuntu-20.04
  479. steps:
  480. # If any jobs we depend on fail, we will fail since this is a required check
  481. # NOTE: A timeout is considered a failure
  482. - name: Check for failures
  483. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  484. run: |
  485. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1