frontend.yml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  31. - name: Check for frontend file changes
  32. uses: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
  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@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  45. - name: Internal github app token
  46. id: token
  47. uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.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@c52be2ea13cfdc084edb806e81958c13e445941e # v1.2.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: |
  76. yarn lint
  77. yarn lint:css
  78. # Otherwise... only lint modified files
  79. # Note `eslint --fix` will not fail when it auto fixes files
  80. - name: eslint (changed files only)
  81. if: steps.eslint.outputs.all-files != 'true'
  82. run: |
  83. yarn eslint --fix ${{ needs.files-changed.outputs.frontend_modified_lintable_files }}
  84. - name: stylelint (changed files only)
  85. if: github.ref != 'refs/heads/master' && needs.files-changed.outputs.frontend_components_modified_lintable == 'true'
  86. run: |
  87. yarn stylelint ${{ needs.files-changed.outputs.frontend_components_modified_lintable_files }}
  88. # Check (and error) for dirty working tree for forks
  89. # Reason being we need a different token to auto commit changes and
  90. # forks do not have access to said token
  91. - name: Check for dirty git working tree (forks)
  92. if: steps.token.outcome != 'success' && github.ref != 'refs/heads/master'
  93. run: |
  94. git diff --quiet || (echo '::error ::lint produced file changes, run linter locally and try again' && exit 1)
  95. # If working tree is dirty, commit and update if we have a token
  96. - name: Commit any eslint fixed files
  97. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master'
  98. uses: getsentry/action-github-commit@748c31dd78cffe76f51bef49a0be856b6effeda7 # v1.1.0
  99. with:
  100. github-token: ${{ steps.token.outputs.token }}
  101. message: ':hammer_and_wrench: apply eslint style fixes'
  102. - name: tsc
  103. id: tsc
  104. if: steps.dependencies.outcome == 'success'
  105. run: yarn tsc -p config/tsconfig.ci.json
  106. frontend-jest-tests:
  107. if: needs.files-changed.outputs.frontend == 'true'
  108. needs: files-changed
  109. name: Jest
  110. # If you change the runs-on image, you must also change the runner in jest-balance.yml
  111. # so that the balancer runs in the same environment as the tests.
  112. runs-on: ubuntu-22.04
  113. timeout-minutes: 30
  114. strategy:
  115. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  116. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  117. fail-fast: false
  118. matrix:
  119. # XXX: When updating this, make sure you also update CI_NODE_TOTAL.
  120. instance: [0, 1, 2, 3]
  121. steps:
  122. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  123. name: Checkout sentry
  124. with:
  125. # Avoid codecov error message related to SHA resolution:
  126. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  127. fetch-depth: '2'
  128. - uses: getsentry/action-setup-volta@c52be2ea13cfdc084edb806e81958c13e445941e # v1.2.0
  129. - name: node_modules cache
  130. uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
  131. id: nodemodulescache
  132. with:
  133. path: node_modules
  134. key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  135. - name: Install Javascript Dependencies
  136. if: steps.nodemodulescache.outputs.cache-hit != 'true'
  137. run: yarn install --frozen-lockfile
  138. - name: jest
  139. env:
  140. GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  141. GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }}
  142. # XXX: CI_NODE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  143. # Otherwise, if there are other things in the matrix, using strategy.job-total
  144. # wouldn't be correct. Also, if this increases, make sure to also increase
  145. # `flags.frontend.after_n_builds` in `codecov.yml`.
  146. CI_NODE_TOTAL: 4
  147. CI_NODE_INDEX: ${{ matrix.instance }}
  148. # Disable testing-library from printing out any of of the DOM to
  149. # stdout. No one actually looks through this in CI, they're just
  150. # going to run it locally.
  151. #
  152. # This quiets up the logs quite a bit.
  153. DEBUG_PRINT_LIMIT: 0
  154. run: |
  155. JEST_TESTS=$(yarn -s jest --listTests --json) yarn test-ci --forceExit
  156. # We only upload coverage data for FE changes since it conflicts with
  157. # codecov's carry forward functionality.
  158. # Upload coverage data even if running the tests step fails since
  159. # it reduces large coverage fluctuations.
  160. - name: Handle artifacts
  161. uses: ./.github/actions/artifacts
  162. if: ${{ always() && needs.files-changed.outputs.frontend_all == 'true' }}
  163. with:
  164. files: .artifacts/coverage/*
  165. type: frontend
  166. token: ${{ secrets.CODECOV_TOKEN }}
  167. # This check runs once all dependant jobs have passed
  168. # It symbolizes that all required Frontend checks have succesfully passed (Or skipped)
  169. # This check is the only required Github check
  170. frontend-required-check:
  171. needs: [files-changed, frontend-jest-tests, typescript-and-lint]
  172. name: Frontend
  173. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  174. if: always()
  175. runs-on: ubuntu-22.04
  176. steps:
  177. # If any jobs we depend on fail, we will fail since this is a required check
  178. # NOTE: A timeout is considered a failure
  179. - name: Check for failures
  180. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  181. run: |
  182. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1