js-build-and-lint.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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@v1 # We are explicitly using v1 due to perf reasons
  37. if: steps.changes.outputs.frontend == 'true'
  38. with:
  39. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  40. key: ${{ runner.os }}-v2-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  41. - name: Install dependencies
  42. if: steps.changes.outputs.frontend == 'true'
  43. run: yarn install --frozen-lockfile
  44. # Setup custom tsc matcher, see https://github.com/actions/setup-node/issues/97
  45. - name: setup matchers
  46. if: steps.changes.outputs.frontend == 'true'
  47. run: |
  48. echo "::remove-matcher owner=masters::"
  49. echo "::add-matcher::.github/tsc.json"
  50. echo "::add-matcher::.github/eslint-stylish.json"
  51. - name: eslint logic
  52. id: eslint
  53. if: steps.changes.outputs.frontend == 'true' && (github.ref == 'refs/heads/master' || steps.changes.outputs.eslint_config == 'true' || steps.changes.outputs.yarn_lockfile == 'true')
  54. run: echo "::set-output name=all-files::true"
  55. # Lint entire frontend if:
  56. # - this is on main branch
  57. # - eslint configuration in repo has changed
  58. # - yarn lockfile has changed (i.e. we bump our eslint config)
  59. - name: eslint
  60. if: steps.eslint.outputs.all-files == 'true'
  61. run: |
  62. # Run relax config on main branch (and stricter config for changed files)
  63. yarn lint -c .eslintrc.relax.js
  64. yarn lint:css
  65. # Otherwise... only lint modified files
  66. # Note `eslint --fix` will not fail when it auto fixes files
  67. - name: eslint (changed files only)
  68. if: steps.changes.outputs.frontend == 'true' && steps.eslint.outputs.all-files != 'true'
  69. run: |
  70. yarn eslint --fix ${{ steps.changes.outputs.frontend_modified_lintable_files }}
  71. - name: stylelint (changed files only)
  72. if: github.ref != 'refs/heads/master' && steps.changes.outputs.frontend_components_modified_lintable == 'true'
  73. run: |
  74. yarn stylelint ${{ steps.changes.outputs.frontend_components_modified_lintable_files }}
  75. # Check (and error) for dirty working tree for forks
  76. # Reason being we need a different token to auto commit changes and
  77. # forks do not have access to said token
  78. - name: Check for dirty git working tree (forks)
  79. if: steps.token.outcome != 'success' && github.ref != 'refs/heads/master' && steps.changes.outputs.frontend == 'true'
  80. run: |
  81. git diff --quiet || (echo '::error ::lint produced file changes, run linter locally and try again' && exit 1)
  82. # If working tree is dirty, commit and update if we have a token
  83. - name: Commit any eslint fixed files
  84. if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && steps.changes.outputs.frontend == 'true'
  85. uses: getsentry/action-github-commit@main
  86. with:
  87. github-token: ${{ steps.token.outputs.token }}
  88. - name: tsc
  89. if: always() && steps.changes.outputs.frontend == 'true'
  90. run: |
  91. yarn tsc -p config/tsconfig.build.json
  92. - name: storybook
  93. if: github.ref != 'refs/heads/master' && steps.changes.outputs.frontend == 'true'
  94. env:
  95. STORYBOOK_BUILD: 1
  96. run: |
  97. yarn storybook-build
  98. webpack:
  99. runs-on: ubuntu-20.04
  100. steps:
  101. - uses: actions/checkout@v2
  102. - name: Check for frontend file changes
  103. uses: getsentry/paths-filter@v2
  104. id: changes
  105. with:
  106. token: ${{ github.token }}
  107. filters: .github/file-filters.yml
  108. - uses: volta-cli/action@v1
  109. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  110. # See https://github.com/actions/cache/blob/master/examples.md#node---yarn for example
  111. - name: Get yarn cache directory path
  112. id: yarn-cache-dir-path
  113. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  114. run: echo "::set-output name=dir::$(yarn cache dir)"
  115. - uses: actions/cache@v1 # We are explicitly using v1 due to perf reasons
  116. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  117. with:
  118. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  119. key: ${{ runner.os }}-v2-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}
  120. - name: Install dependencies
  121. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  122. run: yarn install --frozen-lockfile
  123. - uses: getsentry/size-limit-action@v3
  124. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  125. env:
  126. SENTRY_INSTRUMENTATION: 1
  127. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  128. with:
  129. main_branch: master
  130. workflow_name: 'js-build-and-lint'
  131. skip_step: install
  132. build_script: build
  133. windows_verbatim_arguments: false
  134. github_token: ${{ secrets.GITHUB_TOKEN }}