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