-
Notifications
You must be signed in to change notification settings - Fork 2
440 lines (396 loc) · 15.9 KB
/
Copy pathunified-ci.yml
File metadata and controls
440 lines (396 loc) · 15.9 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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2025-Present Datadog, Inc.
name: Unified CI/CD
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
inputs:
deploy:
description: 'Deploy to AWS dev environment after build'
required: false
default: false
type: boolean
force-all:
description: 'Force build all services regardless of changes'
required: false
default: false
type: boolean
permissions:
contents: read
packages: write
attestations: write
id-token: write
env:
REGISTRY: ghcr.io
REPOSITORY_URL: github.com/${{ github.repository }}
jobs:
# ============================================================================
# CHANGE DETECTION
# ============================================================================
detect-changes:
runs-on: ubuntu-latest
outputs:
user-management: ${{ steps.changes.outputs.user-management }}
sticker-award: ${{ steps.changes.outputs.sticker-award }}
sticker-catalogue: ${{ steps.changes.outputs.sticker-catalogue }}
web-backend: ${{ steps.changes.outputs.web-backend }}
web-frontend: ${{ steps.changes.outputs.web-frontend }}
shared: ${{ steps.changes.outputs.shared }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Detect changed paths
id: changes
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE_SHA=${{ github.event.pull_request.base.sha }}
HEAD_SHA=${{ github.event.pull_request.head.sha }}
else
# For push events, compare with parent commit
BASE_SHA=${{ github.event.before }}
HEAD_SHA=${{ github.sha }}
fi
# Get list of changed files
CHANGED_FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA 2>/dev/null || echo "")
# Check each service directory
echo "user-management=$(echo "$CHANGED_FILES" | grep -q '^user-management/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "sticker-award=$(echo "$CHANGED_FILES" | grep -q '^sticker-award/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "sticker-catalogue=$(echo "$CHANGED_FILES" | grep -q '^sticker-catalogue/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "web-backend=$(echo "$CHANGED_FILES" | grep -q '^web-backend/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "web-frontend=$(echo "$CHANGED_FILES" | grep -q '^web-frontend/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "shared=$(echo "$CHANGED_FILES" | grep -q '^shared/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "Changed files:"
echo "$CHANGED_FILES"
# ============================================================================
# USER MANAGEMENT SERVICE (.NET)
# ============================================================================
# TEMPORARY: 'true' added to force all builds - remove after testing
user-management-build:
needs: detect-changes
if: |
true ||
github.event.inputs.force-all == 'true' ||
github.event_name == 'push' ||
needs.detect-changes.outputs.user-management == 'true' ||
needs.detect-changes.outputs.shared == 'true'
uses: ./.github/workflows/_build-dotnet.yml
with:
working-directory: user-management
dotnet-version: '10.0.x'
user-management-push-api:
needs: user-management-build
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_push-images.yml
with:
image-name: user-management-service
context: ./user-management
dockerfile: ./user-management/src/Stickerlandia.UserManagement.Api/Dockerfile
user-management-push-worker:
needs: user-management-build
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_push-images.yml
with:
image-name: user-management-worker
context: ./user-management
dockerfile: ./user-management/src/Stickerlandia.UserManagement.Worker/Dockerfile
user-management-push-migration:
needs: user-management-build
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_push-images.yml
with:
image-name: user-management-migration
context: ./user-management
dockerfile: ./user-management/src/Stickerlandia.UserManagement.MigrationService/Dockerfile
user-management-deploy:
needs: [user-management-push-api, user-management-push-worker, user-management-push-migration]
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_deploy-aws.yml
with:
service-name: user-management
infra-directory: user-management/infra/aws
dotnet-version: '10.0.x'
secrets:
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
# ============================================================================
# STICKER AWARD SERVICE (Go)
# ============================================================================
# TEMPORARY: 'true' added to force all builds - remove after testing
sticker-award-build:
needs: detect-changes
if: |
true ||
github.event.inputs.force-all == 'true' ||
github.event_name == 'push' ||
needs.detect-changes.outputs.sticker-award == 'true' ||
needs.detect-changes.outputs.shared == 'true'
uses: ./.github/workflows/_build-go.yml
with:
working-directory: sticker-award
go-version: '1.21'
sticker-award-push:
needs: sticker-award-build
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_push-images.yml
with:
image-name: sticker-award-service
context: ./sticker-award
dockerfile: ./sticker-award/Dockerfile
go-version: '1.21'
sticker-award-deploy:
needs: sticker-award-push
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_deploy-aws.yml
with:
service-name: sticker-award
infra-directory: sticker-award/infra/aws
go-version: '1.21'
secrets:
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
# ============================================================================
# STICKER CATALOGUE SERVICE (Java)
# ============================================================================
# TEMPORARY: 'true' added to force all builds - remove after testing
sticker-catalogue-build:
needs: detect-changes
if: |
true ||
github.event.inputs.force-all == 'true' ||
github.event_name == 'push' ||
needs.detect-changes.outputs.sticker-catalogue == 'true' ||
needs.detect-changes.outputs.shared == 'true'
uses: ./.github/workflows/_build-java.yml
with:
working-directory: sticker-catalogue
java-version: '21'
sticker-catalogue-push:
needs: sticker-catalogue-build
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_push-images.yml
with:
image-name: sticker-catalogue-service
context: ./sticker-catalogue
dockerfile: ./sticker-catalogue/src/main/docker/Dockerfile.jvm
java-version: '21'
pre-build-command: 'cd sticker-catalogue && ./mvnw package -DskipTests'
sticker-catalogue-deploy:
needs: sticker-catalogue-push
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_deploy-aws.yml
with:
service-name: sticker-catalogue
infra-directory: sticker-catalogue/infra/aws
java-version: '21'
secrets:
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
# ============================================================================
# WEB BACKEND SERVICE (Node.js)
# ============================================================================
# TEMPORARY: 'true' added to force all builds - remove after testing
web-backend-build:
needs: detect-changes
if: |
true ||
github.event.inputs.force-all == 'true' ||
github.event_name == 'push' ||
needs.detect-changes.outputs.web-backend == 'true' ||
needs.detect-changes.outputs.shared == 'true'
uses: ./.github/workflows/_build-node.yml
with:
working-directory: web-backend
node-version: '18'
web-backend-push:
needs: web-backend-build
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_push-images.yml
with:
image-name: web-backend-service
context: ./web-backend
dockerfile: ./web-backend/Dockerfile
web-backend-deploy:
needs: web-backend-push
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_deploy-aws.yml
with:
service-name: web-backend
infra-directory: web-backend/infra/aws
node-version: '18'
secrets:
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
# ============================================================================
# WEB FRONTEND SERVICE (React/Node.js)
# ============================================================================
web-frontend-push:
needs: detect-changes
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_push-images.yml
with:
image-name: web-frontend
context: ./web-frontend
dockerfile: ./web-frontend/Dockerfile
web-frontend-deploy:
needs: web-frontend-push
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.deploy == true)
uses: ./.github/workflows/_deploy-aws.yml
with:
service-name: web-frontend
infra-directory: web-frontend/infra/aws
node-version: '18'
pre-deploy-command: 'cd web-frontend && npm install && npm run build'
secrets:
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
# ============================================================================
# FAN-IN: UI/E2E TESTS (runs after all deployments complete)
# ============================================================================
ui-tests:
needs:
- user-management-deploy
- sticker-award-deploy
- sticker-catalogue-deploy
- web-backend-deploy
- web-frontend-deploy
# Run if:
# - We're on main branch push AND
# - All preceding jobs either succeeded or were skipped (not failed/cancelled)
if: |
always() &&
github.event_name == 'push' &&
github.ref == 'refs/heads/main' &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
uses: ./.github/workflows/_ui-tests.yml
with:
environment: dev
secrets:
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
# ============================================================================
# DOCKER COMPOSE E2E TESTS (runs after builds, uses GHA cache)
# ============================================================================
docker-compose-tests:
needs:
- user-management-build
- sticker-award-build
- sticker-catalogue-build
- web-backend-build
# Run if all build jobs succeeded or were skipped (not failed/cancelled)
if: |
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
- name: Create CI .env
run: |
cat > .env << EOF
ENV=ci
COMMIT_SHA=latest
DEPLOYMENT_HOST_URL=http://localhost:8080
DD_API_KEY=dummy
DD_SITE=datadoghq.com
DD_RUM_APPLICATION_ID=dummy
DD_RUM_CLIENT_TOKEN=dummy
EOF
- name: Build services with GHA cache
run: |
# Build each service using the GHA cache from build jobs
docker buildx build \
--cache-from type=gha,scope=sticker-catalogue-service \
--load -t sticker-catalogue:latest \
-f sticker-catalogue/src/main/docker/Dockerfile.jvm \
sticker-catalogue
docker buildx build \
--cache-from type=gha,scope=sticker-award-service \
--load -t sticker-award:latest \
-f sticker-award/Dockerfile \
sticker-award
docker buildx build \
--cache-from type=gha,scope=user-management-service \
--load -t user-management:latest \
-f user-management/src/Stickerlandia.UserManagement.Api/Dockerfile \
user-management
docker buildx build \
--cache-from type=gha,scope=user-management-worker \
--load -t user-management-worker:latest \
-f user-management/src/Stickerlandia.UserManagement.Worker/Dockerfile \
user-management
docker buildx build \
--cache-from type=gha,scope=user-management-migration \
--load -t user-management-migration:latest \
-f user-management/src/Stickerlandia.UserManagement.MigrationService/Dockerfile \
user-management
docker buildx build \
--cache-from type=gha,scope=web-backend-service \
--load -t web-backend:latest \
-f web-backend/Dockerfile \
web-backend
docker buildx build \
--cache-from type=gha,scope=web-frontend \
--load -t web-frontend:latest \
-f web-frontend/Dockerfile \
web-frontend
- name: Start services
run: docker compose up -d
- name: Wait for services
run: ./scripts/wait-for-services.sh
- name: Test service endpoints
run: ./scripts/test-services.sh --max-retries 5 --retry-delay 10
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: e2e/package-lock.json
- name: Install Playwright
working-directory: e2e
run: npm ci && npx playwright install --with-deps chromium
- name: Run E2E tests
working-directory: e2e
run: npx playwright test
env:
CI: true
BASE_URL: http://localhost:8080
- name: Upload report on failure
uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report
path: e2e/playwright-report/
- name: Cleanup
if: always()
run: docker compose down -v