-
Notifications
You must be signed in to change notification settings - Fork 95
371 lines (304 loc) · 11.8 KB
/
Copy pathci.yml
File metadata and controls
371 lines (304 loc) · 11.8 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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
name: CI/CD Pipeline
on:
push:
branches: [main, develop, staging]
pull_request:
branches: [main, develop, staging]
workflow_dispatch: # Allow manual triggering
env:
NODE_VERSION: '20'
PNPM_VERSION: '8'
jobs:
# Code Quality Checks
code-quality:
name: Code Quality & Linting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run TypeScript type checking
run: npm run type-check
- name: Run ESLint
run: npm run lint
- name: Check Prettier formatting
run: npm run format:check
- name: Check for console.log statements
run: |
echo "🔍 Checking for console.log statements..."
if grep -r "console\.log" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" src/ components/ hooks/ lib/ app/; then
echo "❌ Found console.log statements. Please remove them before committing."
exit 1
else
echo "✅ No console.log statements found."
fi
- name: Check for TODO/FIXME comments
run: |
echo "🔍 Checking for TODO/FIXME comments..."
if grep -r "TODO\|FIXME" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" src/ components/ hooks/ lib/ app/; then
echo "⚠️ Found TODO/FIXME comments. Please address them before merging."
# Don't fail the build, just warn
else
echo "✅ No TODO/FIXME comments found."
fi
# Build & Test
build:
name: Build & Test
runs-on: ubuntu-latest
needs: code-quality
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Set up environment variables
run: |
echo "🔧 Setting up environment variables for build..."
echo "NEXT_PUBLIC_API_URL=http://localhost:3000/api" >> .env.local
echo "NEXT_PUBLIC_APP_URL=http://localhost:3000" >> .env.local
echo "NEXTAUTH_SECRET=ci-test-secret-key" >> .env.local
echo "NEXTAUTH_URL=http://localhost:3000" >> .env.local
echo "DATABASE_URL=postgresql://test:test@localhost:5432/test_db" >> .env.local
- name: Build application
run: npm run build
continue-on-error: true
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-files
path: .next/
retention-days: 7
# Security Audit
security:
name: Security Audit
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run security audit
run: npm audit --audit-level=moderate
- name: Check for known vulnerabilities
run: |
echo "🔒 Checking for known vulnerabilities..."
npm audit --audit-level=moderate --json > audit-report.json
if jq -e '(.metadata.vulnerabilities.moderate + .metadata.vulnerabilities.high + .metadata.vulnerabilities.critical) > 0' audit-report.json; then
echo "❌ Found security vulnerabilities. Please fix them before merging."
cat audit-report.json | jq '.metadata.vulnerabilities'
exit 1
else
echo "✅ No security vulnerabilities found."
fi
# Commit Message Validation
commit-message:
name: Commit Message Validation
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate commit messages
run: |
echo "📝 Validating commit messages..."
# Conventional commit regex
commit_regex='^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .{1,50}'
# Get all commits in the PR
commits=$(git log --pretty=format:"%H %s" origin/main..HEAD)
invalid_commits=""
while IFS= read -r commit; do
hash=$(echo "$commit" | cut -d' ' -f1)
message=$(echo "$commit" | cut -d' ' -f2-)
# Skip git-generated merge commits
if echo "$message" | grep -qE "^Merge (branch|pull request|remote-tracking branch|[0-9a-f]{7,40}) "; then
continue
fi
if ! echo "$message" | grep -qE "$commit_regex"; then
invalid_commits="$invalid_commits\n$hash: $message"
fi
done <<< "$commits"
if [ -n "$invalid_commits" ]; then
echo "❌ Invalid commit messages found:"
echo -e "$invalid_commits"
echo ""
echo "✅ Please use conventional commit format:"
echo " <type>(<scope>): <description>"
echo ""
echo "📝 Examples:"
echo " feat: add new feature"
echo " fix(wallet): resolve issue"
echo " docs: update documentation"
echo " style: format code"
exit 1
else
echo "✅ All commit messages follow conventional format."
fi
# # Bundle Analysis
# bundle-analysis:
# name: Bundle Analysis
# runs-on: ubuntu-latest
# needs: build
# if: github.event_name == 'pull_request'
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: 'npm'
# - name: Install dependencies
# run: npm ci
# - name: Set up environment variables
# run: |
# echo "🔧 Setting up environment variables for build..."
# echo "NEXT_PUBLIC_API_URL=http://localhost:3000/api" >> .env.local
# echo "NEXT_PUBLIC_APP_URL=http://localhost:3000" >> .env.local
# echo "NEXTAUTH_SECRET=ci-test-secret-key" >> .env.local
# echo "NEXTAUTH_URL=http://localhost:3000" >> .env.local
# echo "DATABASE_URL=postgresql://test:test@localhost:5432/test_db" >> .env.local
# - name: Build with bundle analysis
# run: |
# npm run build
# npx @next/bundle-analyzer .next/static/chunks/**/*.js --out dist/bundle-analysis.html
# - name: Upload bundle analysis
# uses: actions/upload-artifact@v4
# with:
# name: bundle-analysis
# path: dist/bundle-analysis.html
# retention-days: 30
# # Performance Testing
# performance:
# name: Performance Testing
# runs-on: ubuntu-latest
# needs: build
# if: github.event_name == 'pull_request'
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: 'npm'
# - name: Install dependencies
# run: npm ci
# - name: Set up environment variables
# run: |
# echo "🔧 Setting up environment variables for build..."
# echo "NEXT_PUBLIC_API_URL=http://localhost:3000/api" >> .env.local
# echo "NEXT_PUBLIC_APP_URL=http://localhost:3000" >> .env.local
# echo "NEXTAUTH_SECRET=ci-test-secret-key" >> .env.local
# echo "NEXTAUTH_URL=http://localhost:3000" >> .env.local
# echo "DATABASE_URL=postgresql://test:test@localhost:5432/test_db" >> .env.local
# - name: Build application
# run: npm run build
# - name: Check bundle size
# run: |
# echo "📦 Checking bundle size..."
# # Get the main bundle size
# main_bundle_size=$(du -s .next/static/chunks/ | grep main | awk '{print $1}')
# # Set threshold (in KB)
# threshold=500
# if [ "$main_bundle_size" -gt "$threshold" ]; then
# echo "⚠️ Bundle size ($main_bundle_size KB) exceeds threshold ($threshold KB)"
# echo "Consider optimizing your bundle size."
# else
# echo "✅ Bundle size ($main_bundle_size KB) is within acceptable limits."
# fi
# # Deploy to Staging (if on develop branch)
# deploy-staging:
# name: Deploy to Staging
# runs-on: ubuntu-latest
# needs: [code-quality, build, security]
# if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
# environment: staging
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: 'npm'
# - name: Install dependencies
# run: npm ci
# - name: Set up environment variables
# run: |
# echo "🔧 Setting up environment variables for build..."
# echo "NEXT_PUBLIC_API_URL=http://localhost:3000/api" >> .env.local
# echo "NEXT_PUBLIC_APP_URL=http://localhost:3000" >> .env.local
# echo "NEXTAUTH_SECRET=ci-test-secret-key" >> .env.local
# echo "NEXTAUTH_URL=http://localhost:3000" >> .env.local
# echo "DATABASE_URL=postgresql://test:test@localhost:5432/test_db" >> .env.local
# - name: Build application
# run: npm run build
# - name: Deploy to staging
# run: |
# echo "🚀 Deploying to staging environment..."
# # Add your staging deployment commands here
# # Example: npm run deploy:staging
# echo "✅ Successfully deployed to staging!"
# # Deploy to Production (if on main branch)
# deploy-production:
# name: Deploy to Production
# runs-on: ubuntu-latest
# needs: [code-quality, build, security, commit-message]
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# environment: production
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: 'npm'
# - name: Install dependencies
# run: npm ci
# - name: Set up environment variables
# run: |
# echo "🔧 Setting up environment variables for build..."
# echo "NEXT_PUBLIC_API_URL=http://localhost:3000/api" >> .env.local
# echo "NEXT_PUBLIC_APP_URL=http://localhost:3000" >> .env.local
# echo "NEXTAUTH_SECRET=ci-test-secret-key" >> .env.local
# echo "NEXTAUTH_URL=http://localhost:3000" >> .env.local
# echo "DATABASE_URL=postgresql://test:test@localhost:5432/test_db" >> .env.local
# - name: Build application
# run: npm run build
# - name: Deploy to production
# run: |
# echo "🚀 Deploying to production environment..."
# # Add your production deployment commands here
# # Example: npm run deploy:production
# echo "✅ Successfully deployed to production!"
# Notify on Failure
notify-failure:
name: Notify on Failure
runs-on: ubuntu-latest
needs: [code-quality, build, security]
if: failure()
steps:
- name: Notify failure
run: |
echo "❌ CI/CD pipeline failed!"
echo "Please check the logs and fix the issues before merging."
# Add your notification logic here (Slack, email, etc.)