Skip to content

Commit 1b5c593

Browse files
authored
Refactoring ESLint workflow for accuracy and stability (#4519)
* Refactoring ESLint workflow for accuracy and stability * changing setup v3 to v4
1 parent 1b2234e commit 1b5c593

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

.github/workflows/linter.yml

+18-29
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,37 @@ on:
55
branches: [master]
66

77
jobs:
8-
build:
8+
lint:
99
name: Lint updated JavaScript files with ESLint
1010

11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
1212

1313
steps:
1414
- name: Checkout code
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 0
1818
ref: ${{ github.event.pull_request.head.sha }}
1919

20-
- name: Use Node.js
21-
uses: actions/setup-node@v1
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v4
2222
with:
23-
node-version: 12.x
23+
node-version: 20.x
2424

25-
- name: Get changed files
26-
id: getfile
25+
- name: Get changed JavaScript files
26+
id: get_files
2727
run: |
28-
CHANGED_FILES="$(git diff --name-only ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | xargs)"
29-
export CHANGED_FILES # the export command will fail if the inner shell expansion failed
30-
echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
28+
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} -- '*.js')
29+
echo "files<<EOF" >> $GITHUB_ENV
30+
echo "$CHANGED_FILES" >> $GITHUB_ENV
31+
echo "EOF" >> $GITHUB_ENV
3132
32-
- name: Install ESLint
33+
- name: Install dependencies
3334
run: npm install eslint
3435

35-
- name: Lint changed files using ESLint
36+
- name: Run ESLint on changed files
37+
if: env.files != ''
3638
run: |
37-
for i in ${{ steps.getfile.outputs.files }}
38-
do
39-
if [[ "$i" == "D" ]]
40-
then
41-
ignore=1
42-
elif [[ ( "$i" == "M" ) || ( "$i" == "A" ) || ( "$i" == "R" ) || ( "$i" == "C" ) || ( "$i" == "U" ) ]]
43-
then
44-
ignore=0
45-
fi
46-
echo "file $i $ignore"
47-
if [[ "$i" == *".js" && $ignore == 0 ]]
48-
then
49-
echo "linting $i"
50-
npx eslint $i
51-
fi
52-
done
39+
echo "Linting the following files:"
40+
echo "$files"
41+
echo "$files" | xargs npx eslint

0 commit comments

Comments
 (0)