frontend.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. NODE_OPTIONS: '--max-old-space-size=4096'
  16. jobs:
  17. files-changed:
  18. name: detect what files changed
  19. runs-on: ubuntu-22.04
  20. timeout-minutes: 3
  21. # Map a step output to a job output
  22. outputs:
  23. eslint_config: ${{ steps.changes.outputs.eslint_config }}
  24. frontend: ${{ steps.changes.outputs.frontend_all }}
  25. frontend_components_modified_lintable: ${{ steps.changes.outputs.frontend_components_modified_lintable }}
  26. frontend_components_modified_lintable_files: ${{ steps.changes.outputs.frontend_components_modified_lintable_files }}
  27. frontend_modified_lintable_files: ${{ steps.changes.outputs.frontend_modified_lintable_files }}
  28. yarn_lockfile: ${{ steps.changes.outputs.yarn_lockfile }}
  29. steps:
  30. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  31. - name: Check for frontend file changes
  32. uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
  33. id: changes
  34. with:
  35. token: ${{ github.token }}
  36. filters: .github/file-filters.yml
  37. list-files: shell
  38. typescript-and-lint:
  39. if: needs.files-changed.outputs.frontend == 'true'
  40. needs: files-changed
  41. name: typescript and lint
  42. runs-on: ubuntu-22.04
  43. steps:
  44. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  45. - name: Internal github app token
  46. id: token
  47. uses: getsentry/action-github-app-token@d4b5da6c5e37703f8c3b3e43abb5705b46e159cc # v3.0.0
  48. continue-on-error: true
  49. with:
  50. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  51. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  52. - uses: getsentry/action-setup-volta@e4939d337b83760d13a9d7030a6f68c9d0ee7581 # v2.0.0
  53. - name: Install dependencies
  54. id: dependencies
  55. run: yarn install --frozen-lockfile
  56. # Setup custom tsc matcher, see https://github.com/actions/setup-node/issues/97
  57. - name: setup matchers
  58. run: |
  59. echo "::remove-matcher owner=masters::"
  60. echo "::add-matcher::.github/tsc.json"
  61. echo "::add-matcher::.github/eslint-stylish.json"
  62. - name: eslint logic
  63. id: eslint
  64. if: (github.ref == 'refs/heads/master' || needs.files-changed.outputs.eslint_config == 'true' || needs.files-changed.outputs.yarn_lockfile == 'true')
  65. run: echo "all-files=true" >> "$GITHUB_OUTPUT"
  66. # Lint entire frontend if:
  67. # - this is on main branch
  68. # - eslint configuration in repo has changed
  69. # - yarn lockfile has changed (i.e. we bump our eslint config)
  70. - name: eslint
  71. if: steps.eslint.outputs.all-files == 'true'
  72. env:
  73. # Run relax config on main branch (and stricter config for changed files)
  74. SENTRY_ESLINT_RELAXED: 1
  75. run: yarn lint
  76. # Otherwise... only lint modified files
  77. # Note `eslint --fix` will not fail when it auto fixes files
  78. - name: eslint (changed files only)
  79. if: steps.eslint.outputs.all-files != 'true'
  80. run: |
  81. yarn eslint --fix ${{ needs.files-changed.outputs.frontend_modified_lintable_files }}
  82. - name: stylelint (changed files only)
  83. if: github.ref != 'refs/heads/master' && needs.files-changed.outputs.frontend_components_modified_lintable == 'true'
  84. run: |
  85. yarn stylelint ${{ needs.files-changed.outputs.frontend_components_modified_lintable_files }}
  86. - name: biome
  87. if: github.ref != 'refs/heads/master' && needs.files-changed.outputs.frontend_components_modified_lintable == 'true'
  88. run: yarn biome check . --apply
  89. # Check (and error) for dirty working tree for forks
  90. # Reason being we need a different token to auto commit changes and
  91. # forks do not have access to said token
  92. - name: Check for dirty git working tree (forks)
  93. if: steps.token.outcome != 'success' && github.ref != 'refs/heads/master'
  94. run: |
  95. git diff --quiet || (echo '::error ::lint produced file changes, run linter locally and try again' && exit 1)
  96. # If working tree is dirty, commit and update if we have a token
  97. - name: Commit any eslint fixed files
  98. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master'
  99. uses: getsentry/action-github-commit@748c31dd78cffe76f51bef49a0be856b6effeda7 # v1.1.0
  100. with:
  101. github-token: ${{ steps.token.outputs.token }}
  102. message: ':hammer_and_wrench: apply eslint style fixes'
  103. - name: tsc
  104. id: tsc
  105. if: steps.dependencies.outcome == 'success'
  106. run: yarn tsc -p config/tsconfig.ci.json
  107. frontend-jest-tests:
  108. if: needs.files-changed.outputs.frontend == 'true'
  109. needs: files-changed
  110. name: Jest
  111. # If you change the runs-on image, you must also change the runner in jest-balance.yml
  112. # so that the balancer runs in the same environment as the tests.
  113. runs-on: ubuntu-22.04
  114. timeout-minutes: 30
  115. strategy:
  116. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  117. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  118. fail-fast: false
  119. matrix:
  120. # XXX: When updating this, make sure you also update CI_NODE_TOTAL.
  121. instance: [0, 1, 2, 3]
  122. steps:
  123. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  124. name: Checkout sentry
  125. with:
  126. # Avoid codecov error message related to SHA resolution:
  127. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  128. fetch-depth: '2'
  129. - uses: getsentry/action-setup-volta@e4939d337b83760d13a9d7030a6f68c9d0ee7581 # v2.0.0
  130. - name: node_modules cache
  131. uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
  132. id: nodemodulescache
  133. with:
  134. path: node_modules
  135. key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  136. - name: Install Javascript Dependencies
  137. if: steps.nodemodulescache.outputs.cache-hit != 'true'
  138. run: yarn install --frozen-lockfile
  139. - name: jest
  140. env:
  141. GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  142. GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }}
  143. # XXX: CI_NODE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  144. # Otherwise, if there are other things in the matrix, using strategy.job-total
  145. # wouldn't be correct. Also, if this increases, make sure to also increase
  146. # `flags.frontend.after_n_builds` in `codecov.yml`.
  147. CI_NODE_TOTAL: 4
  148. CI_NODE_INDEX: ${{ matrix.instance }}
  149. # Disable testing-library from printing out any of of the DOM to
  150. # stdout. No one actually looks through this in CI, they're just
  151. # going to run it locally.
  152. #
  153. # This quiets up the logs quite a bit.
  154. DEBUG_PRINT_LIMIT: 0
  155. run: |
  156. JEST_TESTS=$(yarn -s jest --listTests --json) yarn test-ci --forceExit
  157. # We only upload coverage data for FE changes since it conflicts with
  158. # codecov's carry forward functionality.
  159. # Upload coverage data even if running the tests step fails since
  160. # it reduces large coverage fluctuations.
  161. - name: Handle artifacts
  162. uses: ./.github/actions/artifacts
  163. if: ${{ always() && needs.files-changed.outputs.frontend_all == 'true' }}
  164. with:
  165. files: .artifacts/coverage/*
  166. type: frontend
  167. token: ${{ secrets.CODECOV_TOKEN }}
  168. # This check runs once all dependant jobs have passed
  169. # It symbolizes that all required Frontend checks have succesfully passed (Or skipped)
  170. # This check is the only required Github check
  171. frontend-required-check:
  172. needs: [files-changed, frontend-jest-tests, typescript-and-lint]
  173. name: Frontend
  174. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  175. if: always()
  176. runs-on: ubuntu-22.04
  177. steps:
  178. # If any jobs we depend on fail, we will fail since this is a required check
  179. # NOTE: A timeout is considered a failure
  180. - name: Check for failures
  181. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  182. run: |
  183. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1