frontend.yml 6.2 KB

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