frontend.yml 9.5 KB

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