backend.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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. # Note: `USE_SNUBA` is not used for backend tests because there are a few failing tests with Snuba enabled.
  128. unset USE_SNUBA
  129. export PYTEST_ADDOPTS="-m 'sentry_metrics and not broken_under_tags_values_as_strings'"
  130. export SENTRY_METRICS_SIMULATE_TAG_VALUES_IN_CLICKHOUSE=1
  131. make test-python-ci
  132. - name: Handle artifacts
  133. uses: ./.github/actions/artifacts
  134. cli:
  135. if: needs.files-changed.outputs.backend == 'true'
  136. needs: files-changed
  137. name: cli test
  138. runs-on: ubuntu-20.04
  139. timeout-minutes: 10
  140. strategy:
  141. matrix:
  142. pg-version: ['9.6']
  143. steps:
  144. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  145. - name: Setup sentry env
  146. uses: ./.github/actions/setup-sentry
  147. id: setup
  148. with:
  149. pg-version: ${{ matrix.pg-version }}
  150. - name: Run test
  151. run: |
  152. make test-cli
  153. - name: Handle artifacts
  154. uses: ./.github/actions/artifacts
  155. requirements:
  156. if: needs.files-changed.outputs.backend_dependencies == 'true'
  157. needs: files-changed
  158. name: requirements check
  159. runs-on: ubuntu-20.04
  160. timeout-minutes: 3
  161. steps:
  162. - uses: getsentry/action-github-app-token@38a3ce582e170ddfe8789f509597c6944f2292a9 # v1
  163. id: token
  164. continue-on-error: true
  165. with:
  166. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  167. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  168. - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3
  169. - uses: actions/setup-python@c4e89fac7e8767b327bbad6cb4d859eda999cf08 # v4
  170. with:
  171. python-version: 3.8.13
  172. - name: check requirements
  173. run: |
  174. python -m pip install -q "$(grep '^pip-tools==' requirements-dev-frozen.txt)"
  175. python -S -m tools.freeze_requirements sentry
  176. if ! git diff --exit-code; then
  177. echo $'\n\nrun `make freeze-requirements` locally to update requirements'
  178. exit 1
  179. fi
  180. - name: apply any requirements changes
  181. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  182. uses: getsentry/action-github-commit@1761f891f036c3efc813b2ba963b121120c1587a # main
  183. with:
  184. github-token: ${{ steps.token.outputs.token }}
  185. message: ':snowflake: re-freeze requirements'
  186. lint:
  187. if: needs.files-changed.outputs.backend == 'true'
  188. needs: files-changed
  189. name: backend lint
  190. runs-on: ubuntu-20.04
  191. timeout-minutes: 10
  192. steps:
  193. - uses: getsentry/action-github-app-token@38a3ce582e170ddfe8789f509597c6944f2292a9 # v1
  194. id: token
  195. continue-on-error: true
  196. with:
  197. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  198. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  199. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  200. - uses: getsentry/paths-filter@66f7f1844185eb7fb6738ea4ea59d74bb99199e5 # v2
  201. id: files
  202. with:
  203. # Enable listing of files matching each filter.
  204. # Paths to files will be available in `${FILTER_NAME}_files` output variable.
  205. # Paths will be escaped and space-delimited.
  206. # Output is usable as command line argument list in linux shell
  207. list-files: shell
  208. # It doesn't make sense to lint deleted files.
  209. # Therefore we specify we are only interested in added or modified files.
  210. filters: |
  211. all:
  212. - added|modified: '**/*.py'
  213. - added|modified: 'requirements-*.txt'
  214. - uses: actions/setup-python@c4e89fac7e8767b327bbad6cb4d859eda999cf08 # v4
  215. with:
  216. python-version: 3.8.13
  217. cache: pip
  218. cache-dependency-path: requirements-dev-only-frozen.txt
  219. - uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8 # v3.0.8
  220. with:
  221. path: ~/.cache/pre-commit
  222. key: cache-epoch-1|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
  223. - name: Setup pre-commit
  224. # We don't use make setup-git because we're only interested in installing
  225. # requirements-dev-only-frozen.txt as a fast path.
  226. # We don't need pre-commit install --install-hooks since we're just interested
  227. # in running the hooks.
  228. run: |
  229. pip install -r requirements-dev-only-frozen.txt
  230. pre-commit install-hooks
  231. - name: Run pre-commit on changed files
  232. run: |
  233. # Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
  234. # XXX: there is a very small chance that it'll expand to exceed Linux's limits
  235. # `getconf ARG_MAX` - max # bytes of args + environ for exec()
  236. pre-commit run --files ${{ steps.files.outputs.all_files }}
  237. - name: Apply any pre-commit fixed files
  238. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  239. uses: getsentry/action-github-commit@1761f891f036c3efc813b2ba963b121120c1587a # main
  240. with:
  241. github-token: ${{ steps.token.outputs.token }}
  242. migration:
  243. if: needs.files-changed.outputs.migration_lockfile == 'true'
  244. needs: files-changed
  245. name: check migration
  246. runs-on: ubuntu-20.04
  247. strategy:
  248. matrix:
  249. pg-version: ['9.6']
  250. steps:
  251. - name: Checkout sentry
  252. uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  253. - name: Setup sentry env
  254. uses: ./.github/actions/setup-sentry
  255. id: setup
  256. with:
  257. pg-version: ${{ matrix.pg-version }}
  258. - name: Migration & lockfile checks
  259. env:
  260. SENTRY_LOG_LEVEL: ERROR
  261. PGPASSWORD: postgres
  262. run: |
  263. ./.github/workflows/scripts/migration-check.sh
  264. plugins:
  265. if: needs.files-changed.outputs.plugins == 'true'
  266. needs: files-changed
  267. name: plugins test
  268. runs-on: ubuntu-20.04
  269. timeout-minutes: 10
  270. steps:
  271. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  272. - name: Setup sentry env
  273. uses: ./.github/actions/setup-sentry
  274. id: setup
  275. with:
  276. snuba: true
  277. - name: Run test
  278. run: |
  279. make test-plugins
  280. relay:
  281. if: needs.files-changed.outputs.backend == 'true'
  282. needs: files-changed
  283. name: relay test
  284. runs-on: ubuntu-20.04
  285. timeout-minutes: 20
  286. steps:
  287. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  288. with:
  289. # Avoid codecov error message related to SHA resolution:
  290. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  291. fetch-depth: '2'
  292. - name: Setup sentry env
  293. uses: ./.github/actions/setup-sentry
  294. id: setup
  295. with:
  296. snuba: true
  297. kafka: true
  298. - name: Pull relay image
  299. run: |
  300. # pull relay we'll run and kill it for each test
  301. docker pull us.gcr.io/sentryio/relay:nightly
  302. docker ps -a
  303. - name: Run test
  304. run: |
  305. make test-relay-integration
  306. - name: Handle artifacts
  307. uses: ./.github/actions/artifacts
  308. snuba:
  309. if: needs.files-changed.outputs.backend == 'true'
  310. needs: files-changed
  311. name: snuba test
  312. runs-on: ubuntu-20.04
  313. timeout-minutes: 30
  314. strategy:
  315. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  316. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  317. fail-fast: false
  318. matrix:
  319. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  320. instance: [0, 1]
  321. env:
  322. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  323. MATRIX_INSTANCE_TOTAL: 2
  324. USE_SNUBA: 1
  325. MIGRATIONS_TEST_MIGRATE: 1
  326. steps:
  327. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  328. with:
  329. # Avoid codecov error message related to SHA resolution:
  330. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  331. fetch-depth: '2'
  332. - name: Setup sentry env
  333. uses: ./.github/actions/setup-sentry
  334. id: setup
  335. with:
  336. snuba: true
  337. kafka: true
  338. - name: Run snuba test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  339. run: |
  340. make test-snuba
  341. - name: Handle artifacts
  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@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: 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. - name: Handle artifacts
  376. uses: ./.github/actions/artifacts
  377. typing:
  378. if: needs.files-changed.outputs.backend == 'true'
  379. needs: files-changed
  380. name: backend typing
  381. runs-on: ubuntu-20.04
  382. timeout-minutes: 12
  383. steps:
  384. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  385. - name: Setup Python
  386. uses: actions/setup-python@c4e89fac7e8767b327bbad6cb4d859eda999cf08 # v4
  387. with:
  388. python-version: 3.8.13
  389. cache: pip
  390. cache-dependency-path: requirements-dev-frozen.txt
  391. # We don't call setup-sentry, because we don't need devservices.
  392. - name: Setup backend typing
  393. run: |
  394. sudo apt-get update
  395. sudo apt-get install -y --no-install-recommends libxmlsec1-dev
  396. pip install -r requirements-dev-frozen.txt
  397. - name: Run backend typing (${{ steps.setup.outputs.matrix-instance-number }} of ${{ strategy.job-total }})
  398. run: |
  399. 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