visual-snapshots.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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: ['9.6']
  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@a2352a3e946d56fa41da256057c2df52e7b0ba13
  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: ['9.6']
  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@a2352a3e946d56fa41da256057c2df52e7b0ba13
  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@a2352a3e946d56fa41da256057c2df52e7b0ba13
  171. with:
  172. api-token: ${{ secrets.VISUAL_SNAPSHOT_SECRET }}
  173. gcs-bucket: 'sentry-visual-snapshots'
  174. gcp-service-account-key: ${{ secrets.SNAPSHOT_GOOGLE_SERVICE_ACCOUNT_KEY }}
  175. base-artifact-name: 'acceptance-visual-snapshots-base'
  176. base-branch: ''
  177. artifact-name: 'acceptance-visual-snapshots-pr'
  178. take-master-frontend-snapshots:
  179. name: Take Default Branch Frontend Snapshots
  180. runs-on: ubuntu-20.04
  181. if: |
  182. contains( github.event.pull_request.labels.*.name, 'Trigger: Visual Snapshot')
  183. timeout-minutes: 30
  184. strategy:
  185. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  186. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  187. fail-fast: false
  188. matrix:
  189. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  190. instance: [0, 1, 2, 3]
  191. env:
  192. VISUAL_HTML_ENABLE: 1
  193. steps:
  194. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  195. name: Checkout sentry
  196. with:
  197. ref: 'master'
  198. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  199. - name: node_modules cache
  200. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  201. id: nodemodulescache
  202. with:
  203. path: node_modules
  204. key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  205. - name: Install Javascript Dependencies
  206. if: steps.nodemodulescache.outputs.cache-hit != 'true'
  207. run: yarn install --frozen-lockfile
  208. - name: Build CSS
  209. run: NODE_ENV=production yarn build-css
  210. - name: jest
  211. env:
  212. GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  213. GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }}
  214. CI_NODE_TOTAL: 4
  215. CI_NODE_INDEX: ${{ matrix.instance }}
  216. run: |
  217. SENTRY_PROFILER_LOGGING_MODE=eager JEST_TESTS=$(yarn -s jest --listTests --json) yarn test-ci --forceExit
  218. - name: Create Images from HTML
  219. uses: getsentry/action-html-to-image@dc153dae538e6e1138f77156d8e62e3b2b897f41 # main
  220. with:
  221. base-path: .artifacts/visual-snapshots/jest
  222. css-path: src/sentry/static/sentry/dist/entrypoints/sentry.css
  223. - name: Save snapshots
  224. uses: getsentry/action-visual-snapshot@a2352a3e946d56fa41da256057c2df52e7b0ba13
  225. with:
  226. save-only: true
  227. artifact-name: 'frontend-visual-snapshots-base'
  228. snapshot-path: .artifacts/visual-snapshots
  229. take-pr-frontend-snapshots:
  230. name: Take PR Frontend Snapshots
  231. runs-on: ubuntu-20.04
  232. if: |
  233. contains( github.event.pull_request.labels.*.name, 'Trigger: Visual Snapshot')
  234. timeout-minutes: 30
  235. strategy:
  236. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  237. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  238. fail-fast: false
  239. matrix:
  240. instance: [0, 1, 2, 3]
  241. env:
  242. VISUAL_HTML_ENABLE: 1
  243. steps:
  244. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  245. name: Checkout sentry
  246. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  247. - name: node_modules cache
  248. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  249. id: nodemodulescache
  250. with:
  251. path: node_modules
  252. key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  253. - name: Install Javascript Dependencies
  254. if: steps.nodemodulescache.outputs.cache-hit != 'true'
  255. run: yarn install --frozen-lockfile
  256. - name: Build CSS
  257. run: NODE_ENV=production yarn build-css
  258. - name: jest
  259. env:
  260. GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  261. GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }}
  262. CI_NODE_TOTAL: 4
  263. CI_NODE_INDEX: ${{ matrix.instance }}
  264. run: |
  265. SENTRY_PROFILER_LOGGING_MODE=eager JEST_TESTS=$(yarn -s jest --listTests --json) yarn test-ci --forceExit
  266. - name: Create Images from HTML
  267. uses: getsentry/action-html-to-image@dc153dae538e6e1138f77156d8e62e3b2b897f41 # main
  268. with:
  269. base-path: .artifacts/visual-snapshots/jest
  270. css-path: src/sentry/static/sentry/dist/entrypoints/sentry.css
  271. - name: Save snapshots
  272. uses: getsentry/action-visual-snapshot@a2352a3e946d56fa41da256057c2df52e7b0ba13
  273. with:
  274. save-only: true
  275. artifact-name: 'frontend-visual-snapshots-pr'
  276. snapshot-path: .artifacts/visual-snapshots
  277. diff-frontend-snapshots:
  278. name: Diff Frontend snapshots
  279. needs: [take-master-frontend-snapshots, take-pr-frontend-snapshots]
  280. runs-on: ubuntu-20.04
  281. if: |
  282. contains( github.event.pull_request.labels.*.name, 'Trigger: Visual Snapshot')
  283. timeout-minutes: 25
  284. steps:
  285. - name: Diff snapshots
  286. uses: getsentry/action-visual-snapshot@a2352a3e946d56fa41da256057c2df52e7b0ba13
  287. with:
  288. api-token: ${{ secrets.VISUAL_SNAPSHOT_SECRET }}
  289. gcs-bucket: 'sentry-visual-snapshots'
  290. gcp-service-account-key: ${{ secrets.SNAPSHOT_GOOGLE_SERVICE_ACCOUNT_KEY }}
  291. base-artifact-name: 'frontend-visual-snapshots-base'
  292. base-branch: ''
  293. artifact-name: 'frontend-visual-snapshots-pr'