backend.yml 16 KB

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