acceptance.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. if: needs.files-changed.outputs.acceptance == 'true'
  34. needs: files-changed
  35. name: frontend tests
  36. runs-on: ubuntu-20.04
  37. timeout-minutes: 20
  38. strategy:
  39. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  40. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  41. fail-fast: false
  42. matrix:
  43. # XXX: When updating this, make sure you also update CI_NODE_TOTAL.
  44. instance: [0, 1, 2, 3]
  45. env:
  46. VISUAL_HTML_ENABLE: 1
  47. steps:
  48. - uses: actions/checkout@v2
  49. name: Checkout sentry
  50. with:
  51. # Avoid codecov error message related to SHA resolution:
  52. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  53. fetch-depth: '2'
  54. - uses: volta-cli/action@v1
  55. # See https://github.com/actions/cache/blob/master/examples.md#node---yarn for example
  56. - name: Get yarn cache directory path
  57. id: yarn-cache-dir-path
  58. run: echo "::set-output name=dir::$(yarn cache dir)"
  59. - uses: actions/cache@v1 # We are explicitly using v1 due to perf reasons
  60. with:
  61. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  62. key: ${{ runner.os }}-v2-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  63. - name: Install dependencies
  64. run: yarn install --frozen-lockfile
  65. - name: Build CSS
  66. run: NODE_ENV=production yarn build-css
  67. - name: jest
  68. env:
  69. GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  70. GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }}
  71. # XXX: CI_NODE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  72. # Otherwise, if there are other things in the matrix, using strategy.job-total
  73. # wouldn't be correct.
  74. CI_NODE_TOTAL: 4
  75. CI_NODE_INDEX: ${{ matrix.instance }}
  76. run: |
  77. JEST_TESTS=$(yarn -s jest --listTests --json) yarn test-ci --forceExit
  78. - name: Save HTML artifacts
  79. uses: actions/upload-artifact@v2
  80. with:
  81. retention-days: 14
  82. name: jest-html
  83. path: .artifacts/visual-snapshots/jest
  84. - name: Create Images from HTML
  85. uses: getsentry/action-html-to-image@main
  86. with:
  87. base-path: .artifacts/visual-snapshots/jest
  88. css-path: src/sentry/static/sentry/dist/entrypoints/sentry.css
  89. - name: Save snapshots
  90. uses: getsentry/action-visual-snapshot@main
  91. with:
  92. save-only: true
  93. snapshot-path: .artifacts/visual-snapshots
  94. - name: Handle artifacts
  95. uses: ./.github/actions/artifacts
  96. with:
  97. files: .artifacts/coverage/*
  98. type: frontend
  99. acceptance:
  100. if: needs.files-changed.outputs.acceptance == 'true'
  101. needs: files-changed
  102. name: acceptance
  103. runs-on: ubuntu-20.04
  104. timeout-minutes: 20
  105. strategy:
  106. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  107. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  108. fail-fast: false
  109. matrix:
  110. python-version: [3.8.12]
  111. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  112. instance: [0, 1, 2, 3]
  113. pg-version: ['9.6']
  114. env:
  115. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  116. MATRIX_INSTANCE_TOTAL: 4
  117. VISUAL_SNAPSHOT_ENABLE: 1
  118. TEST_GROUP_STRATEGY: roundrobin
  119. steps:
  120. - uses: actions/checkout@v2
  121. name: Checkout sentry
  122. - uses: volta-cli/action@v1
  123. - name: Step configurations
  124. id: config
  125. run: |
  126. echo "::set-output name=yarn-path::$(yarn cache dir)"
  127. echo "::set-output name=webpack-path::.webpack_cache"
  128. - name: yarn cache
  129. uses: actions/cache@v1 # We are explicitly using v1 due to perf reasons
  130. with:
  131. path: ${{ steps.config.outputs.yarn-path }}
  132. key: ${{ runner.os }}-v2-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  133. - name: webpack cache
  134. uses: actions/cache@v2
  135. with:
  136. path: ${{ steps.config.outputs.webpack-path }}
  137. key: ${{ runner.os }}-v2-webpack-cache-${{ hashFiles('webpack.config.ts') }}
  138. - name: Install Javascript Dependencies
  139. run: |
  140. yarn install --frozen-lockfile
  141. - name: webpack
  142. env:
  143. WEBPACK_CACHE_PATH: ${{ steps.config.outputs.webpack-path }}
  144. SENTRY_INSTRUMENTATION: 1
  145. # this is fine to not have for forks, it shouldn't fail
  146. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  147. run: |
  148. yarn build-acceptance
  149. - name: Setup sentry env (python ${{ matrix.python-version }})
  150. uses: ./.github/actions/setup-sentry
  151. id: setup
  152. with:
  153. python-version: ${{ matrix.python-version }}
  154. pip-cache-version: ${{ secrets.PIP_CACHE_VERSION }}
  155. snuba: true
  156. pg-version: ${{ matrix.pg-version }}
  157. - name: Run acceptance tests (#${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  158. run: |
  159. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}
  160. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}-mobile
  161. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}-tooltips
  162. make run-acceptance
  163. env:
  164. PYTEST_SNAPSHOTS_DIR: ${{ steps.setup.outputs.acceptance-dir }}
  165. USE_SNUBA: 1
  166. - name: Save snapshots
  167. uses: getsentry/action-visual-snapshot@main
  168. with:
  169. save-only: true
  170. snapshot-path: .artifacts/visual-snapshots
  171. - name: Handle artifacts
  172. uses: ./.github/actions/artifacts
  173. if: needs.files-changed.outputs.backend == 'true'
  174. chartcuterie:
  175. if: needs.files-changed.outputs.acceptance == 'true'
  176. needs: files-changed
  177. name: chartcuterie integration
  178. runs-on: ubuntu-20.04
  179. timeout-minutes: 30
  180. strategy:
  181. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  182. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  183. fail-fast: false
  184. matrix:
  185. python-version: [3.8.12]
  186. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  187. instance: [0]
  188. env:
  189. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  190. MATRIX_INSTANCE_TOTAL: 1
  191. TEST_GROUP_STRATEGY: roundrobin
  192. VISUAL_SNAPSHOT_ENABLE: 1
  193. steps:
  194. - uses: actions/checkout@v2
  195. with:
  196. # Avoid codecov error message related to SHA resolution:
  197. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  198. fetch-depth: '2'
  199. - name: Setup sentry env (python ${{ matrix.python-version }})
  200. uses: ./.github/actions/setup-sentry
  201. id: setup
  202. with:
  203. python-version: ${{ matrix.python-version }}
  204. pip-cache-version: ${{ secrets.PIP_CACHE_VERSION }}
  205. chartcuterie: true
  206. - name: yarn cache
  207. uses: actions/cache@v1 # We are explicitly using v1 due to perf reasons
  208. with:
  209. path: ${{ steps.setup.outputs.yarn-cache-dir }}
  210. key: ${{ runner.os }}-v2-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  211. - name: Install Javascript Dependencies
  212. run: |
  213. yarn install --frozen-lockfile
  214. - name: Build chartcuterie configuration module
  215. run: |
  216. make build-chartcuterie-config
  217. - name: Run chartcuterie tests (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  218. run: |
  219. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}
  220. make test-chartcuterie
  221. env:
  222. PYTEST_SNAPSHOTS_DIR: ${{ steps.setup.outputs.acceptance-dir }}
  223. - name: Save snapshots
  224. uses: getsentry/action-visual-snapshot@main
  225. with:
  226. save-only: true
  227. snapshot-path: .artifacts/visual-snapshots
  228. - name: Handle artifacts
  229. uses: ./.github/actions/artifacts
  230. if: needs.files-changed.outputs.backend == 'true'
  231. visual-diff:
  232. if: always()
  233. # This guarantees that we will only schedule Visual Snapshots if all
  234. # workflows that generate artifacts succeed
  235. needs: [acceptance, frontend, chartcuterie, files-changed]
  236. name: triggers visual snapshot
  237. runs-on: ubuntu-20.04
  238. timeout-minutes: 20
  239. steps:
  240. # If any jobs we depend on fail, we will fail since this checks triggers Visual Snapshots which is a required check
  241. # NOTE: A timeout is considered a failure
  242. - name: Check for failures
  243. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  244. run: |
  245. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1
  246. - name: Determine snapshot version
  247. id: snapshot_ref
  248. run: |
  249. random=$(( ( RANDOM % 10 ) + 1 ));
  250. echo "::set-output name=ref::$([[ $random -ge 3 ]] && echo "pixelmatch" || echo "odiff")"
  251. - name: Diff snapshots
  252. id: visual-snapshots-diff-pixelmatch
  253. uses: getsentry/action-visual-snapshot@main
  254. # Run this step only if there are acceptance related code changes
  255. # Forks are handled in visual-diff.yml
  256. if: steps.snapshot_ref.outputs.ref == 'pixelmatch' && needs.files-changed.outputs.acceptance == 'true' && github.event.pull_request.head.repo.full_name == 'getsentry/sentry'
  257. with:
  258. api-token: ${{ secrets.VISUAL_SNAPSHOT_SECRET }}
  259. gcs-bucket: 'sentry-visual-snapshots'
  260. gcp-service-account-key: ${{ secrets.SNAPSHOT_GOOGLE_SERVICE_ACCOUNT_KEY }}
  261. - name: Diff snapshots
  262. id: visual-snapshots-diff-odiff
  263. uses: getsentry/action-visual-snapshot@905b7e3a7fdd913189b9a35dcef51b6b927f9598
  264. # Run this step only if there are acceptance related code changes
  265. # Forks are handled in visual-diff.yml
  266. if: steps.snapshot_ref.outputs.ref == 'odiff' && needs.files-changed.outputs.acceptance == 'true' && github.event.pull_request.head.repo.full_name == 'getsentry/sentry'
  267. with:
  268. api-token: ${{ secrets.VISUAL_SNAPSHOT_SECRET }}
  269. gcs-bucket: 'sentry-visual-snapshots'
  270. gcp-service-account-key: ${{ secrets.SNAPSHOT_GOOGLE_SERVICE_ACCOUNT_KEY }}
  271. # Since Visual Snapshot is a required check we need to pretend to have run
  272. fake-visual-snapshot:
  273. name: Visual Snapshot
  274. needs: [files-changed]
  275. # Opposite condition to "triggers visual snapshot" required check
  276. if: needs.files-changed.outputs.acceptance != 'true'
  277. runs-on: ubuntu-20.04
  278. steps:
  279. - name: Sentaur attack
  280. run: |
  281. echo "This check pretends to be the Visual Snapshot to satisfy Github required checks"