frontend.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. name: frontend
  2. on:
  3. push:
  4. branches:
  5. - master
  6. pull_request:
  7. # Cancel in progress workflows on pull_requests.
  8. # https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
  9. concurrency:
  10. group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  11. cancel-in-progress: true
  12. # hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
  13. env:
  14. SEGMENT_DOWNLOAD_TIMEOUT_MINS: 3
  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. eslint_config: ${{ steps.changes.outputs.eslint_config }}
  23. frontend: ${{ steps.changes.outputs.frontend_all }}
  24. frontend_components_modified_lintable: ${{ steps.changes.outputs.frontend_components_modified_lintable }}
  25. frontend_components_modified_lintable_files: ${{ steps.changes.outputs.frontend_components_modified_lintable_files }}
  26. frontend_modified_lintable_files: ${{ steps.changes.outputs.frontend_modified_lintable_files }}
  27. yarn_lockfile: ${{ steps.changes.outputs.yarn_lockfile }}
  28. steps:
  29. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  30. - name: Check for frontend file changes
  31. uses: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
  32. id: changes
  33. with:
  34. token: ${{ github.token }}
  35. filters: .github/file-filters.yml
  36. list-files: shell
  37. typescript-and-lint:
  38. if: needs.files-changed.outputs.frontend == 'true'
  39. needs: files-changed
  40. name: typescript and lint
  41. runs-on: ubuntu-20.04
  42. steps:
  43. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  44. - name: Internal github app token
  45. id: token
  46. uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
  47. continue-on-error: true
  48. with:
  49. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  50. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  51. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  52. - name: Install dependencies
  53. id: dependencies
  54. run: yarn install --frozen-lockfile
  55. # Setup custom tsc matcher, see https://github.com/actions/setup-node/issues/97
  56. - name: setup matchers
  57. run: |
  58. echo "::remove-matcher owner=masters::"
  59. echo "::add-matcher::.github/tsc.json"
  60. echo "::add-matcher::.github/eslint-stylish.json"
  61. - name: eslint logic
  62. id: eslint
  63. if: (github.ref == 'refs/heads/master' || needs.files-changed.outputs.eslint_config == 'true' || needs.files-changed.outputs.yarn_lockfile == 'true')
  64. run: echo "all-files=true" >> "$GITHUB_OUTPUT"
  65. # Lint entire frontend if:
  66. # - this is on main branch
  67. # - eslint configuration in repo has changed
  68. # - yarn lockfile has changed (i.e. we bump our eslint config)
  69. - name: eslint
  70. if: steps.eslint.outputs.all-files == 'true'
  71. env:
  72. # Run relax config on main branch (and stricter config for changed files)
  73. SENTRY_ESLINT_RELAXED: 1
  74. run: |
  75. yarn lint
  76. yarn lint:css
  77. # Otherwise... only lint modified files
  78. # Note `eslint --fix` will not fail when it auto fixes files
  79. - name: eslint (changed files only)
  80. if: steps.eslint.outputs.all-files != 'true'
  81. run: |
  82. yarn eslint --fix ${{ needs.files-changed.outputs.frontend_modified_lintable_files }}
  83. - name: stylelint (changed files only)
  84. if: github.ref != 'refs/heads/master' && needs.files-changed.outputs.frontend_components_modified_lintable == 'true'
  85. run: |
  86. yarn stylelint ${{ needs.files-changed.outputs.frontend_components_modified_lintable_files }}
  87. # Check (and error) for dirty working tree for forks
  88. # Reason being we need a different token to auto commit changes and
  89. # forks do not have access to said token
  90. - name: Check for dirty git working tree (forks)
  91. if: steps.token.outcome != 'success' && github.ref != 'refs/heads/master'
  92. run: |
  93. git diff --quiet || (echo '::error ::lint produced file changes, run linter locally and try again' && exit 1)
  94. # If working tree is dirty, commit and update if we have a token
  95. - name: Commit any eslint fixed files
  96. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master'
  97. uses: getsentry/action-github-commit@1761f891f036c3efc813b2ba963b121120c1587a # main
  98. with:
  99. github-token: ${{ steps.token.outputs.token }}
  100. - name: tsc
  101. id: tsc
  102. if: steps.dependencies.outcome == 'success'
  103. run: yarn tsc -p config/tsconfig.ci.json
  104. - name: storybook
  105. if: github.ref != 'refs/heads/master'
  106. env:
  107. STORYBOOK_BUILD: 1
  108. run: |
  109. yarn storybook-build
  110. webpack:
  111. if: github.ref == 'refs/heads/master' || needs.files-changed.outputs.frontend == 'true'
  112. needs: files-changed
  113. runs-on: ubuntu-20.04
  114. steps:
  115. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  116. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  117. - name: Install dependencies
  118. run: yarn install --frozen-lockfile
  119. - uses: getsentry/size-limit-action@7be9865310d295ad211da9a8464332288d60d837 # v5
  120. env:
  121. SENTRY_INSTRUMENTATION: 1
  122. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  123. with:
  124. main_branch: master
  125. skip_step: install
  126. build_script: build
  127. windows_verbatim_arguments: false
  128. github_token: ${{ secrets.GITHUB_TOKEN }}
  129. frontend-browser-tests:
  130. if: needs.files-changed.outputs.frontend == 'true'
  131. needs: files-changed
  132. name: Browser tests
  133. # If you change the runs-on image, you must also change the runner in jest-balance.yml
  134. # so that the balancer runs in the same environment as the tests.
  135. runs-on: ubuntu-20.04
  136. timeout-minutes: 30
  137. strategy:
  138. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  139. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  140. fail-fast: false
  141. matrix:
  142. # XXX: When updating this, make sure you also update CI_NODE_TOTAL.
  143. instance: [0, 1, 2, 3]
  144. env:
  145. VISUAL_HTML_ENABLE: 1
  146. steps:
  147. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  148. name: Checkout sentry
  149. with:
  150. # Avoid codecov error message related to SHA resolution:
  151. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  152. fetch-depth: '2'
  153. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  154. - name: node_modules cache
  155. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  156. id: nodemodulescache
  157. with:
  158. path: node_modules
  159. key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  160. - name: Install Javascript Dependencies
  161. if: steps.nodemodulescache.outputs.cache-hit != 'true'
  162. run: yarn install --frozen-lockfile
  163. - name: Build CSS
  164. run: NODE_ENV=production yarn build-css
  165. - name: jest
  166. env:
  167. GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  168. GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }}
  169. # XXX: CI_NODE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  170. # Otherwise, if there are other things in the matrix, using strategy.job-total
  171. # wouldn't be correct.
  172. CI_NODE_TOTAL: 4
  173. CI_NODE_INDEX: ${{ matrix.instance }}
  174. run: |
  175. SENTRY_PROFILER_LOGGING_MODE=eager JEST_TESTS=$(yarn -s jest --listTests --json) yarn test-ci --forceExit
  176. - name: Save HTML artifacts
  177. uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # v3.1.1
  178. with:
  179. retention-days: 14
  180. name: jest-html
  181. path: .artifacts/visual-snapshots/jest
  182. - name: Create Images from HTML
  183. uses: getsentry/action-html-to-image@dc153dae538e6e1138f77156d8e62e3b2b897f41 # main
  184. with:
  185. base-path: .artifacts/visual-snapshots/jest
  186. css-path: src/sentry/static/sentry/dist/entrypoints/sentry.css
  187. - name: Save snapshots
  188. uses: getsentry/action-visual-snapshot@ea663f1be8b73c86b18081d714423ce52352e934
  189. with:
  190. artifact-name: frontend-snapshots
  191. save-only: true
  192. snapshot-path: .artifacts/visual-snapshots
  193. # We only upload coverage data for FE changes since it conflicts with
  194. # codecov's carry forward functionality.
  195. # Upload coverage data even if running the tests step fails since
  196. # it reduces large coverage fluctuations.
  197. - name: Handle artifacts
  198. uses: ./.github/actions/artifacts
  199. if: ${{ always() && needs.files-changed.outputs.frontend_all == 'true' }}
  200. with:
  201. files: .artifacts/coverage/*
  202. type: frontend
  203. frontend-visual-diff:
  204. needs: [frontend-browser-tests]
  205. name: Visual diff
  206. runs-on: ubuntu-20.04
  207. timeout-minutes: 20
  208. if: github.event.pull_request.head.repo.full_name == 'getsentry/sentry'
  209. steps:
  210. - name: Diff snapshots
  211. uses: getsentry/action-visual-snapshot@ea663f1be8b73c86b18081d714423ce52352e934
  212. with:
  213. action-name: 'Visual Snapshot: Frontend'
  214. artifact-name: 'frontend-snapshots'
  215. base-branch: 'master'
  216. api-token: ${{ secrets.VISUAL_SNAPSHOT_SECRET }}
  217. gcs-bucket: 'sentry-visual-snapshots'
  218. gcp-service-account-key: ${{ secrets.SNAPSHOT_GOOGLE_SERVICE_ACCOUNT_KEY }}
  219. # This check runs once all dependant jobs have passed
  220. # It symbolizes that all required Frontend checks have succesfully passed (Or skipped)
  221. # This check is the only required Github check
  222. frontend-required-check:
  223. needs: [typescript-and-lint, webpack, frontend-browser-tests]
  224. name: Frontend
  225. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  226. if: always()
  227. runs-on: ubuntu-20.04
  228. steps:
  229. # If any jobs we depend on fail, we will fail since this is a required check
  230. # NOTE: A timeout is considered a failure
  231. - name: Check for failures
  232. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  233. run: |
  234. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1