frontend.yml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. - 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()
  164. with:
  165. files: .artifacts/coverage/*
  166. type: frontend
  167. token: ${{ secrets.CODECOV_TOKEN }}
  168. commit_sha: ${{ github.event.pull_request.head.sha }}
  169. # This check runs once all dependant jobs have passed
  170. # It symbolizes that all required Frontend checks have succesfully passed (Or skipped)
  171. # This check is the only required Github check
  172. frontend-required-check:
  173. needs: [files-changed, frontend-jest-tests, typescript-and-lint]
  174. name: Frontend
  175. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  176. if: always()
  177. runs-on: ubuntu-22.04
  178. steps:
  179. # If any jobs we depend on fail, we will fail since this is a required check
  180. # NOTE: A timeout is considered a failure
  181. - name: Check for failures
  182. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  183. run: |
  184. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1