-
Notifications
You must be signed in to change notification settings - Fork 4
283 lines (245 loc) · 9.81 KB
/
Copy pathci-code-quality.yml
File metadata and controls
283 lines (245 loc) · 9.81 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
name: CI - Code Quality
# This workflow runs on every pull request and push to main branches
# It performs formatting checks, linting, building, and testing
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
types: [opened, synchronize, reopened]
# Cancel in-progress runs when a new commit is pushed
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
# Job 1: Code Quality Checks
quality:
name: 🎨 Code Quality
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for better analysis
- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
- name: 📚 Install dependencies
run: |
echo "📦 Installing dependencies..."
npm ci
echo "✅ Dependencies installed"
- name: 🎨 Check formatting
id: format
run: |
echo "🎨 Checking code formatting with Biome..."
npm run format
# Check if there are any changes
if [[ -n $(git status --porcelain) ]]; then
echo "❌ Code formatting issues found!"
echo "formatting_issues=true" >> $GITHUB_OUTPUT
# Show what files would be formatted
echo "📝 Files with formatting issues:"
git status --porcelain
# Create a comment body
echo "## 🎨 Formatting Issues Found" >> format-comment.md
echo "" >> format-comment.md
echo "Please run \`npm run format\` locally to fix formatting issues." >> format-comment.md
echo "" >> format-comment.md
echo "Files that need formatting:" >> format-comment.md
echo "\`\`\`" >> format-comment.md
git status --porcelain | sed 's/^ M //' >> format-comment.md
echo "\`\`\`" >> format-comment.md
exit 1
else
echo "✅ Code formatting is perfect!"
echo "formatting_issues=false" >> $GITHUB_OUTPUT
fi
- name: 🔍 Run linter
id: lint
run: |
echo "🔍 Running linter..."
npm run lint || {
echo "❌ Linting issues found!"
echo "lint_issues=true" >> $GITHUB_OUTPUT
exit 1
}
echo "✅ No linting issues found!"
echo "lint_issues=false" >> $GITHUB_OUTPUT
# Job 2: Build
build:
name: 🔨 Build
runs-on: ubuntu-latest
needs: quality # Only run if quality checks pass
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
- name: 📚 Install dependencies
run: |
echo "📦 Installing dependencies..."
npm ci
echo "✅ Dependencies installed"
- name: 🔨 Build project
run: |
echo "🔨 Building project..."
npm run build
echo "✅ Build successful!"
- name: 📊 Check build output
run: |
echo "📊 Build output summary:"
echo "Total files in dist: $(find dist -type f | wc -l)"
echo "Build size: $(du -sh dist | cut -f1)"
# Ensure executable permissions
chmod +x dist/index.js
echo "✅ Executable permissions set"
- name: 💾 Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: dist/
retention-days: 7
# Job 3: Test
test:
name: 🧪 Test
runs-on: ubuntu-latest
needs: quality # Only run if quality checks pass
strategy:
matrix:
node-version: [18, 20, 22] # Test on multiple Node versions
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: 📚 Install dependencies
run: |
echo "📦 Installing dependencies..."
npm ci
echo "✅ Dependencies installed"
- name: 🧪 Run tests
run: |
echo "🧪 Running tests on Node.js ${{ matrix.node-version }}..."
npm test
echo "✅ All tests passed!"
- name: 📊 Generate coverage report
if: matrix.node-version == 22 # Only on latest Node
run: |
echo "📊 Generating coverage report..."
npm run test:coverage || true
# Display coverage summary
if [ -f coverage/coverage-summary.json ]; then
echo "📈 Coverage Summary:"
node -e "
const coverage = require('./coverage/coverage-summary.json');
const total = coverage.total;
console.log('Lines:', total.lines.pct + '%');
console.log('Statements:', total.statements.pct + '%');
console.log('Functions:', total.functions.pct + '%');
console.log('Branches:', total.branches.pct + '%');
"
fi
- name: 📤 Upload coverage reports
if: matrix.node-version == 22
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/
retention-days: 30
# Job 4: Summary
summary:
name: 📋 PR Summary
runs-on: ubuntu-latest
needs: [quality, build, test]
if: always() # Run even if other jobs fail
steps:
- name: 📋 Create summary
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "# 📋 Pull Request Check Summary" >> $GITHUB_STEP_SUMMARY
else
echo "# 📋 Branch Check Summary (${{ github.ref_name }})" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
# Quality checks
if [[ "${{ needs.quality.result }}" == "success" ]]; then
echo "✅ **Code Quality**: Passed" >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Code Quality**: Failed" >> $GITHUB_STEP_SUMMARY
fi
# Build
if [[ "${{ needs.build.result }}" == "success" ]]; then
echo "✅ **Build**: Successful" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.build.result }}" == "skipped" ]]; then
echo "⏭️ **Build**: Skipped (quality checks failed)" >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Build**: Failed" >> $GITHUB_STEP_SUMMARY
fi
# Tests
if [[ "${{ needs.test.result }}" == "success" ]]; then
echo "✅ **Tests**: All passed" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.test.result }}" == "skipped" ]]; then
echo "⏭️ **Tests**: Skipped (quality checks failed)" >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Tests**: Failed" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📝 Next Steps" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.quality.result }}" != "success" ]]; then
echo "1. Fix code quality issues (run \`npm run format\` and \`npm run lint\`)" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.build.result }}" != "success" ]] && [[ "${{ needs.build.result }}" != "skipped" ]]; then
echo "1. Fix build errors" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.test.result }}" != "success" ]] && [[ "${{ needs.test.result }}" != "skipped" ]]; then
echo "1. Fix failing tests" >> $GITHUB_STEP_SUMMARY
else
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "🎉 All checks passed! Your PR is ready for review." >> $GITHUB_STEP_SUMMARY
else
echo "🎉 All checks passed! The ${{ github.ref_name }} branch is healthy." >> $GITHUB_STEP_SUMMARY
fi
fi
- name: 💬 Comment on PR
if: (failure() || cancelled()) && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const summary = [];
// Add header
summary.push('## 🔍 PR Check Results\n');
// Quality checks
if ('${{ needs.quality.result }}' === 'failure') {
summary.push('### ❌ Code Quality Issues\n');
summary.push('Please fix the following:');
summary.push('- Run `npm run format` to fix formatting issues');
summary.push('- Run `npm run lint` to see linting errors\n');
}
// Build
if ('${{ needs.build.result }}' === 'failure') {
summary.push('### ❌ Build Failed\n');
summary.push('The TypeScript build failed. Please check the build logs.\n');
}
// Tests
if ('${{ needs.test.result }}' === 'failure') {
summary.push('### ❌ Tests Failed\n');
summary.push('Some tests are failing. Please check the test logs.\n');
}
if (summary.length > 1) {
summary.push('---');
summary.push('💡 **Tip**: Click on the job names above to see detailed logs.');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary.join('\n')
});
}