backend.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. relay:
  283. if: needs.files-changed.outputs.backend == 'true'
  284. needs: files-changed
  285. name: relay 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. snuba: true
  299. kafka: true
  300. - name: Pull relay image
  301. run: |
  302. # pull relay we'll run and kill it for each test
  303. docker pull us.gcr.io/sentryio/relay:nightly
  304. docker ps -a
  305. - name: Run test
  306. run: |
  307. make test-relay-integration
  308. - name: Handle artifacts
  309. uses: ./.github/actions/artifacts
  310. snuba:
  311. if: needs.files-changed.outputs.backend == 'true'
  312. needs: files-changed
  313. name: snuba test
  314. runs-on: ubuntu-20.04
  315. timeout-minutes: 30
  316. strategy:
  317. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  318. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  319. fail-fast: false
  320. matrix:
  321. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  322. instance: [0, 1]
  323. env:
  324. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  325. MATRIX_INSTANCE_TOTAL: 2
  326. MIGRATIONS_TEST_MIGRATE: 1
  327. steps:
  328. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  329. with:
  330. # Avoid codecov error message related to SHA resolution:
  331. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  332. fetch-depth: '2'
  333. - name: Setup sentry env
  334. uses: ./.github/actions/setup-sentry
  335. id: setup
  336. with:
  337. snuba: true
  338. kafka: true
  339. - name: Run snuba test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  340. run: |
  341. make test-snuba
  342. - name: Handle artifacts
  343. uses: ./.github/actions/artifacts
  344. symbolicator:
  345. if: needs.files-changed.outputs.backend == 'true'
  346. needs: files-changed
  347. name: symbolicator test
  348. runs-on: ubuntu-20.04
  349. timeout-minutes: 10
  350. steps:
  351. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  352. with:
  353. # Avoid codecov error message related to SHA resolution:
  354. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  355. fetch-depth: '2'
  356. - name: Setup sentry env
  357. uses: ./.github/actions/setup-sentry
  358. id: setup
  359. with:
  360. snuba: true
  361. kafka: true
  362. - name: Start symbolicator
  363. run: |
  364. echo $PWD
  365. docker run \
  366. -d \
  367. -v $PWD/config/symbolicator/:/etc/symbolicator \
  368. --network host \
  369. --name symbolicator \
  370. us.gcr.io/sentryio/symbolicator:nightly \
  371. run -c /etc/symbolicator/config.yml
  372. docker ps -a
  373. - name: Run test
  374. run: |
  375. make test-symbolicator
  376. - name: Handle artifacts
  377. uses: ./.github/actions/artifacts
  378. typing:
  379. if: needs.files-changed.outputs.backend == 'true'
  380. needs: files-changed
  381. name: backend typing
  382. runs-on: ubuntu-20.04
  383. timeout-minutes: 12
  384. steps:
  385. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  386. - name: Setup Python
  387. uses: actions/setup-python@b4fe97ecda6b7a5fcd2448cdbf6a8fc76b3bedb0
  388. with:
  389. python-version: 3.8.13
  390. cache: pip
  391. cache-dependency-path: requirements-dev-frozen.txt
  392. # We don't call setup-sentry, because we don't need devservices.
  393. - name: Setup backend typing
  394. run: pip install -r requirements-dev-frozen.txt
  395. - name: Run backend typing (${{ steps.setup.outputs.matrix-instance-number }} of ${{ strategy.job-total }})
  396. run: make backend-typing
  397. # This check runs once all dependant jobs have passed
  398. # It symbolizes that all required Backend checks have succesfully passed (Or skipped)
  399. # This check is the only required Github check
  400. backend-required-check:
  401. needs:
  402. [
  403. api-docs,
  404. backend-test,
  405. cli,
  406. lint,
  407. requirements,
  408. migration,
  409. plugins,
  410. relay,
  411. snuba,
  412. symbolicator,
  413. typing,
  414. ]
  415. name: Backend
  416. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  417. if: always()
  418. runs-on: ubuntu-20.04
  419. steps:
  420. # If any jobs we depend on fail, we will fail since this is a required check
  421. # NOTE: A timeout is considered a failure
  422. - name: Check for failures
  423. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  424. run: |
  425. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1