backend.yml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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: Setup sentry env
  80. uses: ./.github/actions/setup-sentry
  81. id: setup
  82. with:
  83. snuba: true
  84. # Right now, we run so few bigtable related tests that the
  85. # overhead of running bigtable in all backend tests
  86. # is way smaller than the time it would take to run in its own job.
  87. bigtable: true
  88. pg-version: ${{ matrix.pg-version }}
  89. - name: Run backend test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  90. run: |
  91. make test-python-ci
  92. # Upload coverage data even if running the tests step fails since
  93. # it reduces large coverage fluctuations
  94. - name: Handle artifacts
  95. if: ${{ always() }}
  96. uses: ./.github/actions/artifacts
  97. with:
  98. token: ${{ secrets.CODECOV_TOKEN }}
  99. backend-migration-tests:
  100. if: needs.files-changed.outputs.backend == 'true'
  101. needs: files-changed
  102. name: backend migration tests
  103. runs-on: ubuntu-20.04
  104. timeout-minutes: 30
  105. strategy:
  106. matrix:
  107. pg-version: ['14']
  108. steps:
  109. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  110. with:
  111. # Avoid codecov error message related to SHA resolution:
  112. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  113. fetch-depth: '2'
  114. - name: Setup sentry env
  115. uses: ./.github/actions/setup-sentry
  116. id: setup
  117. with:
  118. snuba: true
  119. pg-version: ${{ matrix.pg-version }}
  120. - name: run tests
  121. run: |
  122. MIGRATIONS_TEST_MIGRATE=1 PYTEST_ADDOPTS="$PYTEST_ADDOPTS -m migrations" make test-python-ci
  123. # Upload coverage data even if running the tests step fails since
  124. # it reduces large coverage fluctuations
  125. - name: Handle artifacts
  126. if: ${{ always() }}
  127. uses: ./.github/actions/artifacts
  128. with:
  129. token: ${{ secrets.CODECOV_TOKEN }}
  130. cli:
  131. if: needs.files-changed.outputs.backend == 'true'
  132. needs: files-changed
  133. name: cli test
  134. runs-on: ubuntu-20.04
  135. timeout-minutes: 10
  136. strategy:
  137. matrix:
  138. pg-version: ['14']
  139. steps:
  140. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  141. - name: Setup sentry env
  142. uses: ./.github/actions/setup-sentry
  143. id: setup
  144. with:
  145. pg-version: ${{ matrix.pg-version }}
  146. - name: Run test
  147. run: |
  148. make test-cli
  149. # Upload coverage data even if running the tests step fails since
  150. # it reduces large coverage fluctuations
  151. - name: Handle artifacts
  152. if: ${{ always() }}
  153. uses: ./.github/actions/artifacts
  154. with:
  155. token: ${{ secrets.CODECOV_TOKEN }}
  156. requirements:
  157. if: needs.files-changed.outputs.backend_dependencies == 'true'
  158. needs: files-changed
  159. name: requirements check
  160. runs-on: ubuntu-20.04
  161. timeout-minutes: 3
  162. steps:
  163. - uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
  164. id: token
  165. continue-on-error: true
  166. with:
  167. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  168. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  169. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  170. - uses: getsentry/action-setup-venv@9e3bbae3836b1b6f129955bf55a19e1d99a61c67 # v1.0.5
  171. with:
  172. python-version: 3.8.16
  173. cache-depedency: requirements-dev-frozen.txt
  174. install-cmd: pip install -q --constraint requirements-dev-frozen.txt pip-tools
  175. - name: check requirements
  176. run: |
  177. python -S -m tools.freeze_requirements
  178. if ! git diff --exit-code; then
  179. echo $'\n\nrun `make freeze-requirements` locally to update requirements'
  180. exit 1
  181. fi
  182. - name: apply any requirements changes
  183. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  184. uses: getsentry/action-github-commit@bec0adb2924f8c19a9f84c18c83d375caf02ca38 # main
  185. with:
  186. github-token: ${{ steps.token.outputs.token }}
  187. message: ':snowflake: re-freeze requirements'
  188. lint:
  189. if: needs.files-changed.outputs.backend == 'true'
  190. needs: files-changed
  191. name: backend lint
  192. runs-on: ubuntu-20.04
  193. timeout-minutes: 10
  194. steps:
  195. - uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
  196. id: token
  197. continue-on-error: true
  198. with:
  199. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  200. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  201. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  202. - uses: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
  203. id: files
  204. with:
  205. # Enable listing of files matching each filter.
  206. # Paths to files will be available in `${FILTER_NAME}_files` output variable.
  207. # Paths will be escaped and space-delimited.
  208. # Output is usable as command line argument list in linux shell
  209. list-files: shell
  210. # It doesn't make sense to lint deleted files.
  211. # Therefore we specify we are only interested in added or modified files.
  212. filters: |
  213. all:
  214. - added|modified: '**/*.py'
  215. - added|modified: 'requirements-*.txt'
  216. - uses: getsentry/action-setup-venv@9e3bbae3836b1b6f129955bf55a19e1d99a61c67 # v1.0.5
  217. with:
  218. python-version: 3.8.16
  219. cache-dependency-path: |
  220. requirements-dev.txt
  221. requirements-dev-frozen.txt
  222. install-cmd: pip install -r requirements-dev.txt -c requirements-dev-frozen.txt
  223. - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  224. with:
  225. path: ~/.cache/pre-commit
  226. key: cache-epoch-1|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
  227. - name: Setup pre-commit
  228. # We don't use make setup-git because we're only interested in installing
  229. # requirements-dev.txt as a fast path.
  230. # We don't need pre-commit install --install-hooks since we're just interested
  231. # in running the hooks.
  232. run: |
  233. pre-commit install-hooks
  234. - name: Run pre-commit on changed files
  235. run: |
  236. # Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
  237. # XXX: there is a very small chance that it'll expand to exceed Linux's limits
  238. # `getconf ARG_MAX` - max # bytes of args + environ for exec()
  239. pre-commit run --files ${{ steps.files.outputs.all_files }}
  240. - name: Apply any pre-commit fixed files
  241. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  242. uses: getsentry/action-github-commit@bec0adb2924f8c19a9f84c18c83d375caf02ca38 # main
  243. with:
  244. github-token: ${{ steps.token.outputs.token }}
  245. message: ':hammer_and_wrench: apply pre-commit fixes'
  246. migration:
  247. if: needs.files-changed.outputs.migration_lockfile == 'true'
  248. needs: files-changed
  249. name: check migration
  250. runs-on: ubuntu-20.04
  251. strategy:
  252. matrix:
  253. pg-version: ['14']
  254. steps:
  255. - name: Checkout sentry
  256. uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  257. - name: Setup sentry env
  258. uses: ./.github/actions/setup-sentry
  259. id: setup
  260. with:
  261. pg-version: ${{ matrix.pg-version }}
  262. - name: Migration & lockfile checks
  263. env:
  264. SENTRY_LOG_LEVEL: ERROR
  265. PGPASSWORD: postgres
  266. run: |
  267. ./.github/workflows/scripts/migration-check.sh
  268. plugins:
  269. if: needs.files-changed.outputs.plugins == 'true'
  270. needs: files-changed
  271. name: plugins test
  272. runs-on: ubuntu-20.04
  273. timeout-minutes: 10
  274. steps:
  275. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  276. - name: Setup sentry env
  277. uses: ./.github/actions/setup-sentry
  278. id: setup
  279. with:
  280. snuba: true
  281. - name: Run test
  282. run: |
  283. make test-plugins
  284. relay:
  285. if: needs.files-changed.outputs.backend == 'true'
  286. needs: files-changed
  287. name: relay test
  288. runs-on: ubuntu-20.04
  289. timeout-minutes: 30
  290. steps:
  291. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  292. with:
  293. # Avoid codecov error message related to SHA resolution:
  294. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  295. fetch-depth: '2'
  296. - name: Setup sentry env
  297. uses: ./.github/actions/setup-sentry
  298. id: setup
  299. with:
  300. snuba: true
  301. kafka: true
  302. - name: Pull relay image
  303. run: |
  304. # pull relay we'll run and kill it for each test
  305. docker pull us.gcr.io/sentryio/relay:nightly
  306. docker ps -a
  307. - name: Run test
  308. run: |
  309. make test-relay-integration
  310. # Upload coverage data even if running the tests step fails since
  311. # it reduces large coverage fluctuations
  312. - name: Handle artifacts
  313. if: ${{ always() }}
  314. uses: ./.github/actions/artifacts
  315. with:
  316. token: ${{ secrets.CODECOV_TOKEN }}
  317. snuba:
  318. if: needs.files-changed.outputs.backend == 'true'
  319. needs: files-changed
  320. name: snuba test
  321. runs-on: ubuntu-20.04
  322. timeout-minutes: 30
  323. strategy:
  324. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  325. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  326. fail-fast: false
  327. matrix:
  328. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  329. instance: [0, 1, 2]
  330. env:
  331. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  332. MATRIX_INSTANCE_TOTAL: 3
  333. steps:
  334. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  335. with:
  336. # Avoid codecov error message related to SHA resolution:
  337. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  338. fetch-depth: '2'
  339. - name: Setup sentry env
  340. uses: ./.github/actions/setup-sentry
  341. id: setup
  342. with:
  343. snuba: true
  344. kafka: true
  345. - name: Run snuba test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  346. run: |
  347. make test-snuba
  348. # Upload coverage data even if running the tests step fails since
  349. # it reduces large coverage fluctuations
  350. - name: Handle artifacts
  351. if: ${{ always() }}
  352. uses: ./.github/actions/artifacts
  353. with:
  354. token: ${{ secrets.CODECOV_TOKEN }}
  355. symbolicator:
  356. if: needs.files-changed.outputs.backend == 'true'
  357. needs: files-changed
  358. name: symbolicator test
  359. runs-on: ubuntu-20.04
  360. timeout-minutes: 20
  361. steps:
  362. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  363. with:
  364. # Avoid codecov error message related to SHA resolution:
  365. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  366. fetch-depth: '2'
  367. - name: Setup sentry env
  368. uses: ./.github/actions/setup-sentry
  369. id: setup
  370. with:
  371. snuba: true
  372. kafka: true
  373. - name: Start symbolicator
  374. run: |
  375. echo $PWD
  376. docker run \
  377. -d \
  378. -v $PWD/config/symbolicator/:/etc/symbolicator \
  379. --network host \
  380. --name symbolicator \
  381. us.gcr.io/sentryio/symbolicator:nightly \
  382. run -c /etc/symbolicator/config.yml
  383. docker ps -a
  384. - name: Run test
  385. run: |
  386. make test-symbolicator
  387. # Upload coverage data even if running the tests step fails since
  388. # it reduces large coverage fluctuations
  389. - name: Handle artifacts
  390. if: ${{ always() }}
  391. uses: ./.github/actions/artifacts
  392. with:
  393. token: ${{ secrets.CODECOV_TOKEN }}
  394. typing:
  395. if: needs.files-changed.outputs.backend == 'true'
  396. needs: files-changed
  397. name: backend typing
  398. runs-on: ubuntu-20.04
  399. timeout-minutes: 20
  400. steps:
  401. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  402. - uses: getsentry/action-setup-venv@9e3bbae3836b1b6f129955bf55a19e1d99a61c67 # v1.0.5
  403. with:
  404. python-version: 3.8.16
  405. cache-dependency-path: requirements-dev-frozen.txt
  406. install-cmd: pip install -r requirements-dev-frozen.txt
  407. - name: setup sentry (lite)
  408. run: |
  409. SENTRY_LIGHT_BUILD=1 pip install --no-deps -e .
  410. sentry init
  411. - run: make backend-typing
  412. id: run
  413. - uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
  414. id: token
  415. continue-on-error: true
  416. with:
  417. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  418. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  419. # only if `backend-typing` succeeds should we try and trim the blocklist
  420. - run: |
  421. python3 -m tools.mypy_helpers.make_module_ignores
  422. git diff --exit-code
  423. - name: apply blocklist changes
  424. if: steps.token.outcome == 'success' && steps.run.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  425. uses: getsentry/action-github-commit@bec0adb2924f8c19a9f84c18c83d375caf02ca38 # main
  426. with:
  427. github-token: ${{ steps.token.outputs.token }}
  428. message: ':knife: regenerate mypy module blocklist'
  429. # This check runs once all dependant jobs have passed
  430. # It symbolizes that all required Backend checks have succesfully passed (Or skipped)
  431. # This check is the only required Github check
  432. backend-required-check:
  433. needs:
  434. [
  435. api-docs,
  436. backend-test,
  437. backend-migration-tests,
  438. cli,
  439. files-changed,
  440. lint,
  441. requirements,
  442. migration,
  443. plugins,
  444. relay,
  445. snuba,
  446. symbolicator,
  447. typing,
  448. ]
  449. name: Backend
  450. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  451. if: always()
  452. runs-on: ubuntu-20.04
  453. steps:
  454. # If any jobs we depend on fail, we will fail since this is a required check
  455. # NOTE: A timeout is considered a failure
  456. - name: Check for failures
  457. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  458. run: |
  459. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1