Skip to content

Commit 549bee9

Browse files
committed
ci: add workflow for linting (ESLint & Prettier) & type checking
1 parent 746483b commit 549bee9

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

.github/workflows/lint-and-check.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Lint and Type-checking
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
pull_request:
9+
branches:
10+
- main
11+
- dev
12+
13+
jobs:
14+
lint:
15+
name: ESLint & Prettier
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '18'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Get list of changed files
31+
id: files
32+
run: |
33+
echo "CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT origin/${{ github.base_ref || github.ref_name }} | tr '\n' ' ')" >> $GITHUB_ENV
34+
35+
- name: Lint JS/TS files with ESLint (no auto-fix)
36+
if: ${{ env.CHANGED_FILES != ''}}
37+
run: |
38+
FILES=$(echo "$CHANGED_FILES" | tr ' ' '\n' | grep -E '\.(js|jsx|ts|tsx)$' | xargs)
39+
if [ -n "$FILES" ]; then
40+
echo "Running ESLint on:"
41+
echo "$FILES"
42+
npx next lint --file $FILES
43+
else
44+
echo "No JS/TS files to lint."
45+
fi
46+
47+
- name: Format other files with Prettier
48+
if: ${{ env.CHANGED_FILES != ''}}
49+
run: |
50+
FILES=$(echo "$CHANGED_FILES" | tr ' ' '\n' | grep -E '\.(json|md|css|scss|html)$' | xargs)
51+
if [ -n "$FILES" ]; then
52+
echo "Running Prettier on:"
53+
echo "$FILES"
54+
npx prettier --check $FILES
55+
else
56+
echo "No files to format with Prettier."
57+
fi
58+
59+
- name: Type Check
60+
run: |
61+
echo "Running TypeScript type checking..."
62+
npx tsc --noEmit
63+
64+
type-check:
65+
name: Type Checking
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- name: Checkout code
70+
uses: actions/checkout@v4
71+
72+
- name: Setup Node.js
73+
uses: actions/setup-node@v4
74+
with:
75+
node-version: '18'
76+
77+
- name: Install dependencies
78+
run: npm ci
79+
80+
- name: Type Check
81+
run: |
82+
echo "Running TypeScript type checking..."
83+
npx tsc --noEmit

0 commit comments

Comments
 (0)