-
Notifications
You must be signed in to change notification settings - Fork 0
324 lines (282 loc) · 10.8 KB
/
Copy pathci.yml
File metadata and controls
324 lines (282 loc) · 10.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
name: CI
on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
changes:
runs-on: ubuntu-latest
outputs:
backends: ${{ steps.set.outputs.backends }}
backends_testable: ${{ steps.set.outputs.backends_testable }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v5
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4
id: filter
with:
filters: |
auth: 'apps/Auth/**'
attendance: 'apps/Attendance/**'
coursemanagement: 'apps/CourseManagement/**'
payment: 'apps/Payment/**'
credentials: 'apps/Credentials/**'
frontend: 'apps/Frontend/**'
- id: set
run: |
set -euo pipefail
declare -A flags=(
[Auth]='${{ steps.filter.outputs.auth }}'
[Attendance]='${{ steps.filter.outputs.attendance }}'
[CourseManagement]='${{ steps.filter.outputs.coursemanagement }}'
[Payment]='${{ steps.filter.outputs.payment }}'
[Credentials]='${{ steps.filter.outputs.credentials }}'
)
backends=()
testable=()
for svc in Auth Attendance CourseManagement Payment Credentials; do
if [ "${flags[$svc]}" = "true" ]; then
backends+=("$svc")
if [ "$svc" != "Credentials" ]; then
testable+=("$svc")
fi
fi
done
emit() {
local name="$1"; shift
if [ "$#" -eq 0 ]; then
echo "$name=[]" >> "$GITHUB_OUTPUT"
else
echo "$name=$(printf '%s\n' "$@" | jq -R . | jq -cs .)" >> "$GITHUB_OUTPUT"
fi
}
emit backends "${backends[@]}"
emit backends_testable "${testable[@]}"
lint-dockerfiles:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Lint Dockerfiles
run: |
for dockerfile in \
infrastructure/environments/auth/Dockerfile \
infrastructure/environments/attendance/Dockerfile \
infrastructure/environments/course-management/Dockerfile \
infrastructure/environments/payment/Dockerfile \
infrastructure/environments/credentials/Dockerfile \
infrastructure/environments/api-gateway/Dockerfile \
infrastructure/environments/frontend/Dockerfile \
infrastructure/environments/rabbitmq/Dockerfile \
infrastructure/environments/tls-init/Dockerfile; do
echo "Linting $dockerfile"
docker run --rm -i hadolint/hadolint@sha256:30a8fd2e785ab6176eed53f74769e04f125afb2f74a6c52aef7d463583b6d45e < "$dockerfile"
done
build-backend:
needs: changes
if: ${{ needs.changes.outputs.backends != '[]' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
service: ${{ fromJSON(needs.changes.outputs.backends) }}
steps:
- uses: actions/checkout@v5
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '9.0.x'
- uses: actions/cache@v5
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ matrix.service }}-${{ hashFiles(format('apps/{0}/Backend/Backend.csproj', matrix.service)) }}
restore-keys: |
nuget-${{ runner.os }}-${{ matrix.service }}-
nuget-${{ runner.os }}-
- name: Restore
run: dotnet restore apps/${{ matrix.service }}/Backend/Backend.csproj --locked-mode
- name: Verify formatting (.editorconfig + analyzers)
run: dotnet format apps/${{ matrix.service }}/Backend/Backend.csproj --verify-no-changes --no-restore
- name: Build (warnings as errors → SonarAnalyzer strict)
run: dotnet build apps/${{ matrix.service }}/Backend/Backend.csproj -c Release --no-restore -p:TreatWarningsAsErrors=true
- name: Generate SBOM
run: |
dotnet tool install --global Microsoft.Sbom.DotNet
export PATH="$HOME/.dotnet/tools:$PATH"
sbom-tool generate \
-b apps/${{ matrix.service }}/Backend \
-bc apps/${{ matrix.service }}/Backend \
-pn DAMA.${{ matrix.service }} \
-pv ${{ github.sha }} \
-ps DAMA-Software \
-nsb https://github.com/JCarlosHidalgo/DAMA
continue-on-error: true
- uses: actions/upload-artifact@v4
if: always()
with:
name: sbom-${{ matrix.service }}
path: apps/${{ matrix.service }}/Backend/_manifest/spdx_2.2/
build-frontend:
needs: changes
if: ${{ needs.changes.outputs.frontend == 'true' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/Frontend
steps:
- uses: actions/checkout@v5
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: '1.3.10'
- uses: actions/cache@v5
with:
path: ~/.bun/install/cache
key: bun-${{ runner.os }}-${{ hashFiles('apps/Frontend/bun.lock') }}
restore-keys: |
bun-${{ runner.os }}-
- name: Install
run: bun install --frozen-lockfile
- name: Prettier check
run: bun run format:check
- name: ESLint
run: bun run lint
- name: Build
run: bun run build
test-backend:
needs: [changes, build-backend]
if: ${{ needs.changes.outputs.backends_testable != '[]' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
service: ${{ fromJSON(needs.changes.outputs.backends_testable) }}
steps:
- uses: actions/checkout@v5
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '9.0.x'
- uses: actions/cache@v5
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ matrix.service }}-${{ hashFiles(format('apps/{0}/Backend/Backend.csproj', matrix.service), format('apps/{0}/Test/Test.csproj', matrix.service)) }}
restore-keys: |
nuget-${{ runner.os }}-${{ matrix.service }}-
nuget-${{ runner.os }}-
- name: Restore test project
run: dotnet restore apps/${{ matrix.service }}/Test/Test.csproj
- name: Test
run: >
dotnet test apps/${{ matrix.service }}/Test/Test.csproj
--no-restore
--settings apps/${{ matrix.service }}/Test/.runsettings
--logger "trx;LogFileName=test-results.trx"
--results-directory apps/${{ matrix.service }}/Test/TestResults
- name: Critical coverage gate (100% business-logic lines)
run: python3 infrastructure/environments-test/cobertura-backends/check-coverage.py "${{ matrix.service }}" "apps/${{ matrix.service }}/Test/TestResults"
- name: Test summary
if: ${{ always() }}
env:
SERVICE: ${{ matrix.service }}
run: |
set -euo pipefail
trx=$(find "apps/${SERVICE}/Test/TestResults" -name '*.trx' | head -n1 || true)
if [ -z "$trx" ]; then
{
echo "## ${SERVICE} Backend Test Report"
echo ""
echo "_No test results (.trx) were produced._"
} >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
python3 - "$trx" >> "$GITHUB_STEP_SUMMARY" <<'PY'
import os, sys, xml.etree.ElementTree as ET
service = os.environ["SERVICE"]
root = ET.parse(sys.argv[1]).getroot()
local = lambda tag: tag.split('}')[-1]
counters = {}
classes = set()
for element in root.iter():
name = local(element.tag)
if name == "Counters":
counters = element.attrib
elif name == "TestMethod":
class_name = element.attrib.get("className")
if class_name:
classes.add(class_name)
total = int(counters.get("total", 0))
passed = int(counters.get("passed", 0))
failed = int(counters.get("failed", 0))
executed = int(counters.get("executed", 0))
skipped = max(total - executed, 0)
separator = " · "
plural = lambda count, one, many: one if count == 1 else many
primary = []
if failed > 0:
primary.append(f"❌ **{failed} {plural(failed, 'failure', 'failures')}**")
if passed > 0:
primary.append(f"✅ **{passed} {plural(passed, 'pass', 'passes')}**")
primary.append(f"{total} total")
lines = [
f"## {service} Backend Test Report",
"",
"### Summary",
"",
f"- **Test Files**: {len(classes)} total",
f"- **Test Results**: {separator.join(primary)}",
]
if skipped > 0:
lines.append(f"- **Other**: {skipped} skipped{separator}{skipped} total")
print("\n".join(lines))
PY
test-frontend:
needs: [changes, build-frontend]
if: ${{ needs.changes.outputs.frontend == 'true' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/Frontend
steps:
- uses: actions/checkout@v5
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: '1.3.10'
- uses: actions/cache@v5
with:
path: ~/.bun/install/cache
key: bun-${{ runner.os }}-${{ hashFiles('apps/Frontend/bun.lock') }}
restore-keys: |
bun-${{ runner.os }}-
- name: Install
run: bun install --frozen-lockfile
- name: Test (with coverage gate)
run: bun run test:coverage:gate
ci-gate:
needs: [build-backend, build-frontend, test-backend, test-frontend, lint-dockerfiles]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Verify required jobs succeeded
run: |
set -euo pipefail
declare -A results=(
[build-backend]='${{ needs.build-backend.result }}'
[build-frontend]='${{ needs.build-frontend.result }}'
[test-backend]='${{ needs.test-backend.result }}'
[test-frontend]='${{ needs.test-frontend.result }}'
[lint-dockerfiles]='${{ needs.lint-dockerfiles.result }}'
)
failed=0
for job in "${!results[@]}"; do
result="${results[$job]}"
echo "$job: $result"
if [ "$result" != "success" ] && [ "$result" != "skipped" ]; then
failed=1
fi
done
if [ "$failed" -ne 0 ]; then
echo "One or more required jobs did not succeed."
exit 1
fi