-
Notifications
You must be signed in to change notification settings - Fork 1.4k
147 lines (131 loc) · 7.56 KB
/
linting.yaml
File metadata and controls
147 lines (131 loc) · 7.56 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Linting and Formatting
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
jobs:
# ============================================
# Python Linting with pre-commit
# ============================================
python-lint:
name: Python Linting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Cache pre-commit
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
pre-commit-
- name: Install pre-commit
run: |
python -m pip install --upgrade pip
# Install pre-commit and tomli (required for bandit to read pyproject.toml)
pip install pre-commit tomli
- name: Run pre-commit on Python files
run: |
echo "🔍 Running pre-commit hooks on Python files..."
pre-commit run --all-files --verbose 2>&1 || {
echo ""
echo "╔═══════════════════════════════════════════════════════════════════════════╗"
echo "║ ❌ Pre-commit checks failed! ║"
echo "╠═══════════════════════════════════════════════════════════════════════════╣"
echo "║ Please run the following commands locally to fix formatting issues: ║"
echo "║ ║"
echo "║ pip install pre-commit # Install pre-commit (if not installed) ║"
echo "║ pre-commit install # Set up git hooks (recommended) ║"
echo "║ pre-commit run --all-files # Fix all formatting issues ║"
echo "║ ║"
echo "║ Then commit and push the changes. ║"
echo "║ ║"
echo "║ 💡 Tip: After running 'pre-commit install', hooks will run ║"
echo "║ automatically on every commit! ║"
echo "╚═══════════════════════════════════════════════════════════════════════════╝"
echo ""
exit 1
}
# ============================================
# Frontend Linting (TypeScript/JavaScript)
# ============================================
frontend-lint:
name: Frontend Linting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: web/package-lock.json
- name: Install frontend dependencies
working-directory: ./web
run: npm ci
- name: Run ESLint
working-directory: ./web
run: |
echo "🔍 Running ESLint on frontend code..."
# Run ESLint directly (Next.js 16 removed the 'next lint' command)
npm run lint 2>&1 || {
echo ""
echo "╔═══════════════════════════════════════════════════════════════════════════╗"
echo "║ ❌ ESLint checks failed! ║"
echo "╠═══════════════════════════════════════════════════════════════════════════╣"
echo "║ Please run the following commands locally to fix linting issues: ║"
echo "║ ║"
echo "║ cd web ║"
echo "║ npm run lint # Check for linting issues ║"
echo "║ npm run lint -- --fix # Auto-fix linting issues ║"
echo "║ ║"
echo "║ Then commit and push the changes. ║"
echo "╚═══════════════════════════════════════════════════════════════════════════╝"
echo ""
exit 1
}
- name: TypeScript type check
working-directory: ./web
run: |
echo "🔍 Running TypeScript type check..."
npx tsc --noEmit 2>&1 || {
echo ""
echo "╔═══════════════════════════════════════════════════════════════════════════╗"
echo "║ ❌ TypeScript type check failed! ║"
echo "╠═══════════════════════════════════════════════════════════════════════════╣"
echo "║ Please fix the TypeScript errors shown above. ║"
echo "╚═══════════════════════════════════════════════════════════════════════════╝"
echo ""
exit 1
}
# ============================================
# Lint Summary
# ============================================
lint-summary:
name: Lint Summary
runs-on: ubuntu-latest
needs: [python-lint, frontend-lint]
if: always()
steps:
- name: Generate summary
run: |
echo "## 🔍 Linting Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Python (pre-commit) | ${{ needs.python-lint.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Frontend (ESLint + TypeScript) | ${{ needs.frontend-lint.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
- name: Fail if linting failed
if: needs.python-lint.result == 'failure' || needs.frontend-lint.result == 'failure'
run: exit 1