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