backend.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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_MIN: 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@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  30. - name: Check for backend file changes
  31. uses: getsentry/paths-filter@66f7f1844185eb7fb6738ea4ea59d74bb99199e5 # v2
  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@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  43. - uses: ./.github/actions/setup-volta
  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: 20
  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. MIGRATIONS_TEST_MIGRATE: 1
  73. steps:
  74. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  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. # Note: `USE_SNUBA` is not used for backend tests because there are a few failing tests with Snuba enabled.
  92. unset USE_SNUBA
  93. make test-python-ci
  94. - name: Handle artifacts
  95. uses: ./.github/actions/artifacts
  96. backend-test-snuba-contains-metrics-tag-values:
  97. if: needs.files-changed.outputs.backend == 'true'
  98. needs: files-changed
  99. name: backend test (snuba contains metrics tag values)
  100. runs-on: ubuntu-20.04
  101. timeout-minutes: 20
  102. strategy:
  103. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  104. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  105. fail-fast: false
  106. matrix:
  107. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  108. instance: [0]
  109. pg-version: ['9.6']
  110. env:
  111. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  112. MATRIX_INSTANCE_TOTAL: 1
  113. MIGRATIONS_TEST_MIGRATE: 1
  114. steps:
  115. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  116. with:
  117. # Avoid codecov error message related to SHA resolution:
  118. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  119. fetch-depth: '2'
  120. - name: Setup sentry env
  121. uses: ./.github/actions/setup-sentry
  122. id: setup
  123. with:
  124. snuba: true
  125. # Right now, we run so few bigtable related tests that the
  126. # overhead of running bigtable in all backend tests
  127. # is way smaller than the time it would take to run in its own job.
  128. bigtable: true
  129. pg-version: ${{ matrix.pg-version }}
  130. - name: Run backend test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  131. run: |
  132. export PYTEST_ADDOPTS="-m 'sentry_metrics and not broken_under_tags_values_as_strings'"
  133. export SENTRY_METRICS_SIMULATE_TAG_VALUES_IN_CLICKHOUSE=1
  134. make test-python-ci
  135. make test-snuba
  136. - name: Handle artifacts
  137. uses: ./.github/actions/artifacts
  138. cli:
  139. if: needs.files-changed.outputs.backend == 'true'
  140. needs: files-changed
  141. name: cli test
  142. runs-on: ubuntu-20.04
  143. timeout-minutes: 10
  144. strategy:
  145. matrix:
  146. pg-version: ['9.6']
  147. steps:
  148. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  149. - name: Setup sentry env
  150. uses: ./.github/actions/setup-sentry
  151. id: setup
  152. with:
  153. pg-version: ${{ matrix.pg-version }}
  154. - name: Run test
  155. run: |
  156. make test-cli
  157. - name: Handle artifacts
  158. uses: ./.github/actions/artifacts
  159. requirements:
  160. if: needs.files-changed.outputs.backend_dependencies == 'true'
  161. needs: files-changed
  162. name: requirements check
  163. runs-on: ubuntu-20.04
  164. timeout-minutes: 3
  165. steps:
  166. - uses: getsentry/action-github-app-token@38a3ce582e170ddfe8789f509597c6944f2292a9 # v1
  167. id: token
  168. continue-on-error: true
  169. with:
  170. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  171. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  172. - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3
  173. - uses: actions/setup-python@b4fe97ecda6b7a5fcd2448cdbf6a8fc76b3bedb0
  174. with:
  175. python-version: 3.8.13
  176. - name: check requirements
  177. run: |
  178. python -m pip install -q "$(grep '^pip-tools==' requirements-dev-frozen.txt)"
  179. python -S -m tools.freeze_requirements sentry
  180. if ! git diff --exit-code; then
  181. echo $'\n\nrun `make freeze-requirements` locally to update requirements'
  182. exit 1
  183. fi
  184. - name: apply any requirements changes
  185. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  186. uses: getsentry/action-github-commit@1761f891f036c3efc813b2ba963b121120c1587a # main
  187. with:
  188. github-token: ${{ steps.token.outputs.token }}
  189. message: ':snowflake: re-freeze requirements'
  190. lint:
  191. if: needs.files-changed.outputs.backend == 'true'
  192. needs: files-changed
  193. name: backend lint
  194. runs-on: ubuntu-20.04
  195. timeout-minutes: 10
  196. steps:
  197. - uses: getsentry/action-github-app-token@38a3ce582e170ddfe8789f509597c6944f2292a9 # v1
  198. id: token
  199. continue-on-error: true
  200. with:
  201. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  202. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  203. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  204. - uses: getsentry/paths-filter@66f7f1844185eb7fb6738ea4ea59d74bb99199e5 # v2
  205. id: files
  206. with:
  207. # Enable listing of files matching each filter.
  208. # Paths to files will be available in `${FILTER_NAME}_files` output variable.
  209. # Paths will be escaped and space-delimited.
  210. # Output is usable as command line argument list in linux shell
  211. list-files: shell
  212. # It doesn't make sense to lint deleted files.
  213. # Therefore we specify we are only interested in added or modified files.
  214. filters: |
  215. all:
  216. - added|modified: '**/*.py'
  217. - added|modified: 'requirements-*.txt'
  218. - uses: actions/setup-python@b4fe97ecda6b7a5fcd2448cdbf6a8fc76b3bedb0
  219. with:
  220. python-version: 3.8.13
  221. cache: pip
  222. cache-dependency-path: requirements-dev-only-frozen.txt
  223. - uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8 # v3.0.8
  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-only-frozen.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. pip install -r requirements-dev-only-frozen.txt
  234. pre-commit install-hooks
  235. - name: Run pre-commit on changed files
  236. run: |
  237. # Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
  238. # XXX: there is a very small chance that it'll expand to exceed Linux's limits
  239. # `getconf ARG_MAX` - max # bytes of args + environ for exec()
  240. pre-commit run --files ${{ steps.files.outputs.all_files }}
  241. - name: Apply any pre-commit fixed files
  242. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  243. uses: getsentry/action-github-commit@1761f891f036c3efc813b2ba963b121120c1587a # main
  244. with:
  245. github-token: ${{ steps.token.outputs.token }}
  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: ['9.6']
  254. steps:
  255. - name: Checkout sentry
  256. uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  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@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  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: 20
  290. steps:
  291. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  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. - name: Handle artifacts
  311. uses: ./.github/actions/artifacts
  312. snuba:
  313. if: needs.files-changed.outputs.backend == 'true'
  314. needs: files-changed
  315. name: snuba test
  316. runs-on: ubuntu-20.04
  317. timeout-minutes: 30
  318. strategy:
  319. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  320. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  321. fail-fast: false
  322. matrix:
  323. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  324. instance: [0, 1]
  325. env:
  326. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  327. MATRIX_INSTANCE_TOTAL: 2
  328. USE_SNUBA: 1
  329. MIGRATIONS_TEST_MIGRATE: 1
  330. steps:
  331. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  332. with:
  333. # Avoid codecov error message related to SHA resolution:
  334. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  335. fetch-depth: '2'
  336. - name: Setup sentry env
  337. uses: ./.github/actions/setup-sentry
  338. id: setup
  339. with:
  340. snuba: true
  341. kafka: true
  342. - name: Run snuba test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  343. run: |
  344. make test-snuba
  345. - name: Handle artifacts
  346. uses: ./.github/actions/artifacts
  347. symbolicator:
  348. if: needs.files-changed.outputs.backend == 'true'
  349. needs: files-changed
  350. name: symbolicator test
  351. runs-on: ubuntu-20.04
  352. timeout-minutes: 10
  353. steps:
  354. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  355. with:
  356. # Avoid codecov error message related to SHA resolution:
  357. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  358. fetch-depth: '2'
  359. - name: Setup sentry env
  360. uses: ./.github/actions/setup-sentry
  361. id: setup
  362. with:
  363. snuba: true
  364. kafka: true
  365. - name: Start symbolicator
  366. run: |
  367. echo $PWD
  368. docker run \
  369. -d \
  370. -v $PWD/config/symbolicator/:/etc/symbolicator \
  371. --network host \
  372. --name symbolicator \
  373. us.gcr.io/sentryio/symbolicator:nightly \
  374. run -c /etc/symbolicator/config.yml
  375. docker ps -a
  376. - name: Run test
  377. run: |
  378. make test-symbolicator
  379. - name: Handle artifacts
  380. uses: ./.github/actions/artifacts
  381. typing:
  382. if: needs.files-changed.outputs.backend == 'true'
  383. needs: files-changed
  384. name: backend typing
  385. runs-on: ubuntu-20.04
  386. timeout-minutes: 12
  387. steps:
  388. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  389. - name: Setup Python
  390. uses: actions/setup-python@b4fe97ecda6b7a5fcd2448cdbf6a8fc76b3bedb0
  391. with:
  392. python-version: 3.8.13
  393. cache: pip
  394. cache-dependency-path: requirements-dev-frozen.txt
  395. # We don't call setup-sentry, because we don't need devservices.
  396. - name: Setup backend typing
  397. run: pip install -r requirements-dev-frozen.txt
  398. - name: Run backend typing (${{ steps.setup.outputs.matrix-instance-number }} of ${{ strategy.job-total }})
  399. run: make backend-typing
  400. # This check runs once all dependant jobs have passed
  401. # It symbolizes that all required Backend checks have succesfully passed (Or skipped)
  402. # This check is the only required Github check
  403. backend-required-check:
  404. needs:
  405. [
  406. api-docs,
  407. backend-test,
  408. cli,
  409. lint,
  410. requirements,
  411. migration,
  412. plugins,
  413. relay,
  414. snuba,
  415. symbolicator,
  416. typing,
  417. ]
  418. name: Backend
  419. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  420. if: always()
  421. runs-on: ubuntu-20.04
  422. steps:
  423. # If any jobs we depend on fail, we will fail since this is a required check
  424. # NOTE: A timeout is considered a failure
  425. - name: Check for failures
  426. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  427. run: |
  428. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1