js-build-and-lint.yml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. if: github.ref != 'refs/heads/master'
  13. runs-on: ubuntu-16.04
  14. steps:
  15. - uses: actions/checkout@v2
  16. with:
  17. # because we want to lint + fix + commit, we need to checkout the HEAD sha (otherwise
  18. # it checks out the merge commit and we will not be able to commit to it)
  19. ref: ${{ github.event.pull_request.head.ref || 'master' }}
  20. # We need the repo here so that this works for forks
  21. repository: ${{ github.event.pull_request.head.repo.full_name }}
  22. - name: Check for frontend file changes
  23. uses: getsentry/paths-filter@v2
  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') }}
  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. id: matchers
  50. if: steps.changes.outputs.frontend == 'true'
  51. run: |
  52. echo "::remove-matcher owner=masters::"
  53. echo "::add-matcher::.github/tsc.json"
  54. echo "::add-matcher::.github/eslint-stylish.json"
  55. # Lint entire frontend if this is on main branch
  56. - name: eslint
  57. if: github.ref == 'refs/heads/master' && steps.changes.outputs.frontend == 'true'
  58. run: |
  59. # Run relax config on main branch (and stricter config for changed files)
  60. yarn lint -c .eslintrc.relax.js
  61. yarn lint:css
  62. - name: eslint (forks)
  63. if: github.ref != 'refs/heads/master' && steps.changes.outputs.frontend == 'true' && github.event.pull_request.head.repo.full_name != github.repository
  64. run: |
  65. yarn eslint ${{ steps.changes.outputs.frontend_modified_lintable_files }}
  66. # Otherwise if it's not main branch, only lint modified files
  67. - name: eslint (changed files only)
  68. if: github.ref != 'refs/heads/master' && steps.changes.outputs.frontend == 'true' && github.event.pull_request.head.repo.full_name == github.repository
  69. run: |
  70. yarn eslint --fix ${{ steps.changes.outputs.frontend_modified_lintable_files }}
  71. # Otherwise if it's not main branch, only lint modified files
  72. - name: Commit any eslint fixed files
  73. if: github.ref != 'refs/heads/master' && steps.changes.outputs.frontend == 'true' && github.event.pull_request.head.repo.full_name == github.repository
  74. continue-on-error: true
  75. run: |
  76. git config --global user.name "github-actions[bot]"
  77. git config --global user.email "github-actions@sentry.io"
  78. git add -A
  79. git commit -m "chore: Automatic eslint fix (${GITHUB_SHA})" || exit 0
  80. git push origin
  81. - name: tsc
  82. if: always() && steps.changes.outputs.frontend == 'true'
  83. run: |
  84. yarn tsc -p config/tsconfig.build.json
  85. - name: storybook
  86. if: steps.changes.outputs.frontend == 'true'
  87. env:
  88. STORYBOOK_BUILD: 1
  89. run: |
  90. yarn storybook-build
  91. webpack:
  92. runs-on: ubuntu-16.04
  93. steps:
  94. - uses: actions/checkout@v2
  95. - name: Check for frontend file changes
  96. uses: getsentry/paths-filter@v2
  97. id: changes
  98. with:
  99. token: ${{ github.token }}
  100. filters: .github/file-filters.yml
  101. - uses: volta-cli/action@v1
  102. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  103. # See https://github.com/actions/cache/blob/master/examples.md#node---yarn for example
  104. - name: Get yarn cache directory path
  105. id: yarn-cache-dir-path
  106. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  107. run: echo "::set-output name=dir::$(yarn cache dir)"
  108. - uses: actions/cache@v2
  109. id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
  110. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  111. with:
  112. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  113. key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  114. restore-keys: |
  115. ${{ runner.os }}-yarn-
  116. - name: Install dependencies
  117. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  118. run: yarn install --frozen-lockfile
  119. - uses: getsentry/size-limit-action@v3
  120. if: github.ref == 'refs/heads/master' || steps.changes.outputs.frontend == 'true'
  121. env:
  122. SENTRY_INSTRUMENTATION: 1
  123. SENTRY_WEBPACK_WEBHOOK_SECRET: ${{ secrets.SENTRY_WEBPACK_WEBHOOK_SECRET }}
  124. with:
  125. main_branch: master
  126. workflow_name: 'js-build-and-lint'
  127. skip_step: install
  128. build_script: build
  129. windows_verbatim_arguments: false
  130. github_token: ${{ secrets.GITHUB_TOKEN }}