backend.yml 17 KB

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