frontend.yml 6.6 KB

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