-
Notifications
You must be signed in to change notification settings - Fork 0
304 lines (259 loc) · 8.88 KB
/
Copy pathci.yml
File metadata and controls
304 lines (259 loc) · 8.88 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
name: CI Pipeline (Build → Test BE/FE in Parallel)
on:
push:
pull_request:
workflow_dispatch:
jobs:
# ============================================
# STAGE 1: DETECT CHANGES
# ============================================
detect-changes:
name: Detect Changed Files
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v6
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backend:
- 'src/**'
- 'pom.xml'
- 'docker-compose.yml'
- '.github/workflows/**'
frontend:
- 'coupon-system-frontend/**'
- '!coupon-system-frontend/node_modules/**'
- '.github/workflows/**'
# ============================================
# STAGE 2: BUILD
# ============================================
build-backend:
name: Build Backend
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.backend == 'true'
env:
DB_URL: jdbc:postgresql://localhost:5432/couponsystem
DB_USER: testuser
DB_PASSWORD: test_db_password_ci_123
POSTGRES_PASSWORD: test_postgres_password_ci_123
ADMIN_EMAIL: admin@admin.com
ADMIN_PASSWORD: $2b$14$8sxQJWhyKIFiSbgX75YBqexuY8oz17Q.nDSqgA3YDTTEddj/icEAO
JWT_SECRET: test_jwt_secret_key_for_ci_environments_only_do_not_use_in_production
steps:
- uses: actions/checkout@v6
- name: Set up JDK 25
uses: actions/setup-java@v5
with:
java-version: '25'
distribution: 'temurin'
cache: 'maven'
- name: Start PostgreSQL
run: |
docker compose up -d postgres
echo "Waiting for PostgreSQL to be healthy..."
for i in {1..40}; do
if docker compose ps postgres | grep -q "healthy"; then
echo "PostgreSQL is ready!"
exit 0
fi
echo "Waiting... ($i/40)"
sleep 3
done
echo "Timeout waiting for PostgreSQL"
docker compose logs postgres
exit 1
- name: Build with Maven (skip tests)
run: mvn -B package -DskipTests --file pom.xml
- name: Upload backend artifact
uses: actions/upload-artifact@v6
with:
name: backend-build
path: target/*.jar
retention-days: 1
- name: Cleanup
if: always()
run: docker compose down -v
build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.frontend == 'true'
defaults:
run:
working-directory: coupon-system-frontend
steps:
- uses: actions/checkout@v6
- name: Set up Node.js 20
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: coupon-system-frontend/package-lock.json
- name: Install dependencies
run: npm ci
- name: Build frontend
run: npm run build
- name: Upload frontend build artifact
uses: actions/upload-artifact@v6
with:
name: frontend-build
path: coupon-system-frontend/dist
retention-days: 1
# ============================================
# STAGE 3: TEST (Parallel Execution)
# ============================================
test-backend:
name: Test Backend (678 tests)
runs-on: ubuntu-latest
needs: [detect-changes, build-backend]
if: needs.detect-changes.outputs.backend == 'true'
env:
DB_URL: jdbc:postgresql://localhost:5432/couponsystem
DB_USER: testuser
DB_PASSWORD: test_db_password_ci_123
POSTGRES_PASSWORD: test_postgres_password_ci_123
ADMIN_EMAIL: admin@admin.com
ADMIN_PASSWORD: $2b$14$8sxQJWhyKIFiSbgX75YBqexuY8oz17Q.nDSqgA3YDTTEddj/icEAO
JWT_SECRET: test_jwt_secret_key_for_ci_environments_only_do_not_use_in_production
steps:
- uses: actions/checkout@v6
- name: Set up JDK 25
uses: actions/setup-java@v5
with:
java-version: '25'
distribution: 'temurin'
cache: 'maven'
- name: Start PostgreSQL
run: |
docker compose up -d postgres
echo "Waiting for PostgreSQL to be healthy..."
for i in {1..40}; do
if docker compose ps postgres | grep -q "healthy"; then
echo "PostgreSQL is ready!"
exit 0
fi
echo "Waiting... ($i/40)"
sleep 3
done
echo "Timeout waiting for PostgreSQL"
docker compose logs postgres
exit 1
- name: Run backend tests with coverage
run: mvn test jacoco:report
- name: Upload backend coverage report
uses: actions/upload-artifact@v6
with:
name: backend-coverage-report
path: target/site/jacoco/
- name: Cleanup
if: always()
run: docker compose down -v
test-frontend:
name: Test Frontend (399 tests)
runs-on: ubuntu-latest
needs: [detect-changes, build-frontend]
if: needs.detect-changes.outputs.frontend == 'true'
defaults:
run:
working-directory: coupon-system-frontend
steps:
- uses: actions/checkout@v6
- name: Set up Node.js 20
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: coupon-system-frontend/package-lock.json
- name: Install dependencies
run: npm ci
- name: Run frontend tests
run: npm test -- --run --reporter=verbose
- name: Generate frontend coverage report
if: always()
continue-on-error: true
run: npm run test:coverage || true
- name: Upload frontend coverage report
if: always()
uses: actions/upload-artifact@v6
with:
name: frontend-coverage-report
path: coupon-system-frontend/coverage/
continue-on-error: true
# ============================================
# STAGE 4: SECURITY SCAN (Main branch only)
# ============================================
security-scan:
name: OWASP Security Scan
runs-on: ubuntu-latest
needs: [test-backend]
if: github.ref == 'refs/heads/main' && needs.detect-changes.outputs.backend == 'true'
steps:
- uses: actions/checkout@v6
- name: Set up JDK 25
uses: actions/setup-java@v5
with:
java-version: '25'
distribution: 'temurin'
cache: 'maven'
- name: Free up disk space
run: |
sudo rm -rf /tmp/*
sudo apt-get clean
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
df -h
- name: Cache OWASP Dependency-Check data
uses: actions/cache@v5
with:
path: dependency-check-data
key: ${{ runner.os }}-owasp-data-v2-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-owasp-data-v2-
${{ runner.os }}-owasp-data-
- name: OWASP Dependency Check
continue-on-error: true
run: |
mvn dependency-check:check \
-Dowasp.skip=false \
-Ddata.directory=${{ github.workspace }}/dependency-check-data
env:
NVD_API_KEY: ${{ secrets.NVD_API_KEY }}
- name: Upload OWASP report
uses: actions/upload-artifact@v6
if: always()
with:
name: owasp-report
path: target/dependency-check-report.html
# ============================================
# STAGE 5: SUMMARY
# ============================================
ci-summary:
name: CI Summary
runs-on: ubuntu-latest
needs: [detect-changes, test-backend, test-frontend]
if: always()
steps:
- name: Check all test results
run: |
echo "## CI Pipeline Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Changes Detected:" >> $GITHUB_STEP_SUMMARY
echo "- Backend: ${{ needs.detect-changes.outputs.backend }}" >> $GITHUB_STEP_SUMMARY
echo "- Frontend: ${{ needs.detect-changes.outputs.frontend }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Test Results:" >> $GITHUB_STEP_SUMMARY
echo "- Backend Tests: ${{ needs.test-backend.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Frontend Tests: ${{ needs.test-frontend.result }}" >> $GITHUB_STEP_SUMMARY
# Fail if any test job failed
if [[ "${{ needs.test-backend.result }}" == "failure" ]] || \
[[ "${{ needs.test-frontend.result }}" == "failure" ]]; then
echo "❌ One or more test suites failed!"
exit 1
fi
echo "✅ All tests passed!"