acceptance.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. # TODO(billy): this workflow has not been re-named from `acceptance` because
  2. # Visual Snapshots compares against artifacts from the same workflow name (on main branch)
  3. # We should rename this when we have a more finalized naming scheme.
  4. #
  5. # Also note that this name *MUST* match the filename because GHA
  6. # only provides the workflow name (https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables)
  7. # and GH APIs only support querying by workflow *FILENAME* (https://developer.github.com/v3/actions/workflows/#get-a-workflow)
  8. name: acceptance
  9. on:
  10. push:
  11. branches:
  12. - master
  13. - releases/**
  14. pull_request:
  15. jobs:
  16. files-changed:
  17. name: detect what files changed
  18. runs-on: ubuntu-20.04
  19. timeout-minutes: 3
  20. # Map a step output to a job output
  21. outputs:
  22. acceptance: ${{ steps.changes.outputs.acceptance }}
  23. backend: ${{ steps.changes.outputs.backend }}
  24. steps:
  25. - uses: actions/checkout@v2
  26. - name: Check for backend file changes
  27. uses: getsentry/paths-filter@v2
  28. id: changes
  29. with:
  30. token: ${{ github.token }}
  31. filters: .github/file-filters.yml
  32. frontend:
  33. needs: files-changed
  34. name: frontend tests
  35. runs-on: ubuntu-20.04
  36. timeout-minutes: 20
  37. strategy:
  38. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  39. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  40. fail-fast: false
  41. matrix:
  42. # XXX: When updating this, make sure you also update CI_NODE_TOTAL.
  43. instance: [0, 1, 2, 3]
  44. env:
  45. VISUAL_HTML_ENABLE: 1
  46. steps:
  47. - uses: actions/checkout@v2
  48. name: Checkout sentry
  49. with:
  50. # Avoid codecov error message related to SHA resolution:
  51. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  52. fetch-depth: '2'
  53. - uses: volta-cli/action@v1
  54. # See https://github.com/actions/cache/blob/master/examples.md#node---yarn for example
  55. - name: Get yarn cache directory path
  56. id: yarn-cache-dir-path
  57. run: echo "::set-output name=dir::$(yarn cache dir)"
  58. - uses: actions/cache@v1 # We are explicitly using v1 due to perf reasons
  59. with:
  60. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  61. key: ${{ runner.os }}-v2-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  62. - name: Install dependencies
  63. run: yarn install --frozen-lockfile
  64. - name: Build CSS
  65. run: NODE_ENV=production yarn build-css
  66. - name: jest
  67. env:
  68. GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  69. GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }}
  70. # XXX: CI_NODE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  71. # Otherwise, if there are other things in the matrix, using strategy.job-total
  72. # wouldn't be correct.
  73. CI_NODE_TOTAL: 4
  74. CI_NODE_INDEX: ${{ matrix.instance }}
  75. run: |
  76. JEST_TESTS=$(yarn -s jest --listTests --json) yarn test-ci --forceExit
  77. - name: Save HTML artifacts
  78. uses: actions/upload-artifact@v2
  79. with:
  80. retention-days: 14
  81. name: jest-html
  82. path: .artifacts/visual-snapshots/jest
  83. - name: Create Images from HTML
  84. uses: getsentry/action-html-to-image@main
  85. with:
  86. base-path: .artifacts/visual-snapshots/jest
  87. css-path: src/sentry/static/sentry/dist/entrypoints/sentry.css
  88. - name: Save snapshots
  89. uses: getsentry/action-visual-snapshot@v2
  90. with:
  91. save-only: true
  92. snapshot-path: .artifacts/visual-snapshots
  93. - name: Handle artifacts
  94. uses: ./.github/actions/artifacts
  95. with:
  96. files: .artifacts/coverage/*
  97. type: frontend
  98. webpack:
  99. needs: files-changed
  100. name: create frontend bundle
  101. runs-on: ubuntu-20.04
  102. timeout-minutes: 10
  103. outputs:
  104. dist-path: ${{ steps.config.outputs.dist-path }}
  105. steps:
  106. - uses: actions/checkout@v2
  107. name: Checkout sentry
  108. - uses: volta-cli/action@v1
  109. - name: Step configurations
  110. id: config
  111. run: |
  112. echo "::set-output name=yarn-path::$(yarn cache dir)"
  113. echo "::set-output name=webpack-path::.webpack_cache"
  114. echo "::set-output name=dist-path::src/sentry/static/sentry/dist"
  115. - name: yarn cache
  116. uses: actions/cache@v1 # We are explicitly using v1 due to perf reasons
  117. with:
  118. path: ${{ steps.config.outputs.yarn-path }}
  119. key: ${{ runner.os }}-v2-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  120. - name: webpack cache
  121. uses: actions/cache@v2
  122. with:
  123. path: ${{ steps.config.outputs.webpack-path }}
  124. key: ${{ runner.os }}-v2-webpack-cache-${{ hashFiles('webpack.config.ts') }}
  125. - name: Install Javascript Dependencies
  126. run: |
  127. yarn install --frozen-lockfile
  128. - name: webpack
  129. env:
  130. WEBPACK_CACHE_PATH: ${{ steps.config.outputs.webpack-path }}
  131. SENTRY_INSTRUMENTATION: 1
  132. # this is fine to not have for forks, it shouldn't fail
  133. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  134. run: |
  135. yarn build-acceptance
  136. # Bundle dist for faster uploading
  137. - name: bundle dist
  138. run: |
  139. tar czf dist.tar.gz ${{ steps.config.outputs.dist-path }}
  140. - name: Save frontend dist
  141. uses: actions/upload-artifact@v2
  142. with:
  143. retention-days: 3
  144. name: frontend-dist
  145. path: dist.tar.gz
  146. acceptance:
  147. needs: files-changed
  148. name: acceptance
  149. runs-on: ubuntu-20.04
  150. timeout-minutes: 20
  151. strategy:
  152. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  153. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  154. fail-fast: false
  155. matrix:
  156. python-version: [3.8.12]
  157. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  158. instance: [0, 1, 2, 3]
  159. pg-version: ['9.6', '14']
  160. env:
  161. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  162. MATRIX_INSTANCE_TOTAL: 4
  163. VISUAL_SNAPSHOT_ENABLE: 1
  164. TEST_GROUP_STRATEGY: roundrobin
  165. steps:
  166. - name: Checkout sentry
  167. uses: actions/checkout@v2
  168. - name: Setup sentry env (python ${{ matrix.python-version }})
  169. uses: ./.github/actions/setup-sentry
  170. id: setup
  171. with:
  172. python-version: ${{ matrix.python-version }}
  173. pip-cache-version: ${{ secrets.PIP_CACHE_VERSION }}
  174. snuba: true
  175. pg-version: ${{ matrix.pg-version }}
  176. - name: Wait for frontend build
  177. uses: getsentry/action-wait-for-check@v1.0.0
  178. id: wait-for-frontend
  179. with:
  180. token: ${{ secrets.GITHUB_TOKEN }}
  181. checkName: create frontend bundle
  182. ref: ${{ github.event.pull_request.head.sha || github.sha }}
  183. - name: Download frontend dist
  184. uses: actions/download-artifact@v2
  185. with:
  186. name: frontend-dist
  187. - name: Extract dist
  188. run: |
  189. tar xf dist.tar.gz
  190. - name: Run acceptance tests (#${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  191. run: |
  192. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}
  193. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}-mobile
  194. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}-tooltips
  195. make run-acceptance
  196. env:
  197. PYTEST_SNAPSHOTS_DIR: ${{ steps.setup.outputs.acceptance-dir }}
  198. USE_SNUBA: 1
  199. - name: Save snapshots
  200. uses: getsentry/action-visual-snapshot@v2
  201. with:
  202. save-only: true
  203. snapshot-path: .artifacts/visual-snapshots
  204. - name: Handle artifacts
  205. uses: ./.github/actions/artifacts
  206. if: ${{ needs.files-changed.outputs.backend == 'true' }}
  207. chartcuterie:
  208. needs: files-changed
  209. name: chartcuterie integration
  210. runs-on: ubuntu-20.04
  211. timeout-minutes: 30
  212. strategy:
  213. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  214. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  215. fail-fast: false
  216. matrix:
  217. python-version: [3.8.12]
  218. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  219. instance: [0]
  220. env:
  221. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  222. MATRIX_INSTANCE_TOTAL: 1
  223. TEST_GROUP_STRATEGY: roundrobin
  224. VISUAL_SNAPSHOT_ENABLE: 1
  225. steps:
  226. - uses: actions/checkout@v2
  227. with:
  228. # Avoid codecov error message related to SHA resolution:
  229. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  230. fetch-depth: '2'
  231. - name: Setup sentry env (python ${{ matrix.python-version }})
  232. uses: ./.github/actions/setup-sentry
  233. id: setup
  234. with:
  235. python-version: ${{ matrix.python-version }}
  236. pip-cache-version: ${{ secrets.PIP_CACHE_VERSION }}
  237. chartcuterie: true
  238. - name: yarn cache
  239. uses: actions/cache@v1 # We are explicitly using v1 due to perf reasons
  240. with:
  241. path: ${{ steps.setup.outputs.yarn-cache-dir }}
  242. key: ${{ runner.os }}-v2-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  243. - name: Install Javascript Dependencies
  244. run: |
  245. yarn install --frozen-lockfile
  246. - name: Build chartcuterie configuration module
  247. run: |
  248. make build-chartcuterie-config
  249. - name: Run chartcuterie tests (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  250. run: |
  251. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}
  252. make test-chartcuterie
  253. env:
  254. PYTEST_SNAPSHOTS_DIR: ${{ steps.setup.outputs.acceptance-dir }}
  255. - name: Save snapshots
  256. uses: getsentry/action-visual-snapshot@v2
  257. with:
  258. save-only: true
  259. snapshot-path: .artifacts/visual-snapshots
  260. - name: Handle artifacts
  261. uses: ./.github/actions/artifacts
  262. if: ${{ needs.files-changed.outputs.backend == 'true' }}
  263. visual-diff:
  264. # This guarantees that we will only schedule Visual Snapshots if all
  265. # workflows that generate artifacts succeed
  266. needs: [acceptance, frontend, chartcuterie]
  267. name: triggers visual snapshot
  268. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  269. if: always()
  270. runs-on: ubuntu-20.04
  271. timeout-minutes: 20
  272. steps:
  273. # If any jobs we depend on fail, we will fail since this checks triggers Visual Snapshots which is a required check
  274. - name: Check for failures
  275. if: contains(needs.*.result, 'failure')
  276. run: |
  277. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1
  278. - name: Diff snapshots
  279. id: visual-snapshots-diff
  280. uses: getsentry/action-visual-snapshot@v2
  281. # Do not execute on forks. Forks are handled in visual-diff.yml
  282. if: github.event.pull_request.head.repo.full_name == 'getsentry/sentry' || github.ref == 'refs/heads/master'
  283. with:
  284. api-token: ${{ secrets.VISUAL_SNAPSHOT_SECRET }}
  285. gcs-bucket: 'sentry-visual-snapshots'
  286. gcp-service-account-key: ${{ secrets.SNAPSHOT_GOOGLE_SERVICE_ACCOUNT_KEY }}