frontend.yml 9.6 KB

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