js-build-and-lint.yml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. name: js build and lint
  2. on:
  3. # Only runs webpack on master to save bundle size info into artifacts
  4. # which are then used on PRs to compare against
  5. push:
  6. branches:
  7. - master
  8. pull_request:
  9. jobs:
  10. typescript-and-lint:
  11. name: typescript and lint
  12. runs-on: ubuntu-20.04
  13. steps:
  14. - uses: actions/checkout@v2
  15. - name: Internal github app token
  16. id: token
  17. uses: getsentry/action-github-app-token@v1
  18. continue-on-error: true
  19. with:
  20. app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
  21. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  22. - name: Check for frontend file changes
  23. uses: getsentry/paths-filter@master
  24. id: changes
  25. with:
  26. list-files: shell
  27. token: ${{ github.token }}
  28. filters: .github/file-filters.yml
  29. - uses: volta-cli/action@v1
  30. if: steps.changes.outputs.frontend == 'true'
  31. # See https://github.com/actions/cache/blob/master/examples.md#node---yarn for example
  32. - name: Get yarn cache directory path
  33. id: yarn-cache-dir-path
  34. if: steps.changes.outputs.frontend == 'true'
  35. run: echo "::set-output name=dir::$(yarn cache dir)"
  36. - uses: actions/cache@v2
  37. id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
  38. if: steps.changes.outputs.frontend == 'true'
  39. with:
  40. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  41. key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  42. restore-keys: |
  43. ${{ runner.os }}-yarn-
  44. - name: Install dependencies
  45. if: steps.changes.outputs.frontend == 'true'
  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. if: steps.changes.outputs.frontend == 'true'
  50. run: |
  51. echo "::remove-matcher owner=masters::"
  52. echo "::add-matcher::.github/tsc.json"
  53. echo "::add-matcher::.github/eslint-stylish.json"
  54. - name: eslint logic
  55. id: eslint
  56. if: steps.changes.outputs.frontend == 'true' && (github.ref == 'refs/heads/master' || steps.changes.outputs.eslint_config == 'true' || steps.changes.outputs.yarn_lockfile == 'true')
  57. run: echo "::set-output name=all-files::true"
  58. # Lint entire frontend if:
  59. # - this is on main branch
  60. # - eslint configuration in repo has changed
  61. # - yarn lockfile has changed (i.e. we bump our eslint config)
  62. - name: eslint
  63. if: steps.eslint.outputs.all-files == 'true'
  64. run: |
  65. # Run relax config on main branch (and stricter config for changed files)
  66. yarn lint -c .eslintrc.relax.js
  67. yarn lint:css
  68. # Otherwise... only lint modified files
  69. # Note `eslint --fix` will not fail when it auto fixes files
  70. - name: eslint (changed files only)
  71. if: steps.changes.outputs.frontend == 'true' && steps.eslint.outputs.all-files != 'true'
  72. run: |
  73. yarn eslint --fix ${{ steps.changes.outputs.frontend_modified_lintable_files }}
  74. - name: stylelint (changed files only)
  75. if: github.ref != 'refs/heads/master' && steps.changes.outputs.frontend_components_modified_lintable == 'true'
  76. run: |
  77. yarn stylelint ${{ steps.changes.outputs.frontend_components_modified_lintable_files }}
  78. # Check (and error) for dirty working tree for forks
  79. # Reason being we need a different token to auto commit changes and
  80. # forks do not have access to said token
  81. - name: Check for dirty git working tree (forks)
  82. if: steps.token.outcome != 'success' && github.ref != 'refs/heads/master' && steps.changes.outputs.frontend == 'true'
  83. run: |
  84. git diff --quiet || (echo '::error ::lint produced file changes, run linter locally and try again' && exit 1)
  85. # If working tree is dirty, commit and update if we have a token
  86. - name: Commit any eslint fixed files
  87. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && steps.changes.outputs.frontend == 'true'
  88. uses: getsentry/action-github-commit@main
  89. with:
  90. github-token: ${{ steps.token.outputs.token }}
  91. - name: tsc
  92. if: always() && steps.changes.outputs.frontend == 'true'
  93. run: |
  94. yarn tsc -p config/tsconfig.build.json
  95. - name: storybook
  96. if: github.ref != 'refs/heads/master' && steps.changes.outputs.frontend == 'true'
  97. env:
  98. STORYBOOK_BUILD: 1
  99. run: |
  100. yarn storybook-build
  101. webpack:
  102. runs-on: ubuntu-20.04
  103. steps:
  104. - uses: actions/checkout@v2
  105. - name: Check for frontend file changes
  106. uses: getsentry/paths-filter@v2
  107. id: changes
  108. with:
  109. token: ${{ github.token }}
  110. filters: .github/file-filters.yml
  111. - uses: volta-cli/action@v1
  112. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  113. # See https://github.com/actions/cache/blob/master/examples.md#node---yarn for example
  114. - name: Get yarn cache directory path
  115. id: yarn-cache-dir-path
  116. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  117. run: echo "::set-output name=dir::$(yarn cache dir)"
  118. - uses: actions/cache@v2
  119. id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
  120. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  121. with:
  122. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  123. key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  124. restore-keys: |
  125. ${{ runner.os }}-yarn-
  126. - name: Install dependencies
  127. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  128. run: yarn install --frozen-lockfile
  129. - uses: getsentry/size-limit-action@v3
  130. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  131. env:
  132. SENTRY_INSTRUMENTATION: 1
  133. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  134. with:
  135. main_branch: master
  136. workflow_name: 'js-build-and-lint'
  137. skip_step: install
  138. build_script: build
  139. windows_verbatim_arguments: false
  140. github_token: ${{ secrets.GITHUB_TOKEN }}