backend.yml 14 KB

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