backend.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. name: backend
  2. on:
  3. push:
  4. branches:
  5. - master
  6. pull_request:
  7. # hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
  8. env:
  9. SEGMENT_DOWNLOAD_TIMEOUT_MIN: 3
  10. jobs:
  11. files-changed:
  12. name: detect what files changed
  13. runs-on: ubuntu-20.04
  14. timeout-minutes: 3
  15. # Map a step output to a job output
  16. outputs:
  17. api_docs: ${{ steps.changes.outputs.api_docs }}
  18. backend: ${{ steps.changes.outputs.backend }}
  19. backend_dependencies: ${{ steps.changes.outputs.backend_dependencies }}
  20. backend_any_type: ${{ steps.changes.outputs.backend_any_type }}
  21. migration_lockfile: ${{ steps.changes.outputs.migration_lockfile }}
  22. plugins: ${{ steps.changes.outputs.plugins }}
  23. steps:
  24. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  25. - name: Check for backend file changes
  26. uses: getsentry/paths-filter@66f7f1844185eb7fb6738ea4ea59d74bb99199e5 # v2
  27. id: changes
  28. with:
  29. token: ${{ github.token }}
  30. filters: .github/file-filters.yml
  31. api-docs:
  32. if: needs.files-changed.outputs.api_docs == 'true'
  33. needs: files-changed
  34. name: api docs test
  35. runs-on: ubuntu-20.04
  36. steps:
  37. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  38. - uses: ./.github/actions/setup-volta
  39. - name: Setup sentry python env
  40. uses: ./.github/actions/setup-sentry
  41. id: setup
  42. with:
  43. snuba: true
  44. - name: Run API docs tests
  45. # install ts-node for ts build scripts to execute properly without potentially installing
  46. # conflicting deps when running scripts locally
  47. # see: https://github.com/getsentry/sentry/pull/32328/files
  48. run: |
  49. yarn add ts-node && make test-api-docs
  50. backend-test:
  51. if: needs.files-changed.outputs.backend == 'true'
  52. needs: files-changed
  53. name: backend test
  54. runs-on: ubuntu-20.04
  55. timeout-minutes: 20
  56. strategy:
  57. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  58. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  59. fail-fast: false
  60. matrix:
  61. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  62. instance: [0, 1, 2, 3]
  63. pg-version: ['9.6']
  64. env:
  65. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  66. MATRIX_INSTANCE_TOTAL: 4
  67. MIGRATIONS_TEST_MIGRATE: 1
  68. steps:
  69. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  70. with:
  71. # Avoid codecov error message related to SHA resolution:
  72. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  73. fetch-depth: '2'
  74. - name: Setup sentry env
  75. uses: ./.github/actions/setup-sentry
  76. id: setup
  77. with:
  78. snuba: true
  79. # Right now, we run so few bigtable related tests that the
  80. # overhead of running bigtable in all backend tests
  81. # is way smaller than the time it would take to run in its own job.
  82. bigtable: true
  83. pg-version: ${{ matrix.pg-version }}
  84. - name: Run backend test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  85. run: |
  86. # Note: `USE_SNUBA` is not used for backend tests because there are a few failing tests with Snuba enabled.
  87. unset USE_SNUBA
  88. make test-python-ci
  89. - name: Handle artifacts
  90. uses: ./.github/actions/artifacts
  91. backend-test-snuba-contains-metrics-tag-values:
  92. if: needs.files-changed.outputs.backend == 'true'
  93. needs: files-changed
  94. name: backend test (snuba contains metrics tag values)
  95. runs-on: ubuntu-20.04
  96. timeout-minutes: 20
  97. strategy:
  98. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  99. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  100. fail-fast: false
  101. matrix:
  102. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  103. instance: [0]
  104. pg-version: ['9.6']
  105. env:
  106. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  107. MATRIX_INSTANCE_TOTAL: 1
  108. MIGRATIONS_TEST_MIGRATE: 1
  109. steps:
  110. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  111. with:
  112. # Avoid codecov error message related to SHA resolution:
  113. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  114. fetch-depth: '2'
  115. - name: Setup sentry env
  116. uses: ./.github/actions/setup-sentry
  117. id: setup
  118. with:
  119. snuba: true
  120. # Right now, we run so few bigtable related tests that the
  121. # overhead of running bigtable in all backend tests
  122. # is way smaller than the time it would take to run in its own job.
  123. bigtable: true
  124. pg-version: ${{ matrix.pg-version }}
  125. - name: Run backend test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  126. run: |
  127. export PYTEST_ADDOPTS="-m 'sentry_metrics and not broken_under_tags_values_as_strings'"
  128. export SENTRY_METRICS_SIMULATE_TAG_VALUES_IN_CLICKHOUSE=1
  129. make test-python-ci
  130. make test-snuba
  131. - name: Handle artifacts
  132. uses: ./.github/actions/artifacts
  133. cli:
  134. if: needs.files-changed.outputs.backend == 'true'
  135. needs: files-changed
  136. name: cli test
  137. runs-on: ubuntu-20.04
  138. timeout-minutes: 10
  139. strategy:
  140. matrix:
  141. pg-version: ['9.6']
  142. steps:
  143. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  144. - name: Setup sentry env
  145. uses: ./.github/actions/setup-sentry
  146. id: setup
  147. with:
  148. pg-version: ${{ matrix.pg-version }}
  149. - name: Run test
  150. run: |
  151. make test-cli
  152. - name: Handle artifacts
  153. uses: ./.github/actions/artifacts
  154. requirements:
  155. if: needs.files-changed.outputs.backend_dependencies == 'true'
  156. needs: files-changed
  157. name: requirements check
  158. runs-on: ubuntu-20.04
  159. timeout-minutes: 3
  160. steps:
  161. - uses: getsentry/action-github-app-token@38a3ce582e170ddfe8789f509597c6944f2292a9 # v1
  162. id: token
  163. continue-on-error: true
  164. with:
  165. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  166. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  167. - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3
  168. - uses: actions/setup-python@c4e89fac7e8767b327bbad6cb4d859eda999cf08 # v4
  169. with:
  170. python-version: 3.8.13
  171. - name: check requirements
  172. run: |
  173. python -m pip install -q "$(grep '^pip-tools==' requirements-dev-frozen.txt)"
  174. python -S -m tools.freeze_requirements sentry
  175. if ! git diff --exit-code; then
  176. echo $'\n\nrun `make freeze-requirements` locally to update requirements'
  177. exit 1
  178. fi
  179. - name: apply any requirements changes
  180. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  181. uses: getsentry/action-github-commit@1761f891f036c3efc813b2ba963b121120c1587a # main
  182. with:
  183. github-token: ${{ steps.token.outputs.token }}
  184. message: ':snowflake: re-freeze requirements'
  185. lint:
  186. if: needs.files-changed.outputs.backend == 'true'
  187. needs: files-changed
  188. name: backend lint
  189. runs-on: ubuntu-20.04
  190. timeout-minutes: 10
  191. steps:
  192. - uses: getsentry/action-github-app-token@38a3ce582e170ddfe8789f509597c6944f2292a9 # v1
  193. id: token
  194. continue-on-error: true
  195. with:
  196. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  197. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  198. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  199. - uses: getsentry/paths-filter@66f7f1844185eb7fb6738ea4ea59d74bb99199e5 # v2
  200. id: files
  201. with:
  202. # Enable listing of files matching each filter.
  203. # Paths to files will be available in `${FILTER_NAME}_files` output variable.
  204. # Paths will be escaped and space-delimited.
  205. # Output is usable as command line argument list in linux shell
  206. list-files: shell
  207. # It doesn't make sense to lint deleted files.
  208. # Therefore we specify we are only interested in added or modified files.
  209. filters: |
  210. all:
  211. - added|modified: '**/*.py'
  212. - added|modified: 'requirements-*.txt'
  213. - uses: actions/setup-python@c4e89fac7e8767b327bbad6cb4d859eda999cf08 # v4
  214. with:
  215. python-version: 3.8.13
  216. cache: pip
  217. cache-dependency-path: requirements-dev-only-frozen.txt
  218. - uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8 # v3.0.8
  219. with:
  220. path: ~/.cache/pre-commit
  221. key: cache-epoch-1|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
  222. - name: Setup pre-commit
  223. # We don't use make setup-git because we're only interested in installing
  224. # requirements-dev-only-frozen.txt as a fast path.
  225. # We don't need pre-commit install --install-hooks since we're just interested
  226. # in running the hooks.
  227. run: |
  228. pip install -r requirements-dev-only-frozen.txt
  229. pre-commit install-hooks
  230. - name: Run pre-commit on changed files
  231. run: |
  232. # Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
  233. # XXX: there is a very small chance that it'll expand to exceed Linux's limits
  234. # `getconf ARG_MAX` - max # bytes of args + environ for exec()
  235. pre-commit run --files ${{ steps.files.outputs.all_files }}
  236. - name: Apply any pre-commit fixed files
  237. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  238. uses: getsentry/action-github-commit@1761f891f036c3efc813b2ba963b121120c1587a # main
  239. with:
  240. github-token: ${{ steps.token.outputs.token }}
  241. migration:
  242. if: needs.files-changed.outputs.migration_lockfile == 'true'
  243. needs: files-changed
  244. name: check migration
  245. runs-on: ubuntu-20.04
  246. strategy:
  247. matrix:
  248. pg-version: ['9.6']
  249. steps:
  250. - name: Checkout sentry
  251. uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  252. - name: Setup sentry env
  253. uses: ./.github/actions/setup-sentry
  254. id: setup
  255. with:
  256. pg-version: ${{ matrix.pg-version }}
  257. - name: Migration & lockfile checks
  258. env:
  259. SENTRY_LOG_LEVEL: ERROR
  260. PGPASSWORD: postgres
  261. run: |
  262. ./.github/workflows/scripts/migration-check.sh
  263. plugins:
  264. if: needs.files-changed.outputs.plugins == 'true'
  265. needs: files-changed
  266. name: plugins test
  267. runs-on: ubuntu-20.04
  268. timeout-minutes: 10
  269. steps:
  270. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  271. - name: Setup sentry env
  272. uses: ./.github/actions/setup-sentry
  273. id: setup
  274. with:
  275. snuba: true
  276. - name: Run test
  277. run: |
  278. make test-plugins
  279. relay:
  280. if: needs.files-changed.outputs.backend == 'true'
  281. needs: files-changed
  282. name: relay test
  283. runs-on: ubuntu-20.04
  284. timeout-minutes: 20
  285. steps:
  286. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  287. with:
  288. # Avoid codecov error message related to SHA resolution:
  289. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  290. fetch-depth: '2'
  291. - name: Setup sentry env
  292. uses: ./.github/actions/setup-sentry
  293. id: setup
  294. with:
  295. snuba: true
  296. kafka: true
  297. - name: Pull relay image
  298. run: |
  299. # pull relay we'll run and kill it for each test
  300. docker pull us.gcr.io/sentryio/relay:nightly
  301. docker ps -a
  302. - name: Run test
  303. run: |
  304. make test-relay-integration
  305. - name: Handle artifacts
  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]
  320. env:
  321. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  322. MATRIX_INSTANCE_TOTAL: 2
  323. USE_SNUBA: 1
  324. MIGRATIONS_TEST_MIGRATE: 1
  325. steps:
  326. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  327. with:
  328. # Avoid codecov error message related to SHA resolution:
  329. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  330. fetch-depth: '2'
  331. - name: Setup sentry env
  332. uses: ./.github/actions/setup-sentry
  333. id: setup
  334. with:
  335. snuba: true
  336. kafka: true
  337. - name: Run snuba test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  338. run: |
  339. make test-snuba
  340. - name: Handle artifacts
  341. uses: ./.github/actions/artifacts
  342. symbolicator:
  343. if: needs.files-changed.outputs.backend == 'true'
  344. needs: files-changed
  345. name: symbolicator test
  346. runs-on: ubuntu-20.04
  347. timeout-minutes: 10
  348. steps:
  349. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  350. with:
  351. # Avoid codecov error message related to SHA resolution:
  352. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  353. fetch-depth: '2'
  354. - name: Setup sentry env
  355. uses: ./.github/actions/setup-sentry
  356. id: setup
  357. with:
  358. snuba: true
  359. kafka: true
  360. - name: Start symbolicator
  361. run: |
  362. echo $PWD
  363. docker run \
  364. -d \
  365. -v $PWD/config/symbolicator/:/etc/symbolicator \
  366. --network host \
  367. --name symbolicator \
  368. us.gcr.io/sentryio/symbolicator:nightly \
  369. run -c /etc/symbolicator/config.yml
  370. docker ps -a
  371. - name: Run test
  372. run: |
  373. make test-symbolicator
  374. - name: Handle artifacts
  375. uses: ./.github/actions/artifacts
  376. typing:
  377. if: needs.files-changed.outputs.backend == 'true'
  378. needs: files-changed
  379. name: backend typing
  380. runs-on: ubuntu-20.04
  381. timeout-minutes: 12
  382. steps:
  383. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  384. - name: Setup Python
  385. uses: actions/setup-python@c4e89fac7e8767b327bbad6cb4d859eda999cf08 # v4
  386. with:
  387. python-version: 3.8.13
  388. cache: pip
  389. cache-dependency-path: requirements-dev-frozen.txt
  390. # We don't call setup-sentry, because we don't need devservices.
  391. - name: Setup backend typing
  392. run: 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. cli,
  404. lint,
  405. requirements,
  406. migration,
  407. plugins,
  408. relay,
  409. snuba,
  410. symbolicator,
  411. typing,
  412. ]
  413. name: Backend
  414. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  415. if: always()
  416. runs-on: ubuntu-20.04
  417. steps:
  418. # If any jobs we depend on fail, we will fail since this is a required check
  419. # NOTE: A timeout is considered a failure
  420. - name: Check for failures
  421. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  422. run: |
  423. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1