frontend.yml 5.8 KB

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