acceptance.yml 11 KB

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