-
Notifications
You must be signed in to change notification settings - Fork 1
89 lines (80 loc) · 2.74 KB
/
js-lint.yml
File metadata and controls
89 lines (80 loc) · 2.74 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: JavaScript/TypeScript Code Quality
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
contents: read
jobs:
js-lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get changed JS/TS files
id: changed-files
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46
with:
files: |
frontend/**/*.js
frontend/**/*.ts
frontend/**/*.jsx
frontend/**/*.tsx
frontend/**/*.css
frontend/**/*.json
frontend/**/*.mjs
- name: Set up Node.js
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
if: steps.changed-files.outputs.any_changed == 'true'
run: npm ci
- name: Run ESLint on changed files
if: steps.changed-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "Linting changed JS/TS files:"
# Filter to only .ts/.tsx/.js/.jsx files for ESLint
ESLINT_FILES=""
for file in ${ALL_CHANGED_FILES}; do
# Strip frontend/ prefix since working-directory is frontend
relative_file="${file#frontend/}"
if [ -f "$relative_file" ] && echo "$relative_file" | grep -qE '\.(ts|tsx|js|jsx)$'; then
ESLINT_FILES="$ESLINT_FILES $relative_file"
echo " $relative_file"
fi
done
if [ -n "$ESLINT_FILES" ]; then
npx eslint $ESLINT_FILES
else
echo "No JS/TS files to lint"
fi
- name: Run Prettier check on changed files
if: steps.changed-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "Checking format of changed files:"
PRETTIER_FILES=""
for file in ${ALL_CHANGED_FILES}; do
relative_file="${file#frontend/}"
if [ -f "$relative_file" ]; then
PRETTIER_FILES="$PRETTIER_FILES $relative_file"
echo " $relative_file"
fi
done
if [ -n "$PRETTIER_FILES" ]; then
npx prettier --check $PRETTIER_FILES
else
echo "No files to check"
fi
- name: Skip message
if: steps.changed-files.outputs.any_changed == 'false'
run: echo "No JavaScript/TypeScript files changed - skipping JS/TS linting"