-
Notifications
You must be signed in to change notification settings - Fork 0
455 lines (395 loc) · 16.9 KB
/
gradle-java21.yml
File metadata and controls
455 lines (395 loc) · 16.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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
name: Gradle Build with Kotlin 2.0 and Java 21
on:
push:
branches: [ main, develop, 'feature/**', 'feat/**', 'fix/**', 'ci/**', 'copilot/**', 'claude/**' ]
pull_request:
branches: [ main, develop, 'feature/**', 'feat/**', 'fix/**', 'ci/**', 'copilot/**', 'claude/**' ]
workflow_dispatch: # Allow manual trigger
permissions:
contents: read
checks: write # For test reporting
packages: read # For GitHub Packages (kDisco dependency)
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
JAVA_VERSION: '21'
GRADLE_OPTS: '-Xmx512m -XX:MaxMetaspaceSize=512m'
KOTLIN_COMPILER_PARALLELISM: '4' # Enable parallel Kotlin compilation for faster builds
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 25 # Increased from 15 to 25 minutes for Kotlin compilation overhead
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ env.JAVA_VERSION }}
- name: Cache Koin Dependencies
id: cache-koin
uses: actions/cache@v4
with:
path: ~/.m2/repository/io/insert-koin
key: koin-${{ hashFiles('gradle.properties', 'build.gradle.kts') }}
restore-keys: |
koin-${{ hashFiles('gradle.properties', 'build.gradle.kts') }}
koin-
- name: Install kDisco 0.3.0 artifacts from repository
run: |
mkdir -p ~/.m2/repository/cz/hovorka/kdisco
cp -r docker-kdisco/cz/hovorka/kdisco/. ~/.m2/repository/cz/hovorka/kdisco/
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: wrapper
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use"
build-scan-terms-of-use-agree: "yes"
- name: Make Gradle wrapper executable
run: chmod +x gradlew
- name: Install libxml2 development headers
run: |
sudo apt-get update && sudo apt-get install -y --no-install-recommends libxml2-dev libicu-dev
sudo ln -sf /usr/include/unicode /usr/include/libxml2/unicode
- name: Compile Kotlin and Java sources
timeout-minutes: 15
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew clean compileKotlin compileJava compileTestKotlin compileTestJava --no-daemon --warning-mode=all --stacktrace
- name: Run unit tests
timeout-minutes: 10
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew test --no-daemon --warning-mode=all --stacktrace
- name: Run integration tests
timeout-minutes: 10
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew integrationTest --no-daemon --warning-mode=all --stacktrace
- name: Run linuxX64 native tests
timeout-minutes: 5
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew :core:linuxX64Test --no-daemon --stacktrace
- name: Verify Koin DI Configuration
timeout-minutes: 5
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Validating Koin dependency injection container..."
./gradlew verifyKoinConfiguration --no-daemon --stacktrace
echo ""
echo "✓ Koin DI container initialized and configured successfully"
- name: Create JAR artifacts (shadowJar)
timeout-minutes: 10
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew shadowJar --no-daemon --stacktrace
- name: Upload compiled JAR artifact
uses: actions/upload-artifact@v4
if: success()
with:
name: interlockSim-jar-${{ github.sha }}
path: desktop-ui/build/libs/interlockSim.jar
retention-days: 90
if-no-files-found: error
compression-level: 9
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ github.sha }}
path: desktop-ui/build/test-results/
retention-days: 30
- name: Generate test report summary
if: always()
run: |
if [ -f desktop-ui/build/test-results/test/TEST-*.xml ]; then
echo "## Test Execution Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Count total tests
TOTAL_TESTS=$(find desktop-ui/build/test-results -name "TEST-*.xml" -exec grep -h 'tests="' {} \; | awk -F'tests="' '{sum+=$2; gsub(/".*/, "", sum)}' | awk '{s+=$1} END {print s}')
echo "**Total Unit Tests**: $TOTAL_TESTS" >> $GITHUB_STEP_SUMMARY
# Count failures
FAILURES=$(find desktop-ui/build/test-results -name "TEST-*.xml" -exec grep -h 'failures="' {} \; | awk -F'failures="' '{sum+=$2; gsub(/".*/, "", sum)}' | awk '{s+=$1} END {print s}')
echo "**Failures**: $FAILURES" >> $GITHUB_STEP_SUMMARY
echo "**Status**: ✓ All tests passed" >> $GITHUB_STEP_SUMMARY
fi
- name: Run smoke test with Koin integration validation
if: success()
timeout-minutes: 8
run: |
echo "Starting smoke test (shunting loop, 300 simulated seconds with Koin)..."
echo "Timeout: 8 minutes. Expected: ~4-5 minutes."
echo ""
# Run simulation with timing metrics, capture output for cross-platform comparison
set -o pipefail # Ensure pipe propagates java exit code, not tee's
START_TIME=$(date +%s%N)
if java -Dlogback.configurationFile=.github/workflows/logback-ci.xml \
-jar desktop-ui/build/libs/interlockSim.jar example shuntingLoop 300 \
| tee jvm-smoke-output.txt; then
END_TIME=$(date +%s%N)
ELAPSED_MS=$(( (END_TIME - START_TIME) / 1000000 ))
ELAPSED_SEC=$(awk "BEGIN {printf \"%.2f\", $ELAPSED_MS / 1000}")
echo ""
echo "## Smoke Test Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Status:** ✓ Passed" >> $GITHUB_STEP_SUMMARY
echo "**Simulation:** Shunting Loop (vyhybna.xml)" >> $GITHUB_STEP_SUMMARY
echo "**Duration:** ${ELAPSED_SEC} seconds" >> $GITHUB_STEP_SUMMARY
echo "**Koin Status:** ✓ Initialized and configured" >> $GITHUB_STEP_SUMMARY
echo "**Framework:** Koin 3.5.6 dependency injection active" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✓ Smoke test completed successfully (${ELAPSED_SEC}s)"
exit 0
else
EXIT_CODE=$?
echo ""
echo "## Smoke Test Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Status:** ✗ Failed" >> $GITHUB_STEP_SUMMARY
echo "**Exit Code:** $EXIT_CODE" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✗ Smoke test failed with exit code: $EXIT_CODE"
exit $EXIT_CODE
fi
- name: Upload JVM smoke test output
uses: actions/upload-artifact@v4
if: success()
with:
name: jvm-smoke-output-${{ github.sha }}
path: jvm-smoke-output.txt
retention-days: 30
if-no-files-found: error
fast-sim:
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [build] # Gate: don't spend native build time unless JVM build passes
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ env.JAVA_VERSION }}
- name: Install kDisco 0.3.0 artifacts from repository
run: |
mkdir -p ~/.m2/repository/cz/hovorka/kdisco
cp -r docker-kdisco/cz/hovorka/kdisco/. ~/.m2/repository/cz/hovorka/kdisco/
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: wrapper
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use"
build-scan-terms-of-use-agree: "yes"
- name: Make Gradle wrapper executable
run: chmod +x gradlew
- name: Install libxml2 development headers
run: |
sudo apt-get update && sudo apt-get install -y --no-install-recommends libxml2-dev libicu-dev
sudo ln -sf /usr/include/unicode /usr/include/libxml2/unicode
- name: Build fast-sim native binary (release)
timeout-minutes: 20
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew :fast-sim:linkReleaseExecutableLinuxX64 --no-daemon --stacktrace
- name: Run fast-sim native tests
timeout-minutes: 5
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew :fast-sim:linuxX64Test --no-daemon --stacktrace
- name: Smoke test — native binary (shuntingLoop 300s)
timeout-minutes: 8
run: |
BINARY=fast-sim/build/bin/linuxX64/releaseExecutable/fast-sim.kexe
echo "Starting native smoke test (shunting loop, 300 simulated seconds)..."
START_TIME=$(date +%s%N)
if OUTPUT=$("$BINARY" example shuntingLoop 300 2>&1); then
END_TIME=$(date +%s%N)
ELAPSED_MS=$(( (END_TIME - START_TIME) / 1000000 ))
ELAPSED_SEC=$(awk "BEGIN {printf \"%.2f\", $ELAPSED_MS / 1000}")
# Verify output contains simulation summary with at least 1 train
if echo "$OUTPUT" | grep -qP -- '--- Simulation complete: [1-9]\d* trains'; then
echo "✓ Native smoke test passed (${ELAPSED_SEC}s)"
echo "$OUTPUT"
# Save output for cross-platform comparison
echo "$OUTPUT" > native-smoke-output.txt
else
echo "✗ Native smoke test: unexpected output (missing summary or 0 trains)"
echo "$OUTPUT"
exit 1
fi
else
EXIT_CODE=$?
echo "✗ Native smoke test failed with exit code: $EXIT_CODE"
echo "$OUTPUT"
exit $EXIT_CODE
fi
- name: Sanity check — verify version
run: |
BINARY=fast-sim/build/bin/linuxX64/releaseExecutable/fast-sim.kexe
echo "Binary path: $BINARY"
echo "Binary size: $(stat --format='%s' "$BINARY" | numfmt --to=iec-i --suffix=B)"
echo ""
VERSION=$("$BINARY" --version)
echo "Binary version: $VERSION"
if ! echo "$VERSION" | grep -q 'fast-sim'; then
echo "ERROR: --version output does not contain 'fast-sim'. Actual output: '$VERSION'"
exit 1
fi
- name: Upload fast-sim native binary
uses: actions/upload-artifact@v4
if: success()
with:
name: fast-sim-linux-x64-${{ github.sha }}
path: fast-sim/build/bin/linuxX64/releaseExecutable/fast-sim.kexe
retention-days: 30
if-no-files-found: error
compression-level: 9
- name: Upload native smoke test output
uses: actions/upload-artifact@v4
if: success()
with:
name: native-smoke-output-${{ github.sha }}
path: native-smoke-output.txt
retention-days: 30
if-no-files-found: error
- name: Add fast-sim summary
if: success()
run: |
BINARY=fast-sim/build/bin/linuxX64/releaseExecutable/fast-sim.kexe
SIZE=$(stat --format='%s' "$BINARY" | numfmt --to=iec-i --suffix=B)
VERSION=$("$BINARY" --version)
echo "## fast-sim Native Binary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** $VERSION" >> $GITHUB_STEP_SUMMARY
echo "**Size:** $SIZE" >> $GITHUB_STEP_SUMMARY
echo "**Artifact:** fast-sim-linux-x64-${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "**Retention:** 30 days" >> $GITHUB_STEP_SUMMARY
compare-outputs:
name: Compare JVM vs Native smoke-test outputs
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [build, fast-sim]
steps:
- name: Download JVM smoke test output
uses: actions/download-artifact@v4
with:
name: jvm-smoke-output-${{ github.sha }}
- name: Download native smoke test output
uses: actions/download-artifact@v4
with:
name: native-smoke-output-${{ github.sha }}
- name: Compare structural invariants
run: |
echo "Comparing JVM vs native smoke test outputs..."
echo ""
FAIL=0
# --- Invariant 1: Both outputs are non-empty ---
if [ ! -s jvm-smoke-output.txt ]; then
echo "FAIL: JVM output is empty"
FAIL=1
fi
if [ ! -s native-smoke-output.txt ]; then
echo "FAIL: Native output is empty"
FAIL=1
fi
# --- Invariant 2: Both contain event lines (t=<number>) ---
JVM_EVENTS=$(grep -cE 't=[0-9]' jvm-smoke-output.txt || true)
NATIVE_EVENTS=$(grep -cE 't=[0-9]' native-smoke-output.txt || true)
echo "JVM event lines: $JVM_EVENTS"
echo "Native event lines: $NATIVE_EVENTS"
if [ "$JVM_EVENTS" -eq 0 ]; then
echo "FAIL: JVM output has no event lines"
FAIL=1
fi
if [ "$NATIVE_EVENTS" -eq 0 ]; then
echo "FAIL: Native output has no event lines"
FAIL=1
fi
# --- Invariant 3: Both contain a summary line ---
JVM_SUMMARY=$(grep -- '^--- Simulation complete:' jvm-smoke-output.txt || true)
NATIVE_SUMMARY=$(grep -- '^--- Simulation complete:' native-smoke-output.txt || true)
echo "JVM summary: $JVM_SUMMARY"
echo "Native summary: $NATIVE_SUMMARY"
if [ -z "$JVM_SUMMARY" ]; then
echo "FAIL: JVM output missing simulation summary"
FAIL=1
fi
if [ -z "$NATIVE_SUMMARY" ]; then
echo "FAIL: Native output missing simulation summary"
FAIL=1
fi
# --- Invariant 4: Timestamps are chronologically ordered ---
for PLATFORM in jvm native; do
FILE="${PLATFORM}-smoke-output.txt"
PREV=0
ORDERED=true
while IFS= read -r ts; do
if awk "BEGIN { exit ($ts < $PREV) ? 0 : 1 }"; then
echo "FAIL: $PLATFORM timestamps not chronological: $ts < $PREV"
ORDERED=false
FAIL=1
break
fi
PREV=$ts
done < <(grep -oE 't=[0-9.]+' "$FILE" | sed 's/t=//')
if [ "$ORDERED" = true ]; then
echo "$PLATFORM timestamps: chronological OK"
fi
done
# --- Invariant 5: Both summaries mention trains ---
if [ -n "$JVM_SUMMARY" ] && ! echo "$JVM_SUMMARY" | grep -q 'trains'; then
echo "FAIL: JVM summary does not mention trains"
FAIL=1
fi
if [ -n "$NATIVE_SUMMARY" ] && ! echo "$NATIVE_SUMMARY" | grep -q 'trains'; then
echo "FAIL: Native summary does not mention trains"
FAIL=1
fi
# --- Invariant 6: Event counts within same order of magnitude (0.5x-2.0x) ---
if [ "$JVM_EVENTS" -gt 0 ] && [ "$NATIVE_EVENTS" -gt 0 ]; then
RATIO=$(awk "BEGIN { printf \"%.2f\", $JVM_EVENTS / $NATIVE_EVENTS }")
echo "Event count ratio (JVM/Native): $RATIO"
if awk "BEGIN { exit ($RATIO < 0.5 || $RATIO > 2.0) ? 0 : 1 }"; then
echo "FAIL: Event count ratio $RATIO outside acceptable range [0.5, 2.0]"
FAIL=1
fi
fi
echo ""
if [ "$FAIL" -eq 0 ]; then
echo "All 6 structural invariants passed."
else
echo "One or more structural invariants FAILED."
exit 1
fi
- name: Add comparison summary
if: always()
run: |
echo "## Cross-Platform Output Comparison (Issue #439)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Scenario:** shuntingLoop (endTime=300)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
JVM_EVENTS=$(grep -cE 't=[0-9]' jvm-smoke-output.txt 2>/dev/null || echo 0)
NATIVE_EVENTS=$(grep -cE 't=[0-9]' native-smoke-output.txt 2>/dev/null || echo 0)
JVM_SUMMARY=$(grep -- '^--- Simulation complete:' jvm-smoke-output.txt 2>/dev/null || true)
NATIVE_SUMMARY=$(grep -- '^--- Simulation complete:' native-smoke-output.txt 2>/dev/null || true)
echo "| Metric | JVM | Native |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-----|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Event lines | $JVM_EVENTS | $NATIVE_EVENTS |" >> $GITHUB_STEP_SUMMARY
echo "| Summary | ${JVM_SUMMARY:-missing} | ${NATIVE_SUMMARY:-missing} |" >> $GITHUB_STEP_SUMMARY