backend.yml 16 KB

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