1+ name : Auto Format Code
2+
3+ on :
4+ push :
5+ branches : [ main, develop, feature/*, bugfix/* ]
6+ pull_request :
7+ branches : [ main, develop ]
8+
9+ jobs :
10+ format :
11+ name : Format Code
12+ runs-on : ubuntu-latest
13+ if : github.event_name == 'push'
14+
15+ steps :
16+ - name : Checkout code
17+ uses : actions/checkout@v4
18+ with :
19+ token : ${{ secrets.GITHUB_TOKEN }}
20+
21+ - name : Setup Node.js
22+ uses : actions/setup-node@v4
23+ with :
24+ node-version : ' 18'
25+ cache : ' npm'
26+ cache-dependency-path : |
27+ frontend/package-lock.json
28+ backend/package-lock.json
29+
30+ # Format frontend
31+ - name : Install frontend dependencies
32+ working-directory : ./frontend
33+ run : npm ci
34+
35+ - name : Format frontend code
36+ working-directory : ./frontend
37+ run : npm run format
38+
39+ # Format backend
40+ - name : Install backend dependencies
41+ working-directory : ./backend
42+ run : npm ci
43+
44+ - name : Format backend code
45+ working-directory : ./backend
46+ run : npm run format
47+
48+ # Commit formatted code
49+ - name : Commit formatted code
50+ run : |
51+ git config --local user.email "action@github.com"
52+ git config --local user.name "GitHub Action"
53+ git add .
54+ git diff --staged --quiet || git commit -m "🎨 Auto-format code with Prettier"
55+ git push
56+
57+ check-format :
58+ name : Check Formatting
59+ runs-on : ubuntu-latest
60+ if : github.event_name == 'pull_request'
61+
62+ steps :
63+ - name : Checkout code
64+ uses : actions/checkout@v4
65+
66+ - name : Setup Node.js
67+ uses : actions/setup-node@v4
68+ with :
69+ node-version : ' 18'
70+ cache : ' npm'
71+ cache-dependency-path : |
72+ frontend/package-lock.json
73+ backend/package-lock.json
74+
75+ # Check frontend formatting
76+ - name : Install frontend dependencies
77+ working-directory : ./frontend
78+ run : npm ci
79+
80+ - name : Check frontend formatting
81+ working-directory : ./frontend
82+ run : npm run format:check
83+
84+ # Check backend formatting
85+ - name : Install backend dependencies
86+ working-directory : ./backend
87+ run : npm ci
88+
89+ - name : Check backend formatting
90+ working-directory : ./backend
91+ run : npm run format:check
0 commit comments