-
Notifications
You must be signed in to change notification settings - Fork 785
52 lines (44 loc) · 1.39 KB
/
linter.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: ESLint
on:
pull_request:
branches: [master]
jobs:
build:
name: Lint updated JavaScript files with ESLint
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Get changed files
id: getfile
run: |
CHANGED_FILES="$(git diff --name-only ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | xargs)"
export CHANGED_FILES # the export command will fail if the inner shell expansion failed
echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
- name: Install ESLint
run: npm install eslint
- name: Lint changed files using ESLint
run: |
for i in ${{ steps.getfile.outputs.files }}
do
if [[ "$i" == "D" ]]
then
ignore=1
elif [[ ( "$i" == "M" ) || ( "$i" == "A" ) || ( "$i" == "R" ) || ( "$i" == "C" ) || ( "$i" == "U" ) ]]
then
ignore=0
fi
echo "file $i $ignore"
if [[ "$i" == *".js" && $ignore == 0 ]]
then
echo "linting $i"
npx eslint $i
fi
done