backend.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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@v2
  22. - name: Check for backend file changes
  23. uses: getsentry/paths-filter@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@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@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. python-version: [3.8.12]
  100. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  101. instance: [0]
  102. pg-version: ['9.6']
  103. env:
  104. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  105. MATRIX_INSTANCE_TOTAL: 1
  106. MIGRATIONS_TEST_MIGRATE: 1
  107. steps:
  108. - uses: actions/checkout@v2
  109. with:
  110. # Avoid codecov error message related to SHA resolution:
  111. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  112. fetch-depth: '2'
  113. - name: Setup sentry env (python ${{ matrix.python-version }})
  114. uses: ./.github/actions/setup-sentry
  115. id: setup
  116. with:
  117. python-version: ${{ matrix.python-version }}
  118. pip-cache-version: ${{ secrets.PIP_CACHE_VERSION }}
  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@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. # Assuming Python 3.8 in GHA's ubuntu 20.04. If we run into any issues,
  162. # this can just be pinned with setup-python.
  163. steps:
  164. - uses: actions/checkout@v3
  165. - name: check requirements
  166. run: |
  167. python -m pip install 'pip-tools==6.7.0'
  168. python -S -m tools.check_frozen_requirements sentry
  169. lint:
  170. if: needs.files-changed.outputs.backend == 'true'
  171. needs: files-changed
  172. name: backend lint
  173. runs-on: ubuntu-20.04
  174. timeout-minutes: 10
  175. steps:
  176. - uses: actions/checkout@v2
  177. - name: Internal github app token
  178. id: token
  179. uses: getsentry/action-github-app-token@v1
  180. continue-on-error: true
  181. with:
  182. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  183. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  184. - uses: getsentry/paths-filter@v2
  185. id: files
  186. with:
  187. # Enable listing of files matching each filter.
  188. # Paths to files will be available in `${FILTER_NAME}_files` output variable.
  189. # Paths will be escaped and space-delimited.
  190. # Output is usable as command line argument list in linux shell
  191. list-files: shell
  192. # It doesn't make sense to lint deleted files.
  193. # Therefore we specify we are only interested in added or modified files.
  194. filters: |
  195. all:
  196. - added|modified: '**/*.py'
  197. - added|modified: 'requirements-*.txt'
  198. - uses: actions/setup-python@v4
  199. with:
  200. python-version: 3.8.13
  201. cache: pip
  202. cache-dependency-path: requirements-dev-only-frozen.txt
  203. - uses: actions/cache@v3
  204. with:
  205. path: ~/.cache/pre-commit
  206. key: cache-epoch-1|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
  207. - name: Setup pre-commit
  208. # We don't use make setup-git because we're only interested in installing
  209. # requirements-dev-only-frozen.txt as a fast path.
  210. # We don't need pre-commit install --install-hooks since we're just interested
  211. # in running the hooks.
  212. run: |
  213. pip install -r requirements-dev-only-frozen.txt
  214. pre-commit install-hooks
  215. - name: Run pre-commit on changed files
  216. run: |
  217. # Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
  218. # XXX: there is a very small chance that it'll expand to exceed Linux's limits
  219. # `getconf ARG_MAX` - max # bytes of args + environ for exec()
  220. pre-commit run --files ${{ steps.files.outputs.all_files }}
  221. # If working tree is dirty, commit and update if we have a token
  222. - name: Apply any pre-commit fixed files
  223. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
  224. uses: getsentry/action-github-commit@main
  225. with:
  226. github-token: ${{ steps.token.outputs.token }}
  227. migration:
  228. if: needs.files-changed.outputs.migration_lockfile == 'true'
  229. needs: files-changed
  230. name: check migration
  231. runs-on: ubuntu-20.04
  232. strategy:
  233. matrix:
  234. pg-version: ['9.6']
  235. steps:
  236. - name: Checkout sentry
  237. uses: actions/checkout@v2
  238. - name: Setup sentry env
  239. uses: ./.github/actions/setup-sentry
  240. id: setup
  241. with:
  242. pg-version: ${{ matrix.pg-version }}
  243. - name: Migration & lockfile checks
  244. env:
  245. SENTRY_LOG_LEVEL: ERROR
  246. PGPASSWORD: postgres
  247. run: |
  248. ./.github/workflows/scripts/migration-check.sh
  249. plugins:
  250. if: needs.files-changed.outputs.plugins == 'true'
  251. needs: files-changed
  252. name: plugins test
  253. runs-on: ubuntu-20.04
  254. timeout-minutes: 10
  255. steps:
  256. - uses: actions/checkout@v2
  257. - name: Setup sentry env
  258. uses: ./.github/actions/setup-sentry
  259. id: setup
  260. with:
  261. snuba: true
  262. - name: Run test
  263. run: |
  264. make test-plugins
  265. relay:
  266. if: needs.files-changed.outputs.backend == 'true'
  267. needs: files-changed
  268. name: relay test
  269. runs-on: ubuntu-20.04
  270. timeout-minutes: 20
  271. steps:
  272. - uses: actions/checkout@v2
  273. with:
  274. # Avoid codecov error message related to SHA resolution:
  275. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  276. fetch-depth: '2'
  277. - name: Setup sentry env
  278. uses: ./.github/actions/setup-sentry
  279. id: setup
  280. with:
  281. snuba: true
  282. kafka: true
  283. - name: Pull relay image
  284. run: |
  285. # pull relay we'll run and kill it for each test
  286. docker pull us.gcr.io/sentryio/relay:nightly
  287. docker ps -a
  288. - name: Run test
  289. run: |
  290. make test-relay-integration
  291. - name: Handle artifacts
  292. uses: ./.github/actions/artifacts
  293. snuba:
  294. if: needs.files-changed.outputs.backend == 'true'
  295. needs: files-changed
  296. name: snuba test
  297. runs-on: ubuntu-20.04
  298. timeout-minutes: 30
  299. strategy:
  300. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  301. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  302. fail-fast: false
  303. matrix:
  304. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  305. instance: [0, 1]
  306. env:
  307. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  308. MATRIX_INSTANCE_TOTAL: 2
  309. USE_SNUBA: 1
  310. MIGRATIONS_TEST_MIGRATE: 1
  311. steps:
  312. - uses: actions/checkout@v2
  313. with:
  314. # Avoid codecov error message related to SHA resolution:
  315. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  316. fetch-depth: '2'
  317. - name: Setup sentry env
  318. uses: ./.github/actions/setup-sentry
  319. id: setup
  320. with:
  321. snuba: true
  322. kafka: true
  323. - name: Run snuba test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  324. run: |
  325. make test-snuba
  326. - name: Handle artifacts
  327. uses: ./.github/actions/artifacts
  328. symbolicator:
  329. if: needs.files-changed.outputs.backend == 'true'
  330. needs: files-changed
  331. name: symbolicator test
  332. runs-on: ubuntu-20.04
  333. timeout-minutes: 10
  334. steps:
  335. - uses: actions/checkout@v2
  336. with:
  337. # Avoid codecov error message related to SHA resolution:
  338. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  339. fetch-depth: '2'
  340. - name: Setup sentry env
  341. uses: ./.github/actions/setup-sentry
  342. id: setup
  343. with:
  344. snuba: true
  345. kafka: true
  346. - name: Start symbolicator
  347. run: |
  348. echo $PWD
  349. docker run \
  350. -d \
  351. -v $PWD/config/symbolicator/:/etc/symbolicator \
  352. --network host \
  353. --name symbolicator \
  354. us.gcr.io/sentryio/symbolicator:nightly \
  355. run -c /etc/symbolicator/config.yml
  356. docker ps -a
  357. - name: Run test
  358. run: |
  359. make test-symbolicator
  360. - name: Handle artifacts
  361. uses: ./.github/actions/artifacts
  362. typing:
  363. if: needs.files-changed.outputs.backend == 'true'
  364. needs: files-changed
  365. name: backend typing
  366. runs-on: ubuntu-20.04
  367. timeout-minutes: 12
  368. steps:
  369. - uses: actions/checkout@v2
  370. - name: Setup Python
  371. uses: actions/setup-python@v4
  372. with:
  373. python-version: 3.8.13
  374. cache: pip
  375. cache-dependency-path: requirements-dev-frozen.txt
  376. # We don't call setup-sentry, because we don't need devservices.
  377. - name: Setup backend typing
  378. run: |
  379. sudo apt-get update
  380. sudo apt-get install -y --no-install-recommends libxmlsec1-dev
  381. pip install -r requirements-dev-frozen.txt
  382. - name: Run backend typing (${{ steps.setup.outputs.matrix-instance-number }} of ${{ strategy.job-total }})
  383. run: |
  384. make backend-typing
  385. # This check runs once all dependant jobs have passed
  386. # It symbolizes that all required Backend checks have succesfully passed (Or skipped)
  387. # This check is the only required Github check
  388. backend-required-check:
  389. needs:
  390. [
  391. api-docs,
  392. backend-test,
  393. cli,
  394. lint,
  395. requirements,
  396. migration,
  397. plugins,
  398. relay,
  399. snuba,
  400. symbolicator,
  401. typing,
  402. ]
  403. name: Backend
  404. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  405. if: always()
  406. runs-on: ubuntu-20.04
  407. steps:
  408. # If any jobs we depend on fail, we will fail since this is a required check
  409. # NOTE: A timeout is considered a failure
  410. - name: Check for failures
  411. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  412. run: |
  413. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1