js-build-and-lint.yml 6.3 KB

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