Browse Source

build(ci): Run eslint on entire codebase when config changes (#25973)

This makes a change to the eslint workflow where we will now run eslint
across the entire frontend codebase (vs. only changed files) when eslint
configuration files change *OR* yarn lockfile changes. (yarn lockfile
changes accounts for bumps to our external eslint configuration package.)
Billy Vong 3 years ago
parent
commit
f0115180a6
2 changed files with 20 additions and 7 deletions
  1. 8 2
      .github/file-filters.yml
  2. 12 5
      .github/workflows/js-build-and-lint.yml

+ 8 - 2
.github/file-filters.yml

@@ -10,11 +10,17 @@ frontend_lintable: &frontend_lintable
   - '**/tsconfig*.json'
   - '{package,now,vercel}.json'
 
+yarn_lockfile: &yarn_lockfile
+  - 'yarn.lock'
+
+eslint_config: &eslint_config
+  - '.eslint*'
+
 frontend: &frontend
+  - *yarn_lockfile
   - *frontend_lintable
+  - *eslint_config
   - '**/*.less'
-  - 'yarn.lock'
-  - '.eslint*'
   - 'docs-ui/**'
   - 'static/**'
   - 'tests/js/**'

+ 12 - 5
.github/workflows/js-build-and-lint.yml

@@ -55,25 +55,32 @@ jobs:
 
       # Setup custom tsc matcher, see https://github.com/actions/setup-node/issues/97
       - name: setup matchers
-        id: matchers
         if: steps.changes.outputs.frontend == 'true'
         run: |
           echo "::remove-matcher owner=masters::"
           echo "::add-matcher::.github/tsc.json"
           echo "::add-matcher::.github/eslint-stylish.json"
 
-      # Lint entire frontend if this is on main branch
+      - name: eslint logic
+        id: eslint
+        if: steps.changes.outputs.frontend == 'true' && (github.ref == 'refs/heads/master' || steps.changes.outputs.eslint_config == 'true' || steps.changes.outputs.yarn_lockfile == 'true')
+        run: echo "::set-output name=all-files::true"
+
+      # Lint entire frontend if:
+      # - this is on main branch
+      # - eslint configuration in repo has changed
+      # - yarn lockfile has changed (i.e. we bump our eslint config)
       - name: eslint
-        if: github.ref == 'refs/heads/master' && steps.changes.outputs.frontend == 'true'
+        if: steps.eslint.outputs.all-files == 'true'
         run: |
           # Run relax config on main branch (and stricter config for changed files)
           yarn lint -c .eslintrc.relax.js
           yarn lint:css
 
-      # Otherwise if it's not main branch, only lint modified files
+      # Otherwise... only lint modified files
       # Note `eslint --fix` will not fail when it auto fixes files
       - name: eslint (changed files only)
-        if: github.ref != 'refs/heads/master' && steps.changes.outputs.frontend == 'true'
+        if: steps.eslint.outputs.all-files != 'true'
         run: |
           yarn eslint --fix ${{ steps.changes.outputs.frontend_modified_lintable_files }}