frontend.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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-24.04
  20. timeout-minutes: 3
  21. # Map a step output to a job output
  22. outputs:
  23. testable_modified: ${{ steps.changes.outputs.testable_modified }}
  24. testable_modified_files: ${{ steps.changes.outputs.testable_modified_files }}
  25. testable_rules_changed: ${{ steps.changes.outputs.testable_rules_changed }}
  26. frontend_all: ${{ steps.changes.outputs.frontend_all }}
  27. steps:
  28. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  29. - name: Check for frontend file changes
  30. uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
  31. id: changes
  32. with:
  33. token: ${{ github.token }}
  34. filters: .github/file-filters.yml
  35. list-files: shell
  36. typescript:
  37. if: needs.files-changed.outputs.frontend_all == 'true'
  38. needs: files-changed
  39. name: typescript
  40. runs-on: ubuntu-24.04
  41. steps:
  42. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  43. - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4
  44. id: setup-node
  45. with:
  46. node-version-file: '.volta.json'
  47. - name: node_modules cache
  48. uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
  49. id: nodemodulescache
  50. with:
  51. path: node_modules
  52. key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock', '.volta.json') }}
  53. - name: Install Javascript Dependencies
  54. if: steps.nodemodulescache.outputs.cache-hit != 'true'
  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: tsc
  63. id: tsc
  64. if: steps.dependencies.outcome == 'success'
  65. run: yarn tsc -p config/tsconfig.ci.json
  66. frontend-jest-tests:
  67. if: needs.files-changed.outputs.testable_rules_changed == 'true' || needs.files-changed.outputs.testable_modified == 'true'
  68. needs: [files-changed, typescript]
  69. name: Jest
  70. # If you change the runs-on image, you must also change the runner in jest-balance.yml
  71. # so that the balancer runs in the same environment as the tests.
  72. runs-on: ubuntu-24.04
  73. timeout-minutes: 30
  74. strategy:
  75. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  76. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  77. fail-fast: false
  78. matrix:
  79. # XXX: When updating this, make sure you also update CI_NODE_TOTAL.
  80. instance: [0, 1, 2, 3]
  81. steps:
  82. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  83. name: Checkout sentry
  84. - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4
  85. id: setup-node
  86. with:
  87. node-version-file: '.volta.json'
  88. - name: node_modules cache
  89. uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
  90. id: nodemodulescache
  91. with:
  92. path: node_modules
  93. key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock', '.volta.json') }}
  94. - name: Install Javascript Dependencies
  95. if: steps.nodemodulescache.outputs.cache-hit != 'true'
  96. run: yarn install --frozen-lockfile
  97. - name: jest
  98. env:
  99. GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  100. GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }}
  101. # XXX: CI_NODE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
  102. # Otherwise, if there are other things in the matrix, using strategy.job-total
  103. # wouldn't be correct. Also, if this increases, make sure to also increase
  104. # `flags.frontend.after_n_builds` in `codecov.yml`.
  105. CI_NODE_TOTAL: 4
  106. CI_NODE_INDEX: ${{ matrix.instance }}
  107. # Disable testing-library from printing out any of of the DOM to
  108. # stdout. No one actually looks through this in CI, they're just
  109. # going to run it locally.
  110. #
  111. # This quiets up the logs quite a bit.
  112. DEBUG_PRINT_LIMIT: 0
  113. run: |
  114. JEST_TESTS=$(yarn -s jest --listTests --json) yarn test-ci --forceExit
  115. # We only upload coverage data for FE changes since it conflicts with
  116. # codecov's carry forward functionality.
  117. # Upload coverage data even if running the tests step fails since
  118. # it reduces large coverage fluctuations.
  119. - name: Handle artifacts
  120. uses: ./.github/actions/artifacts
  121. if: always()
  122. with:
  123. files: .artifacts/coverage/*
  124. type: frontend
  125. token: ${{ secrets.CODECOV_TOKEN }}
  126. commit_sha: ${{ github.event.pull_request.head.sha }}
  127. # This check runs once all dependant jobs have passed
  128. # It symbolizes that all required Frontend checks have succesfully passed (Or skipped)
  129. # This check is the only required Github check
  130. frontend-required-check:
  131. needs: [files-changed, frontend-jest-tests, typescript]
  132. name: Frontend
  133. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  134. if: always()
  135. runs-on: ubuntu-24.04
  136. steps:
  137. # If any jobs we depend on fail, we will fail since this is a required check
  138. # NOTE: A timeout is considered a failure
  139. - name: Check for failures
  140. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  141. run: |
  142. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1