frontend.yml 8.5 KB

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