frontend.yml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. jobs:
  16. files-changed:
  17. name: detect what files changed
  18. runs-on: ubuntu-20.04
  19. timeout-minutes: 3
  20. # Map a step output to a job output
  21. outputs:
  22. eslint_config: ${{ steps.changes.outputs.eslint_config }}
  23. frontend: ${{ steps.changes.outputs.frontend_all }}
  24. frontend_components_modified_lintable: ${{ steps.changes.outputs.frontend_components_modified_lintable }}
  25. frontend_components_modified_lintable_files: ${{ steps.changes.outputs.frontend_components_modified_lintable_files }}
  26. frontend_modified_lintable_files: ${{ steps.changes.outputs.frontend_modified_lintable_files }}
  27. yarn_lockfile: ${{ steps.changes.outputs.yarn_lockfile }}
  28. steps:
  29. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  30. - name: Check for frontend file changes
  31. uses: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
  32. id: changes
  33. with:
  34. token: ${{ github.token }}
  35. filters: .github/file-filters.yml
  36. list-files: shell
  37. typescript-and-lint:
  38. if: needs.files-changed.outputs.frontend == 'true'
  39. needs: files-changed
  40. name: typescript and lint
  41. runs-on: ubuntu-20.04
  42. steps:
  43. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  44. - name: Internal github app token
  45. id: token
  46. uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
  47. continue-on-error: true
  48. with:
  49. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  50. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  51. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  52. - name: Install dependencies
  53. id: dependencies
  54. run: yarn install --frozen-lockfile
  55. # Setup custom tsc matcher, see https://github.com/actions/setup-node/issues/97
  56. - name: setup matchers
  57. run: |
  58. echo "::remove-matcher owner=masters::"
  59. echo "::add-matcher::.github/tsc.json"
  60. echo "::add-matcher::.github/eslint-stylish.json"
  61. - name: eslint logic
  62. id: eslint
  63. if: (github.ref == 'refs/heads/master' || needs.files-changed.outputs.eslint_config == 'true' || needs.files-changed.outputs.yarn_lockfile == 'true')
  64. run: echo "all-files=true" >> "$GITHUB_OUTPUT"
  65. # Lint entire frontend if:
  66. # - this is on main branch
  67. # - eslint configuration in repo has changed
  68. # - yarn lockfile has changed (i.e. we bump our eslint config)
  69. - name: eslint
  70. if: steps.eslint.outputs.all-files == 'true'
  71. env:
  72. # Run relax config on main branch (and stricter config for changed files)
  73. SENTRY_ESLINT_RELAXED: 1
  74. run: |
  75. yarn lint
  76. yarn lint:css
  77. # Otherwise... only lint modified files
  78. # Note `eslint --fix` will not fail when it auto fixes files
  79. - name: eslint (changed files only)
  80. if: steps.eslint.outputs.all-files != 'true'
  81. run: |
  82. yarn eslint --fix ${{ needs.files-changed.outputs.frontend_modified_lintable_files }}
  83. - name: stylelint (changed files only)
  84. if: github.ref != 'refs/heads/master' && needs.files-changed.outputs.frontend_components_modified_lintable == 'true'
  85. run: |
  86. yarn stylelint ${{ needs.files-changed.outputs.frontend_components_modified_lintable_files }}
  87. # Check (and error) for dirty working tree for forks
  88. # Reason being we need a different token to auto commit changes and
  89. # forks do not have access to said token
  90. - name: Check for dirty git working tree (forks)
  91. if: steps.token.outcome != 'success' && github.ref != 'refs/heads/master'
  92. run: |
  93. git diff --quiet || (echo '::error ::lint produced file changes, run linter locally and try again' && exit 1)
  94. # If working tree is dirty, commit and update if we have a token
  95. - name: Commit any eslint fixed files
  96. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master'
  97. uses: getsentry/action-github-commit@1761f891f036c3efc813b2ba963b121120c1587a # main
  98. with:
  99. github-token: ${{ steps.token.outputs.token }}
  100. - name: tsc
  101. id: tsc
  102. if: steps.dependencies.outcome == 'success'
  103. run: |
  104. set -o pipefail
  105. yarn tsc -p config/tsconfig.ci.json --diagnostics --generateTrace /tmp/trace | tee /tmp/typescript-monitor.log
  106. - name: monitor-tsc
  107. continue-on-error: true
  108. if: steps.tsc.outcome == 'success'
  109. env:
  110. GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  111. GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }}
  112. run: yarn run ts-node .github/workflows/scripts/monitor-typescript.ts
  113. - name: storybook
  114. if: github.ref != 'refs/heads/master'
  115. env:
  116. STORYBOOK_BUILD: 1
  117. run: |
  118. yarn storybook-build
  119. webpack:
  120. if: github.ref == 'refs/heads/master' || needs.files-changed.outputs.frontend == 'true'
  121. needs: files-changed
  122. runs-on: ubuntu-20.04
  123. steps:
  124. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  125. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  126. - name: Install dependencies
  127. run: yarn install --frozen-lockfile
  128. - uses: getsentry/size-limit-action@7be9865310d295ad211da9a8464332288d60d837 # v5
  129. env:
  130. SENTRY_INSTRUMENTATION: 1
  131. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  132. with:
  133. main_branch: master
  134. skip_step: install
  135. build_script: build
  136. windows_verbatim_arguments: false
  137. github_token: ${{ secrets.GITHUB_TOKEN }}
  138. # This check runs once all dependant jobs have passed
  139. # It symbolizes that all required Frontend checks have succesfully passed (Or skipped)
  140. # This check is the only required Github check
  141. frontend-required-check:
  142. needs: [typescript-and-lint, webpack]
  143. name: Frontend
  144. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  145. if: always()
  146. runs-on: ubuntu-20.04
  147. steps:
  148. # If any jobs we depend on fail, we will fail since this is a required check
  149. # NOTE: A timeout is considered a failure
  150. - name: Check for failures
  151. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  152. run: |
  153. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1