acceptance.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. # Cancel in progress workflows on pull_requests.
  16. # https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
  17. concurrency:
  18. group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  19. cancel-in-progress: true
  20. # hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
  21. env:
  22. SEGMENT_DOWNLOAD_TIMEOUT_MIN: 3
  23. jobs:
  24. files-changed:
  25. name: detect what files changed
  26. runs-on: ubuntu-20.04
  27. timeout-minutes: 3
  28. # Map a step output to a job output
  29. outputs:
  30. acceptance: ${{ steps.changes.outputs.acceptance }}
  31. backend: ${{ steps.changes.outputs.backend_all }}
  32. steps:
  33. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  34. - name: Check for backend file changes
  35. uses: getsentry/paths-filter@66f7f1844185eb7fb6738ea4ea59d74bb99199e5 # v2
  36. id: changes
  37. with:
  38. token: ${{ github.token }}
  39. filters: .github/file-filters.yml
  40. frontend:
  41. if: needs.files-changed.outputs.acceptance == 'true'
  42. needs: files-changed
  43. name: frontend tests
  44. runs-on: ubuntu-20.04
  45. timeout-minutes: 20
  46. strategy:
  47. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  48. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  49. fail-fast: false
  50. matrix:
  51. # XXX: When updating this, make sure you also update CI_NODE_TOTAL.
  52. instance: [0, 1, 2, 3]
  53. env:
  54. VISUAL_HTML_ENABLE: 1
  55. steps:
  56. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  57. name: Checkout sentry
  58. with:
  59. # Avoid codecov error message related to SHA resolution:
  60. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  61. fetch-depth: '2'
  62. - uses: ./.github/actions/setup-volta
  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@82c141cc518b40d92cc801eee768e7aafc9c2fa2 # 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@dc153dae538e6e1138f77156d8e62e3b2b897f41 # 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@e832d70549c14886ddc2ab809b436ba72e30e19b # 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: 25
  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. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  111. instance: [0, 1, 2, 3]
  112. pg-version: ['9.6']
  113. env:
  114. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  115. MATRIX_INSTANCE_TOTAL: 4
  116. VISUAL_SNAPSHOT_ENABLE: 1
  117. TEST_GROUP_STRATEGY: roundrobin
  118. steps:
  119. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  120. name: Checkout sentry
  121. - uses: ./.github/actions/setup-volta
  122. - name: Step configurations
  123. id: config
  124. run: echo "webpack-path=.webpack_cache" >> "$GITHUB_OUTPUT"
  125. - name: webpack cache
  126. uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8 # v3.0.8
  127. with:
  128. path: ${{ steps.config.outputs.webpack-path }}
  129. key: ${{ runner.os }}-v2-webpack-cache-${{ hashFiles('webpack.config.ts') }}
  130. - name: Install Javascript Dependencies
  131. run: |
  132. yarn install --frozen-lockfile
  133. - name: webpack
  134. env:
  135. WEBPACK_CACHE_PATH: ${{ steps.config.outputs.webpack-path }}
  136. SENTRY_INSTRUMENTATION: 1
  137. # this is fine to not have for forks, it shouldn't fail
  138. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  139. run: |
  140. yarn build-acceptance
  141. - name: Setup sentry env
  142. uses: ./.github/actions/setup-sentry
  143. id: setup
  144. with:
  145. snuba: true
  146. pg-version: ${{ matrix.pg-version }}
  147. - name: Run acceptance tests (#${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  148. run: |
  149. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}
  150. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}-mobile
  151. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}-tooltips
  152. make run-acceptance
  153. env:
  154. PYTEST_SNAPSHOTS_DIR: ${{ steps.setup.outputs.acceptance-dir }}
  155. - name: Save snapshots
  156. uses: getsentry/action-visual-snapshot@e832d70549c14886ddc2ab809b436ba72e30e19b # main
  157. with:
  158. save-only: true
  159. snapshot-path: .artifacts/visual-snapshots
  160. - name: Handle artifacts
  161. uses: ./.github/actions/artifacts
  162. if: needs.files-changed.outputs.backend_all == 'true'
  163. chartcuterie:
  164. if: needs.files-changed.outputs.acceptance == 'true'
  165. needs: files-changed
  166. name: chartcuterie integration
  167. runs-on: ubuntu-20.04
  168. timeout-minutes: 30
  169. strategy:
  170. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  171. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  172. fail-fast: false
  173. matrix:
  174. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  175. instance: [0]
  176. env:
  177. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  178. MATRIX_INSTANCE_TOTAL: 1
  179. TEST_GROUP_STRATEGY: roundrobin
  180. VISUAL_SNAPSHOT_ENABLE: 1
  181. steps:
  182. - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
  183. with:
  184. # Avoid codecov error message related to SHA resolution:
  185. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  186. fetch-depth: '2'
  187. - name: Setup sentry env
  188. uses: ./.github/actions/setup-sentry
  189. id: setup
  190. with:
  191. chartcuterie: true
  192. - name: yarn cache
  193. uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8 # v3.0.8
  194. with:
  195. path: ${{ steps.setup.outputs.yarn-cache-dir }}
  196. key: ${{ runner.os }}-v2-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  197. - name: Install Javascript Dependencies
  198. run: |
  199. yarn install --frozen-lockfile
  200. - name: Build chartcuterie configuration module
  201. run: |
  202. make build-chartcuterie-config
  203. - name: Run chartcuterie tests (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  204. run: |
  205. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}
  206. make test-chartcuterie
  207. env:
  208. PYTEST_SNAPSHOTS_DIR: ${{ steps.setup.outputs.acceptance-dir }}
  209. - name: Save snapshots
  210. uses: getsentry/action-visual-snapshot@e832d70549c14886ddc2ab809b436ba72e30e19b # main
  211. with:
  212. save-only: true
  213. snapshot-path: .artifacts/visual-snapshots
  214. - name: Handle artifacts
  215. uses: ./.github/actions/artifacts
  216. if: needs.files-changed.outputs.backend_all == 'true'
  217. visual-diff:
  218. if: always()
  219. # This guarantees that we will only schedule Visual Snapshots if all
  220. # workflows that generate artifacts succeed
  221. needs: [acceptance, frontend, chartcuterie, files-changed]
  222. name: triggers visual snapshot
  223. runs-on: ubuntu-20.04
  224. timeout-minutes: 20
  225. steps:
  226. # If any jobs we depend on fail, we will fail since this checks triggers Visual Snapshots which is a required check
  227. # NOTE: A timeout is considered a failure
  228. - name: Check for failures
  229. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  230. run: |
  231. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1
  232. - name: Diff snapshots
  233. uses: getsentry/action-visual-snapshot@e832d70549c14886ddc2ab809b436ba72e30e19b # main
  234. # Run this step only if there are acceptance related code changes
  235. # Forks are handled in visual-diff.yml
  236. if: needs.files-changed.outputs.acceptance == 'true' && github.event.pull_request.head.repo.full_name == 'getsentry/sentry'
  237. with:
  238. api-token: ${{ secrets.VISUAL_SNAPSHOT_SECRET }}
  239. gcs-bucket: 'sentry-visual-snapshots'
  240. gcp-service-account-key: ${{ secrets.SNAPSHOT_GOOGLE_SERVICE_ACCOUNT_KEY }}
  241. # Since Visual Snapshot is a required check we need to pretend to have run
  242. fake-visual-snapshot:
  243. name: Visual Snapshot
  244. needs: [files-changed]
  245. # Opposite condition to "triggers visual snapshot" required check
  246. if: needs.files-changed.outputs.acceptance != 'true'
  247. runs-on: ubuntu-20.04
  248. steps:
  249. - name: Sentaur attack
  250. run: |
  251. echo "This check pretends to be the Visual Snapshot to satisfy Github required checks"