acceptance.yml 13 KB

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