acceptance.yml 11 KB

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