acceptance.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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: 30
  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@d08945864bd75129863897062b8c1687f1600a2d
  93. with:
  94. save-only: true
  95. snapshot-path: .artifacts/visual-snapshots
  96. # This job runs when FE or BE changes happen, however, we only upload coverage data for
  97. # FE changes since it conflicts with codecov's carry forward functionality
  98. - name: Handle artifacts
  99. uses: ./.github/actions/artifacts
  100. if: needs.files-changed.outputs.frontend_all == 'true'
  101. with:
  102. files: .artifacts/coverage/*
  103. type: frontend
  104. acceptance:
  105. if: needs.files-changed.outputs.acceptance == 'true'
  106. needs: files-changed
  107. name: acceptance
  108. runs-on: ubuntu-20.04
  109. timeout-minutes: 25
  110. strategy:
  111. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  112. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  113. fail-fast: false
  114. matrix:
  115. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  116. instance: [0, 1, 2, 3]
  117. pg-version: ['9.6']
  118. env:
  119. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  120. MATRIX_INSTANCE_TOTAL: 4
  121. VISUAL_SNAPSHOT_ENABLE: 1
  122. TEST_GROUP_STRATEGY: roundrobin
  123. steps:
  124. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  125. name: Checkout sentry
  126. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  127. - name: Step configurations
  128. id: config
  129. run: echo "webpack-path=.webpack_cache" >> "$GITHUB_OUTPUT"
  130. - name: webpack cache
  131. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  132. with:
  133. path: ${{ steps.config.outputs.webpack-path }}
  134. key: ${{ runner.os }}-v2-webpack-cache-${{ hashFiles('webpack.config.ts') }}
  135. - name: Install Javascript Dependencies
  136. run: |
  137. yarn install --frozen-lockfile
  138. - name: webpack
  139. env:
  140. WEBPACK_CACHE_PATH: ${{ steps.config.outputs.webpack-path }}
  141. SENTRY_INSTRUMENTATION: 1
  142. # this is fine to not have for forks, it shouldn't fail
  143. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  144. run: |
  145. yarn build-acceptance
  146. - name: Setup sentry env
  147. uses: ./.github/actions/setup-sentry
  148. id: setup
  149. with:
  150. snuba: true
  151. pg-version: ${{ matrix.pg-version }}
  152. - name: Run acceptance tests (#${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  153. run: |
  154. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}
  155. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}-mobile
  156. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}-tooltips
  157. make run-acceptance
  158. env:
  159. PYTEST_SNAPSHOTS_DIR: ${{ steps.setup.outputs.acceptance-dir }}
  160. - name: Save snapshots
  161. uses: getsentry/action-visual-snapshot@d08945864bd75129863897062b8c1687f1600a2d
  162. with:
  163. save-only: true
  164. snapshot-path: .artifacts/visual-snapshots
  165. # This job runs when FE or BE changes happen, however, we only upload coverage data for
  166. # BE changes since it conflicts with codecov's carry forward functionality
  167. - name: Handle artifacts
  168. uses: ./.github/actions/artifacts
  169. if: needs.files-changed.outputs.backend_all == 'true'
  170. chartcuterie:
  171. if: needs.files-changed.outputs.acceptance == 'true'
  172. needs: files-changed
  173. name: chartcuterie integration
  174. runs-on: ubuntu-20.04
  175. timeout-minutes: 30
  176. strategy:
  177. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  178. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  179. fail-fast: false
  180. matrix:
  181. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  182. instance: [0]
  183. env:
  184. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  185. MATRIX_INSTANCE_TOTAL: 1
  186. TEST_GROUP_STRATEGY: roundrobin
  187. VISUAL_SNAPSHOT_ENABLE: 1
  188. steps:
  189. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  190. with:
  191. # Avoid codecov error message related to SHA resolution:
  192. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  193. fetch-depth: '2'
  194. - name: Setup sentry env
  195. uses: ./.github/actions/setup-sentry
  196. id: setup
  197. with:
  198. chartcuterie: true
  199. - name: yarn cache
  200. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  201. with:
  202. path: ${{ steps.setup.outputs.yarn-cache-dir }}
  203. key: ${{ runner.os }}-v2-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  204. - name: Install Javascript Dependencies
  205. run: |
  206. yarn install --frozen-lockfile
  207. - name: Build chartcuterie configuration module
  208. run: |
  209. make build-chartcuterie-config
  210. - name: Run chartcuterie tests (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  211. run: |
  212. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}
  213. make test-chartcuterie
  214. env:
  215. PYTEST_SNAPSHOTS_DIR: ${{ steps.setup.outputs.acceptance-dir }}
  216. - name: Save snapshots
  217. uses: getsentry/action-visual-snapshot@d08945864bd75129863897062b8c1687f1600a2d
  218. with:
  219. save-only: true
  220. snapshot-path: .artifacts/visual-snapshots
  221. # This job runs when FE or BE changes happen, however, we only upload coverage data for
  222. # BE changes since it conflicts with codecov's carry forward functionality
  223. - name: Handle artifacts
  224. uses: ./.github/actions/artifacts
  225. if: needs.files-changed.outputs.backend_all == 'true'
  226. visual-diff:
  227. if: always()
  228. # This guarantees that we will only schedule Visual Snapshots if all
  229. # workflows that generate artifacts succeed
  230. needs: [acceptance, frontend, chartcuterie, files-changed]
  231. name: triggers visual snapshot
  232. runs-on: ubuntu-20.04
  233. timeout-minutes: 20
  234. steps:
  235. # If any jobs we depend on fail, we will fail since this checks triggers Visual Snapshots which is a required check
  236. # NOTE: A timeout is considered a failure
  237. - name: Check for failures
  238. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  239. run: |
  240. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1
  241. - name: Diff snapshots
  242. uses: getsentry/action-visual-snapshot@d08945864bd75129863897062b8c1687f1600a2d
  243. # Run this step only if there are acceptance related code changes
  244. # Forks are handled in visual-diff.yml
  245. if: needs.files-changed.outputs.acceptance == 'true' && github.event.pull_request.head.repo.full_name == 'getsentry/sentry'
  246. with:
  247. api-token: ${{ secrets.VISUAL_SNAPSHOT_SECRET }}
  248. gcs-bucket: 'sentry-visual-snapshots'
  249. gcp-service-account-key: ${{ secrets.SNAPSHOT_GOOGLE_SERVICE_ACCOUNT_KEY }}
  250. # Since Visual Snapshot is a required check we need to pretend to have run
  251. fake-visual-snapshot:
  252. name: Visual Snapshot
  253. needs: [files-changed]
  254. # Opposite condition to "triggers visual snapshot" required check
  255. if: needs.files-changed.outputs.acceptance != 'true'
  256. runs-on: ubuntu-20.04
  257. steps:
  258. - name: Sentaur attack
  259. run: |
  260. echo "This check pretends to be the Visual Snapshot to satisfy Github required checks"