backend.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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. make test-python-ci
  92. - name: Handle artifacts
  93. uses: ./.github/actions/artifacts
  94. backend-test-snuba-contains-metrics-tag-values:
  95. if: needs.files-changed.outputs.backend == 'true'
  96. needs: files-changed
  97. name: backend test (snuba contains metrics tag values)
  98. runs-on: ubuntu-20.04
  99. timeout-minutes: 20
  100. strategy:
  101. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  102. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  103. fail-fast: false
  104. matrix:
  105. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  106. instance: [0]
  107. pg-version: ['9.6']
  108. env:
  109. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  110. MATRIX_INSTANCE_TOTAL: 1
  111. MIGRATIONS_TEST_MIGRATE: 1
  112. steps:
  113. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  114. with:
  115. # Avoid codecov error message related to SHA resolution:
  116. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  117. fetch-depth: '2'
  118. - name: Setup sentry env
  119. uses: ./.github/actions/setup-sentry
  120. id: setup
  121. with:
  122. snuba: true
  123. # Right now, we run so few bigtable related tests that the
  124. # overhead of running bigtable in all backend tests
  125. # is way smaller than the time it would take to run in its own job.
  126. bigtable: true
  127. pg-version: ${{ matrix.pg-version }}
  128. - name: Run backend test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  129. run: |
  130. export PYTEST_ADDOPTS="-m 'sentry_metrics and not broken_under_tags_values_as_strings'"
  131. export SENTRY_METRICS_SIMULATE_TAG_VALUES_IN_CLICKHOUSE=1
  132. make test-python-ci
  133. make test-snuba
  134. - name: Handle artifacts
  135. uses: ./.github/actions/artifacts
  136. cli:
  137. if: needs.files-changed.outputs.backend == 'true'
  138. needs: files-changed
  139. name: cli test
  140. runs-on: ubuntu-20.04
  141. timeout-minutes: 10
  142. strategy:
  143. matrix:
  144. pg-version: ['9.6']
  145. steps:
  146. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  147. - name: Setup sentry env
  148. uses: ./.github/actions/setup-sentry
  149. id: setup
  150. with:
  151. pg-version: ${{ matrix.pg-version }}
  152. - name: Run test
  153. run: |
  154. make test-cli
  155. - name: Handle artifacts
  156. uses: ./.github/actions/artifacts
  157. requirements:
  158. if: needs.files-changed.outputs.backend_dependencies == 'true'
  159. needs: files-changed
  160. name: requirements check
  161. runs-on: ubuntu-20.04
  162. timeout-minutes: 3
  163. steps:
  164. - uses: getsentry/action-github-app-token@38a3ce582e170ddfe8789f509597c6944f2292a9 # v1
  165. id: token
  166. continue-on-error: true
  167. with:
  168. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  169. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  170. - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3
  171. - uses: actions/setup-python@b4fe97ecda6b7a5fcd2448cdbf6a8fc76b3bedb0
  172. with:
  173. python-version: 3.8.13
  174. - name: check requirements
  175. run: |
  176. python -m pip install -q "$(grep '^pip-tools==' requirements-dev-frozen.txt)"
  177. python -S -m tools.freeze_requirements sentry
  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@1761f891f036c3efc813b2ba963b121120c1587a # 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@38a3ce582e170ddfe8789f509597c6944f2292a9 # v1
  196. id: token
  197. continue-on-error: true
  198. with:
  199. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  200. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  201. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  202. - uses: getsentry/paths-filter@66f7f1844185eb7fb6738ea4ea59d74bb99199e5 # v2
  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: actions/setup-python@b4fe97ecda6b7a5fcd2448cdbf6a8fc76b3bedb0
  217. with:
  218. python-version: 3.8.13
  219. cache: pip
  220. cache-dependency-path: requirements-dev-only-frozen.txt
  221. - uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8 # v3.0.8
  222. with:
  223. path: ~/.cache/pre-commit
  224. key: cache-epoch-1|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
  225. - name: Setup pre-commit
  226. # We don't use make setup-git because we're only interested in installing
  227. # requirements-dev-only-frozen.txt as a fast path.
  228. # We don't need pre-commit install --install-hooks since we're just interested
  229. # in running the hooks.
  230. run: |
  231. pip install -r requirements-dev-only-frozen.txt
  232. pre-commit install-hooks
  233. - name: Run pre-commit on changed files
  234. run: |
  235. # Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
  236. # XXX: there is a very small chance that it'll expand to exceed Linux's limits
  237. # `getconf ARG_MAX` - max # bytes of args + environ for exec()
  238. pre-commit run --files ${{ steps.files.outputs.all_files }}
  239. - name: Apply any pre-commit fixed files
  240. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  241. uses: getsentry/action-github-commit@1761f891f036c3efc813b2ba963b121120c1587a # main
  242. with:
  243. github-token: ${{ steps.token.outputs.token }}
  244. migration:
  245. if: needs.files-changed.outputs.migration_lockfile == 'true'
  246. needs: files-changed
  247. name: check migration
  248. runs-on: ubuntu-20.04
  249. strategy:
  250. matrix:
  251. pg-version: ['9.6']
  252. steps:
  253. - name: Checkout sentry
  254. uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  255. - name: Setup sentry env
  256. uses: ./.github/actions/setup-sentry
  257. id: setup
  258. with:
  259. pg-version: ${{ matrix.pg-version }}
  260. - name: Migration & lockfile checks
  261. env:
  262. SENTRY_LOG_LEVEL: ERROR
  263. PGPASSWORD: postgres
  264. run: |
  265. ./.github/workflows/scripts/migration-check.sh
  266. plugins:
  267. if: needs.files-changed.outputs.plugins == 'true'
  268. needs: files-changed
  269. name: plugins test
  270. runs-on: ubuntu-20.04
  271. timeout-minutes: 10
  272. steps:
  273. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  274. - name: Setup sentry env
  275. uses: ./.github/actions/setup-sentry
  276. id: setup
  277. with:
  278. snuba: true
  279. - name: Run test
  280. run: |
  281. make test-plugins
  282. region-to-control:
  283. if: needs.files-changed.outputs.backend == 'true'
  284. needs: files-changed
  285. name: region-to-control test
  286. runs-on: ubuntu-20.04
  287. timeout-minutes: 20
  288. steps:
  289. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  290. with:
  291. # Avoid codecov error message related to SHA resolution:
  292. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  293. fetch-depth: '2'
  294. - name: Setup sentry env
  295. uses: ./.github/actions/setup-sentry
  296. id: setup
  297. with:
  298. kafka: true
  299. - name: Run test
  300. run: |
  301. make test-region-to-control-integration
  302. - name: Handle artifacts
  303. uses: ./.github/actions/artifacts
  304. relay:
  305. if: needs.files-changed.outputs.backend == 'true'
  306. needs: files-changed
  307. name: relay test
  308. runs-on: ubuntu-20.04
  309. timeout-minutes: 20
  310. steps:
  311. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  312. with:
  313. # Avoid codecov error message related to SHA resolution:
  314. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  315. fetch-depth: '2'
  316. - name: Setup sentry env
  317. uses: ./.github/actions/setup-sentry
  318. id: setup
  319. with:
  320. snuba: true
  321. kafka: true
  322. - name: Pull relay image
  323. run: |
  324. # pull relay we'll run and kill it for each test
  325. docker pull us.gcr.io/sentryio/relay:nightly
  326. docker ps -a
  327. - name: Run test
  328. run: |
  329. make test-relay-integration
  330. - name: Handle artifacts
  331. uses: ./.github/actions/artifacts
  332. snuba:
  333. if: needs.files-changed.outputs.backend == 'true'
  334. needs: files-changed
  335. name: snuba test
  336. runs-on: ubuntu-20.04
  337. timeout-minutes: 30
  338. strategy:
  339. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  340. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  341. fail-fast: false
  342. matrix:
  343. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  344. instance: [0, 1]
  345. env:
  346. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  347. MATRIX_INSTANCE_TOTAL: 2
  348. MIGRATIONS_TEST_MIGRATE: 1
  349. steps:
  350. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  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: Run snuba test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  362. run: |
  363. make test-snuba
  364. - name: Handle artifacts
  365. uses: ./.github/actions/artifacts
  366. symbolicator:
  367. if: needs.files-changed.outputs.backend == 'true'
  368. needs: files-changed
  369. name: symbolicator test
  370. runs-on: ubuntu-20.04
  371. timeout-minutes: 10
  372. steps:
  373. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  374. with:
  375. # Avoid codecov error message related to SHA resolution:
  376. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  377. fetch-depth: '2'
  378. - name: Setup sentry env
  379. uses: ./.github/actions/setup-sentry
  380. id: setup
  381. with:
  382. snuba: true
  383. kafka: true
  384. - name: Start symbolicator
  385. run: |
  386. echo $PWD
  387. docker run \
  388. -d \
  389. -v $PWD/config/symbolicator/:/etc/symbolicator \
  390. --network host \
  391. --name symbolicator \
  392. us.gcr.io/sentryio/symbolicator:nightly \
  393. run -c /etc/symbolicator/config.yml
  394. docker ps -a
  395. - name: Run test
  396. run: |
  397. make test-symbolicator
  398. - name: Handle artifacts
  399. uses: ./.github/actions/artifacts
  400. typing:
  401. if: needs.files-changed.outputs.backend == 'true'
  402. needs: files-changed
  403. name: backend typing
  404. runs-on: ubuntu-20.04
  405. timeout-minutes: 12
  406. steps:
  407. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  408. - name: Setup Python
  409. uses: actions/setup-python@b4fe97ecda6b7a5fcd2448cdbf6a8fc76b3bedb0
  410. with:
  411. python-version: 3.8.13
  412. cache: pip
  413. cache-dependency-path: requirements-dev-frozen.txt
  414. # We don't call setup-sentry, because we don't need devservices.
  415. - name: Setup backend typing
  416. run: pip install -r requirements-dev-frozen.txt
  417. - name: Run backend typing (${{ steps.setup.outputs.matrix-instance-number }} of ${{ strategy.job-total }})
  418. run: make backend-typing
  419. # This check runs once all dependant jobs have passed
  420. # It symbolizes that all required Backend checks have succesfully passed (Or skipped)
  421. # This check is the only required Github check
  422. backend-required-check:
  423. needs:
  424. [
  425. api-docs,
  426. backend-test,
  427. cli,
  428. lint,
  429. requirements,
  430. migration,
  431. plugins,
  432. relay,
  433. region-to-control,
  434. snuba,
  435. symbolicator,
  436. typing,
  437. ]
  438. name: Backend
  439. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  440. if: always()
  441. runs-on: ubuntu-20.04
  442. steps:
  443. # If any jobs we depend on fail, we will fail since this is a required check
  444. # NOTE: A timeout is considered a failure
  445. - name: Check for failures
  446. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  447. run: |
  448. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1