visual-snapshots.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. # Visual Snapshots compares against artifacts from the same workflow name (on main branch)
  2. name: visual-snapshots
  3. on:
  4. pull_request:
  5. types: [opened, synchronize, reopened, labeled]
  6. # Cancel in progress workflows on pull_requests.
  7. # https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
  8. concurrency:
  9. group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  10. cancel-in-progress: true
  11. # hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
  12. env:
  13. SEGMENT_DOWNLOAD_TIMEOUT_MINS: 3
  14. jobs:
  15. take-master-acceptance-snapshots:
  16. name: Take Default Branch Acceptance Snapshots
  17. runs-on: ubuntu-20.04
  18. if: |
  19. contains( github.event.pull_request.labels.*.name, 'Trigger: Visual Snapshot')
  20. timeout-minutes: 25
  21. strategy:
  22. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  23. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  24. fail-fast: false
  25. matrix:
  26. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  27. instance: [0, 1, 2]
  28. pg-version: ['14']
  29. env:
  30. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  31. MATRIX_INSTANCE_TOTAL: 3
  32. VISUAL_SNAPSHOT_ENABLE: 1
  33. TEST_GROUP_STRATEGY: roundrobin
  34. steps:
  35. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  36. name: Checkout sentry
  37. with:
  38. ref: 'master'
  39. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  40. - name: Step configurations
  41. id: config
  42. run: echo "webpack-path=.webpack_cache" >> "$GITHUB_OUTPUT"
  43. - name: webpack cache
  44. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  45. with:
  46. path: ${{ steps.config.outputs.webpack-path }}
  47. key: ${{ runner.os }}-v2-webpack-cache-${{ hashFiles('webpack.config.ts') }}
  48. - name: node_modules cache
  49. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  50. id: nodemodulescache
  51. with:
  52. path: node_modules
  53. key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  54. - name: Install Javascript Dependencies
  55. if: steps.nodemodulescache.outputs.cache-hit != 'true'
  56. run: yarn install --frozen-lockfile
  57. - name: webpack
  58. env:
  59. WEBPACK_CACHE_PATH: ${{ steps.config.outputs.webpack-path }}
  60. SENTRY_INSTRUMENTATION: 1
  61. # this is fine to not have for forks, it shouldn't fail
  62. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  63. run: |
  64. yarn build-acceptance
  65. - name: Build chartcuterie configuration module
  66. run: |
  67. make build-chartcuterie-config
  68. - name: Setup sentry env
  69. uses: ./.github/actions/setup-sentry
  70. id: setup
  71. with:
  72. snuba: true
  73. chartcuterie: true
  74. pg-version: ${{ matrix.pg-version }}
  75. - name: Run acceptance tests (#${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }})
  76. run: |
  77. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}
  78. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}-mobile
  79. mkdir -p ${{ steps.setup.outputs.acceptance-dir }}-tooltips
  80. make run-acceptance
  81. env:
  82. PYTEST_SNAPSHOTS_DIR: ${{ steps.setup.outputs.acceptance-dir }}
  83. - name: Save snapshots
  84. uses: getsentry/action-visual-snapshot@f2537eaa143289fc5d246370767fb6cb5eff1e12
  85. with:
  86. save-only: true
  87. artifact-name: 'acceptance-visual-snapshots-base'
  88. snapshot-path: .artifacts/visual-snapshots
  89. take-pr-acceptance-snapshots:
  90. name: Take PR Acceptance Snapshots
  91. runs-on: ubuntu-20.04
  92. if: |
  93. contains( github.event.pull_request.labels.*.name, 'Trigger: Visual Snapshot')
  94. timeout-minutes: 25
  95. strategy:
  96. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  97. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  98. fail-fast: false
  99. matrix:
  100. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  101. instance: [0, 1, 2]
  102. pg-version: ['14']
  103. env:
  104. # XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  105. MATRIX_INSTANCE_TOTAL: 3
  106. VISUAL_SNAPSHOT_ENABLE: 1
  107. TEST_GROUP_STRATEGY: roundrobin
  108. steps:
  109. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  110. name: Checkout sentry
  111. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  112. - name: Step configurations
  113. id: config
  114. run: echo "webpack-path=.webpack_cache" >> "$GITHUB_OUTPUT"
  115. - name: webpack cache
  116. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  117. with:
  118. path: ${{ steps.config.outputs.webpack-path }}
  119. key: ${{ runner.os }}-v2-webpack-cache-${{ hashFiles('webpack.config.ts') }}
  120. - name: node_modules cache
  121. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  122. id: nodemodulescache
  123. with:
  124. path: node_modules
  125. key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  126. - name: Install Javascript Dependencies
  127. if: steps.nodemodulescache.outputs.cache-hit != 'true'
  128. run: yarn install --frozen-lockfile
  129. - name: webpack
  130. env:
  131. WEBPACK_CACHE_PATH: ${{ steps.config.outputs.webpack-path }}
  132. SENTRY_INSTRUMENTATION: 1
  133. # this is fine to not have for forks, it shouldn't fail
  134. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  135. run: |
  136. yarn build-acceptance
  137. - name: Build chartcuterie configuration module
  138. run: |
  139. make build-chartcuterie-config
  140. - name: Setup sentry env
  141. uses: ./.github/actions/setup-sentry
  142. id: setup
  143. with:
  144. snuba: true
  145. chartcuterie: 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@f2537eaa143289fc5d246370767fb6cb5eff1e12
  157. with:
  158. save-only: true
  159. artifact-name: 'acceptance-visual-snapshots-pr'
  160. snapshot-path: .artifacts/visual-snapshots
  161. diff-acceptance-snapshots:
  162. name: Diff Acceptance snapshots
  163. needs: [take-master-acceptance-snapshots, take-pr-acceptance-snapshots]
  164. runs-on: ubuntu-20.04
  165. if: |
  166. contains( github.event.pull_request.labels.*.name, 'Trigger: Visual Snapshot')
  167. timeout-minutes: 25
  168. steps:
  169. - name: Diff snapshots
  170. uses: getsentry/action-visual-snapshot@f2537eaa143289fc5d246370767fb6cb5eff1e12
  171. with:
  172. action-name: 'Visual Snapshot: Acceptance'
  173. api-token: ${{ secrets.VISUAL_SNAPSHOT_SECRET }}
  174. gcs-bucket: 'sentry-visual-snapshots'
  175. gcp-service-account-key: ${{ secrets.SNAPSHOT_GOOGLE_SERVICE_ACCOUNT_KEY }}
  176. base-artifact-name: 'acceptance-visual-snapshots-base'
  177. base-branch: ''
  178. artifact-name: 'acceptance-visual-snapshots-pr'
  179. take-master-frontend-snapshots:
  180. name: Take Default Branch Frontend Snapshots
  181. runs-on: ubuntu-20.04
  182. if: |
  183. contains( github.event.pull_request.labels.*.name, 'Trigger: Visual Snapshot')
  184. timeout-minutes: 30
  185. strategy:
  186. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  187. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  188. fail-fast: false
  189. matrix:
  190. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  191. instance: [0, 1, 2, 3]
  192. env:
  193. VISUAL_HTML_ENABLE: 1
  194. steps:
  195. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  196. name: Checkout sentry
  197. with:
  198. ref: 'master'
  199. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  200. - name: node_modules cache
  201. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  202. id: nodemodulescache
  203. with:
  204. path: node_modules
  205. key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  206. - name: Install Javascript Dependencies
  207. if: steps.nodemodulescache.outputs.cache-hit != 'true'
  208. run: yarn install --frozen-lockfile
  209. - name: Build CSS
  210. run: NODE_ENV=production yarn build-css
  211. - name: jest
  212. env:
  213. GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  214. GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }}
  215. CI_NODE_TOTAL: 4
  216. CI_NODE_INDEX: ${{ matrix.instance }}
  217. run: |
  218. SENTRY_PROFILER_LOGGING_MODE=eager JEST_TESTS=$(yarn -s jest --listTests --json) yarn test-ci --forceExit
  219. - name: Create Images from HTML
  220. uses: getsentry/action-html-to-image@dc153dae538e6e1138f77156d8e62e3b2b897f41 # main
  221. with:
  222. base-path: .artifacts/visual-snapshots/jest
  223. css-path: src/sentry/static/sentry/dist/entrypoints/sentry.css
  224. - name: Save snapshots
  225. uses: getsentry/action-visual-snapshot@f2537eaa143289fc5d246370767fb6cb5eff1e12
  226. with:
  227. save-only: true
  228. artifact-name: 'frontend-visual-snapshots-base'
  229. snapshot-path: .artifacts/visual-snapshots
  230. take-pr-frontend-snapshots:
  231. name: Take PR Frontend Snapshots
  232. runs-on: ubuntu-20.04
  233. if: |
  234. contains( github.event.pull_request.labels.*.name, 'Trigger: Visual Snapshot')
  235. timeout-minutes: 30
  236. strategy:
  237. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  238. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  239. fail-fast: false
  240. matrix:
  241. instance: [0, 1, 2, 3]
  242. env:
  243. VISUAL_HTML_ENABLE: 1
  244. steps:
  245. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  246. name: Checkout sentry
  247. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  248. - name: node_modules cache
  249. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  250. id: nodemodulescache
  251. with:
  252. path: node_modules
  253. key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  254. - name: Install Javascript Dependencies
  255. if: steps.nodemodulescache.outputs.cache-hit != 'true'
  256. run: yarn install --frozen-lockfile
  257. - name: Build CSS
  258. run: NODE_ENV=production yarn build-css
  259. - name: jest
  260. env:
  261. GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  262. GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }}
  263. CI_NODE_TOTAL: 4
  264. CI_NODE_INDEX: ${{ matrix.instance }}
  265. run: |
  266. SENTRY_PROFILER_LOGGING_MODE=eager JEST_TESTS=$(yarn -s jest --listTests --json) yarn test-ci --forceExit
  267. - name: Create Images from HTML
  268. uses: getsentry/action-html-to-image@dc153dae538e6e1138f77156d8e62e3b2b897f41 # main
  269. with:
  270. base-path: .artifacts/visual-snapshots/jest
  271. css-path: src/sentry/static/sentry/dist/entrypoints/sentry.css
  272. - name: Save snapshots
  273. uses: getsentry/action-visual-snapshot@f2537eaa143289fc5d246370767fb6cb5eff1e12
  274. with:
  275. save-only: true
  276. artifact-name: 'frontend-visual-snapshots-pr'
  277. snapshot-path: .artifacts/visual-snapshots
  278. diff-frontend-snapshots:
  279. name: Diff Frontend snapshots
  280. needs: [take-master-frontend-snapshots, take-pr-frontend-snapshots]
  281. runs-on: ubuntu-20.04
  282. if: |
  283. contains( github.event.pull_request.labels.*.name, 'Trigger: Visual Snapshot')
  284. timeout-minutes: 25
  285. steps:
  286. - name: Diff snapshots
  287. uses: getsentry/action-visual-snapshot@f2537eaa143289fc5d246370767fb6cb5eff1e12
  288. with:
  289. action-name: 'Visual Snapshot: Frontend'
  290. api-token: ${{ secrets.VISUAL_SNAPSHOT_SECRET }}
  291. gcs-bucket: 'sentry-visual-snapshots'
  292. gcp-service-account-key: ${{ secrets.SNAPSHOT_GOOGLE_SERVICE_ACCOUNT_KEY }}
  293. base-artifact-name: 'frontend-visual-snapshots-base'
  294. base-branch: ''
  295. artifact-name: 'frontend-visual-snapshots-pr'