acceptance.yml 11 KB

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