frontend.yml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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: yarn tsc -p config/tsconfig.ci.json
  104. - name: storybook
  105. if: github.ref != 'refs/heads/master'
  106. env:
  107. STORYBOOK_BUILD: 1
  108. run: |
  109. yarn storybook-build
  110. webpack:
  111. if: github.ref == 'refs/heads/master' || needs.files-changed.outputs.frontend == 'true'
  112. needs: files-changed
  113. runs-on: ubuntu-20.04
  114. steps:
  115. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  116. - uses: getsentry/action-setup-volta@54775a59c41065f54ecc76d1dd5f2cdc7a1550cb # v1.1.0
  117. - name: Install dependencies
  118. run: yarn install --frozen-lockfile
  119. - uses: getsentry/size-limit-action@7be9865310d295ad211da9a8464332288d60d837 # v5
  120. env:
  121. SENTRY_INSTRUMENTATION: 1
  122. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  123. with:
  124. main_branch: master
  125. skip_step: install
  126. build_script: build
  127. windows_verbatim_arguments: false
  128. github_token: ${{ secrets.GITHUB_TOKEN }}
  129. # This check runs once all dependant jobs have passed
  130. # It symbolizes that all required Frontend checks have succesfully passed (Or skipped)
  131. # This check is the only required Github check
  132. frontend-required-check:
  133. needs: [typescript-and-lint, webpack]
  134. name: Frontend
  135. # This is necessary since a failed/skipped dependent job would cause this job to be skipped
  136. if: always()
  137. runs-on: ubuntu-20.04
  138. steps:
  139. # If any jobs we depend on fail, we will fail since this is a required check
  140. # NOTE: A timeout is considered a failure
  141. - name: Check for failures
  142. if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
  143. run: |
  144. echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1