-
-
Notifications
You must be signed in to change notification settings - Fork 350
1322 lines (1151 loc) · 56.8 KB
/
Copy pathmaven-staging.yml
File metadata and controls
1322 lines (1151 loc) · 56.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
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Maven Staging Repository Test
# Triggers on pull requests that modify Maven-related files
on:
pull_request:
branches: [ develop, main ]
paths:
- 'java/src/hdf/hdf5lib/**'
- 'HDF5Examples/JAVA/**'
- '.github/workflows/maven-*.yml'
- '.github/workflows/java-examples-*.yml'
- 'CMakePresets.json'
- '**/CMakeLists.txt'
- 'java/src/hdf/hdf5lib/pom.xml.in'
- 'HDF5Examples/JAVA/pom-examples.xml.in'
workflow_call:
inputs:
test_maven_deployment:
description: 'Test Maven deployment to staging'
type: boolean
required: false
default: true
use_snapshot_version:
description: 'Use snapshot version (-SNAPSHOT suffix)'
type: boolean
required: false
default: true
platforms:
description: 'Build platforms for Maven artifacts'
type: string
required: false
default: 'all-platforms'
java_implementation:
description: 'Java implementation to test'
type: string
required: false
default: 'both'
outputs:
version:
description: 'Maven artifact version that was built'
value: ${{ jobs.test-maven-deployment.outputs.version }}
workflow_dispatch:
inputs:
test_maven_deployment:
description: 'Test Maven deployment to staging'
type: boolean
required: false
default: true
use_snapshot_version:
description: 'Use snapshot version (-SNAPSHOT suffix)'
type: boolean
required: false
default: true
platforms:
description: 'Build platforms for Maven artifacts'
type: choice
required: false
default: 'all-platforms'
options:
- 'linux-only'
- 'linux-windows'
- 'linux-macos'
- 'all-platforms'
java_implementation:
description: 'Java implementation to test'
type: choice
required: false
default: 'both'
options:
- 'both'
- 'ffm'
- 'jni'
- 'auto'
permissions:
contents: read
packages: write
pull-requests: write
jobs:
detect-changes:
name: Detect Maven-related Changes
runs-on: ubuntu-latest
outputs:
maven-changes: ${{ steps.changes.outputs.maven }}
should-test: ${{ steps.should-test.outputs.result }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Detect changes in Maven-related files
id: changes
run: |
# Check if this is a manual trigger
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "maven=true" >> $GITHUB_OUTPUT
echo "Manual workflow dispatch - Maven testing enabled"
exit 0
fi
# For push events, check the last commit
if [ "${{ github.event_name }}" == "push" ]; then
echo "maven=true" >> $GITHUB_OUTPUT
echo "Push event - Maven testing enabled"
exit 0
fi
# For pull requests, check changed files
if [ -n "${{ github.base_ref }}" ]; then
git fetch origin ${{ github.base_ref }}
MAVEN_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E "(java/src/hdf/hdf5lib/|HDF5Examples/JAVA/|maven|pom\.xml|CMakePresets\.json)" || true)
else
# Fallback: assume changes if base_ref not available
MAVEN_FILES="true"
fi
if [ -n "$MAVEN_FILES" ]; then
echo "maven=true" >> $GITHUB_OUTPUT
echo "Maven-related changes detected"
else
echo "maven=false" >> $GITHUB_OUTPUT
echo "No Maven-related changes detected"
fi
- name: Determine if Maven testing should run
id: should-test
run: |
if [ "${{ steps.changes.outputs.maven }}" == "true" ] || [ "${{ inputs.test_maven_deployment }}" == "true" ]; then
echo "result=true" >> $GITHUB_OUTPUT
echo "Maven testing will be performed"
else
echo "result=false" >> $GITHUB_OUTPUT
echo "Maven testing will be skipped"
fi
determine-matrix:
name: Determine Build Matrix
needs: detect-changes
if: ${{ needs.detect-changes.outputs.should-test == 'true' }}
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Determine build matrix
id: set-matrix
run: |
JAVA_IMPL="${{ inputs.java_implementation || 'auto' }}"
PLATFORMS="${{ inputs.platforms || 'all-platforms' }}"
# Determine which implementations to build
case "$JAVA_IMPL" in
"ffm")
IMPLEMENTATIONS='["ffm"]'
;;
"jni")
IMPLEMENTATIONS='["jni"]'
;;
"both")
IMPLEMENTATIONS='["ffm", "jni"]'
;;
"auto"|*)
# Auto means build based on Java version (defaults handled by presets)
# We'll build once with auto setting
IMPLEMENTATIONS='["auto"]'
;;
esac
# Determine which platforms to build
case "$PLATFORMS" in
"linux-only")
PLATFORM_LIST='[{"name": "Linux", "os": "ubuntu-latest", "compiler": "GNUC", "arch": "x86_64"}]'
;;
"linux-windows")
PLATFORM_LIST='[{"name": "Linux", "os": "ubuntu-latest", "compiler": "GNUC", "arch": "x86_64"}, {"name": "Windows", "os": "windows-latest", "compiler": "MSVC", "arch": "x86_64"}]'
;;
"linux-macos")
PLATFORM_LIST='[{"name": "Linux", "os": "ubuntu-latest", "compiler": "GNUC", "arch": "x86_64"}, {"name": "macOS-x86_64", "os": "macos-14", "compiler": "Clang", "arch": "x86_64"}, {"name": "macOS-aarch64", "os": "macos-latest", "compiler": "Clang", "arch": "aarch64"}]'
;;
"all-platforms"|*)
PLATFORM_LIST='[{"name": "Linux", "os": "ubuntu-latest", "compiler": "GNUC", "arch": "x86_64"}, {"name": "Windows", "os": "windows-latest", "compiler": "MSVC", "arch": "x86_64"}, {"name": "macOS-x86_64", "os": "macos-14", "compiler": "Clang", "arch": "x86_64"}, {"name": "macOS-aarch64", "os": "macos-latest", "compiler": "Clang", "arch": "aarch64"}]'
;;
esac
# Create the full matrix combining platforms and implementations
MATRIX="{\"include\":["
FIRST=true
for platform in $(echo "$PLATFORM_LIST" | jq -c '.[]'); do
for impl in $(echo "$IMPLEMENTATIONS" | jq -r '.[]'); do
if [ "$FIRST" = true ]; then
FIRST=false
else
MATRIX+=","
fi
# Extract platform details
PLATFORM_NAME=$(echo "$platform" | jq -r '.name')
PLATFORM_OS=$(echo "$platform" | jq -r '.os')
PLATFORM_COMPILER=$(echo "$platform" | jq -r '.compiler')
PLATFORM_ARCH=$(echo "$platform" | jq -r '.arch')
# Create artifact name suffix
# Platform name already includes arch for macOS (e.g., macOS-x86_64)
PLATFORM_LOWER="${PLATFORM_NAME,,}"
if [[ "$PLATFORM_LOWER" == *"-"* ]]; then
# Platform name already has arch suffix (macOS case)
BASE_NAME="$PLATFORM_LOWER"
else
# Add arch suffix (Linux, Windows case)
BASE_NAME="${PLATFORM_LOWER}-${PLATFORM_ARCH}"
fi
if [ "$impl" = "auto" ]; then
ARTIFACT_SUFFIX="$BASE_NAME"
else
ARTIFACT_SUFFIX="${BASE_NAME}-${impl}"
fi
MATRIX+="{\"platform\":\"$PLATFORM_NAME\",\"os\":\"$PLATFORM_OS\",\"compiler\":\"$PLATFORM_COMPILER\",\"arch\":\"$PLATFORM_ARCH\",\"implementation\":\"$impl\",\"artifact-suffix\":\"$ARTIFACT_SUFFIX\"}"
done
done
MATRIX+="]}"
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
echo "Generated matrix:"
echo "$MATRIX" | jq '.'
build-maven-artifacts:
name: "Build Maven Artifacts (${{ matrix.platform }} - ${{ matrix.implementation }})"
needs: [detect-changes, determine-matrix]
if: ${{ needs.detect-changes.outputs.should-test == 'true' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.determine-matrix.outputs.matrix) }}
steps:
- name: Install Dependencies (Linux)
if: ${{ runner.os == 'Linux' }}
run: |
sudo apt-get update
sudo apt-get install ninja-build graphviz
- name: Install Dependencies (macOS)
if: ${{ runner.os == 'macOS' }}
run: |
brew install ninja graphviz
- name: Install Dependencies (Windows)
if: ${{ runner.os == 'Windows' }}
run: |
choco install ninja
choco install graphviz
- name: Enable Developer Command Prompt (Windows)
if: ${{ runner.os == 'Windows' }}
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
- name: Set up JDK (Java 25 for FFM builds)
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: ${{ matrix.implementation == 'ffm' && '25' || '21' }}
distribution: ${{ matrix.implementation == 'ffm' && 'oracle' || 'temurin' }}
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup jextract (FFM builds only)
if: ${{ matrix.implementation == 'ffm' }}
uses: ./.github/actions/setup-jextract
with:
java-version: '25'
- name: Set preset name
id: set-preset
shell: bash
run: |
# Determine implementation suffix for preset based on matrix
JAVA_IMPL="${{ matrix.implementation }}"
case "$JAVA_IMPL" in
"ffm")
IMPL_SUFFIX="-FFM"
;;
"jni"|"auto"|*)
# JNI and auto use default Maven presets (JNI is default as of HDF5 2.0)
IMPL_SUFFIX=""
;;
esac
# Determine snapshot setting
SNAPSHOT_SUFFIX=""
if [ "${{ inputs.use_snapshot_version }}" == "true" ] || [ "${{ github.event_name }}" == "pull_request" ]; then
SNAPSHOT_SUFFIX="-Snapshot"
fi
# Build preset name: ci-MinShar-{COMPILER}-Maven{-FFM}{-Snapshot}
# Note: Generic Maven presets default to JNI (no suffix needed)
PRESET_NAME="ci-MinShar-${{ matrix.compiler }}-Maven${IMPL_SUFFIX}${SNAPSHOT_SUFFIX}"
echo "preset=$PRESET_NAME" >> $GITHUB_OUTPUT
echo "Using preset: $PRESET_NAME"
echo "Platform: ${{ matrix.platform }}, Compiler: ${{ matrix.compiler }}, Implementation: $JAVA_IMPL"
- name: Build HDF5 with Maven support
id: buildhdf5
shell: bash
run: |
# macOS: Disable Spotlight indexing to prevent file locking during CPack
if [[ "$RUNNER_OS" == "macOS" ]]; then
echo "Disabling Spotlight indexing temporarily"
sudo mdutil -i off / || true
fi
cd "${{ github.workspace }}"
# Run workflow with retry logic for macOS CPack failures
if [[ "$RUNNER_OS" == "macOS" ]]; then
echo "Running CMake workflow with macOS retry logic..."
if ! cmake --workflow --preset="${{ steps.set-preset.outputs.preset }}" --fresh; then
echo "⚠️ First attempt failed, retrying in 5 seconds..."
sleep 5
cmake --workflow --preset="${{ steps.set-preset.outputs.preset }}" --fresh
fi
else
# Non-macOS: run normally without retry
cmake --workflow --preset="${{ steps.set-preset.outputs.preset }}" --fresh
fi
- name: Extract version information
id: version-info
shell: bash
run: |
# Find the generated POM file across all possible locations
BUILD_ROOT="${{ runner.workspace }}/build/${{ steps.set-preset.outputs.preset }}"
echo "Looking for POM file in: $BUILD_ROOT"
# Try multiple search patterns for cross-platform compatibility
POM_FILE=""
# Search patterns in order of preference
if [ -z "$POM_FILE" ]; then
POM_FILE=$(find "$BUILD_ROOT" -name "pom.xml" -path "*/java/*" 2>/dev/null | head -1)
fi
if [ -z "$POM_FILE" ]; then
POM_FILE=$(find "$BUILD_ROOT" -name "pom.xml" 2>/dev/null | head -1)
fi
# Try Maven artifacts directory if build structure differs
if [ -z "$POM_FILE" ] && [ -d "${{ runner.workspace }}/maven-artifacts" ]; then
POM_FILE=$(find "${{ runner.workspace }}/maven-artifacts" -name "pom.xml" 2>/dev/null | head -1)
fi
if [ -n "$POM_FILE" ] && [ -f "$POM_FILE" ]; then
# Extract version using robust pattern that works across platforms
VERSION=$(grep -o '<version>[^<]*</version>' "$POM_FILE" | head -1 | sed 's/<[^>]*>//g' | tr -d '\r\n')
# Validate version format
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "✓ Detected version: $VERSION"
echo "✓ POM file: $POM_FILE"
else
echo "version=unknown" >> $GITHUB_OUTPUT
echo "❌ Invalid version format detected: $VERSION"
exit 1
fi
else
echo "version=unknown" >> $GITHUB_OUTPUT
echo "❌ Could not find POM file"
echo "Available files in build root:"
find "$BUILD_ROOT" -name "*.xml" -o -name "pom*" 2>/dev/null | head -10 || echo "No XML files found"
exit 1
fi
- name: Collect Maven artifacts
shell: bash
run: |
echo "Collecting Maven artifacts for testing..."
mkdir -p "${{ runner.workspace }}/maven-artifacts"
BUILD_ROOT="${{ runner.workspace }}/build/${{ steps.set-preset.outputs.preset }}"
echo "Looking for Maven artifacts in build root: $BUILD_ROOT"
if [ ! -d "$BUILD_ROOT" ]; then
echo "ERROR: Build root directory does not exist: $BUILD_ROOT"
exit 1
fi
# Debug: Show what's in the build directory
echo "Build directory contents:"
find "$BUILD_ROOT" -maxdepth 3 -type d 2>/dev/null | head -20 || echo "Directory listing completed"
# Find build directory (try multiple patterns)
BUILD_DIR=$(find "$BUILD_ROOT" -name "*Maven*" -type d 2>/dev/null | head -1)
if [ -z "$BUILD_DIR" ]; then
# Try looking for java directory as fallback (more specific patterns)
BUILD_DIR=$(find "$BUILD_ROOT" -path "*/java/*" -type d 2>/dev/null | head -1)
if [ -z "$BUILD_DIR" ]; then
BUILD_DIR=$(find "$BUILD_ROOT" -name "java" -type d 2>/dev/null | head -1)
fi
fi
if [ -z "$BUILD_DIR" ]; then
# Try looking for any directory with JAR files
JAR_FILE=$(find "$BUILD_ROOT" -name "*.jar" -type f 2>/dev/null | head -1)
if [ -n "$JAR_FILE" ]; then
BUILD_DIR=$(dirname "$JAR_FILE")
echo "Found JAR file in: $BUILD_DIR"
fi
fi
if [ -z "$BUILD_DIR" ]; then
# Last resort: look for the build directory itself if it contains artifacts
if find "$BUILD_ROOT" -name "*.jar" -o -name "pom.xml" | grep -q .; then
BUILD_DIR="$BUILD_ROOT"
echo "Using build root as artifacts directory"
fi
fi
if [ -z "$BUILD_DIR" ]; then
echo "ERROR: Could not find Maven build directory with any of the patterns"
echo "Available directories:"
find "$BUILD_ROOT" -maxdepth 2 -type d
exit 1
fi
echo "Looking for artifacts in: $BUILD_DIR"
# Debug: Show all JAR files in build directory
echo "All JAR files in build directory:"
find "$BUILD_DIR" -name "*.jar" -type f 2>/dev/null | head -20 || true
# Debug: Show specifically what we're looking for
echo "SLF4J JAR files in build directory:"
find "$BUILD_DIR" -name "*slf4j*.jar" -type f
# Copy JAR files (excluding test and H5Ex_ example JARs)
find "$BUILD_DIR" -name "*.jar" -not -name "*test*" -not -name "*H5Ex_*" -exec cp {} "${{ runner.workspace }}/maven-artifacts/" \;
# Also look for Maven dependencies in common locations
echo "Looking for Maven dependencies in additional locations..."
# Check if there's a Maven repository in the build area
if [ -d "$BUILD_ROOT" ]; then
find "$BUILD_ROOT" -name "*slf4j*.jar" -type f -exec cp {} "${{ runner.workspace }}/maven-artifacts/" \;
fi
# Check common Maven local repository locations
MAVEN_REPO_PATHS=(
"$HOME/.m2/repository"
"$BUILD_ROOT/.m2/repository"
"${{ runner.workspace }}/.m2/repository"
)
for repo_path in "${MAVEN_REPO_PATHS[@]}"; do
if [ -d "$repo_path" ]; then
echo "Checking Maven repository: $repo_path"
find "$repo_path" -name "slf4j-api*.jar" -o -name "slf4j-simple*.jar" 2>/dev/null | head -2 | while read jar_file; do
if [ -f "$jar_file" ]; then
echo "Found dependency: $jar_file"
cp "$jar_file" "${{ runner.workspace }}/maven-artifacts/"
fi
done
fi
done
# Copy POM files
find "$BUILD_DIR" -name "pom.xml" -exec cp {} "${{ runner.workspace }}/maven-artifacts/" \;
# List collected artifacts
echo "Collected Maven artifacts:"
ls -la "${{ runner.workspace }}/maven-artifacts/"
- name: Validate artifacts
id: artifacts-check
shell: bash
run: |
ARTIFACT_COUNT=$(find "${{ runner.workspace }}/maven-artifacts" -name "*.jar" | wc -l)
POM_COUNT=$(find "${{ runner.workspace }}/maven-artifacts" -name "pom.xml" | wc -l)
echo "Found $ARTIFACT_COUNT JAR files and $POM_COUNT POM files"
if [ $ARTIFACT_COUNT -gt 0 ] && [ $POM_COUNT -gt 0 ]; then
echo "created=true" >> $GITHUB_OUTPUT
echo "✅ Artifacts successfully created"
else
echo "created=false" >> $GITHUB_OUTPUT
echo "❌ Artifact creation failed"
exit 1
fi
- name: Verify JAR contents (CRITICAL - Prevents Incomplete Packages)
shell: bash
run: |
echo "::group::Verify JAR contents"
echo "============================================"
echo "Verifying Maven artifacts contain HDF5 classes"
echo "============================================"
ARTIFACT_DIR="${{ runner.workspace }}/maven-artifacts"
VERIFICATION_FAILED=false
IMPL="${{ matrix.implementation }}"
# Find the main HDF5 JAR (not slf4j dependencies)
HDF5_JAR=$(find "$ARTIFACT_DIR" -name "*hdf5*.jar" ! -name "*sources*" ! -name "*javadoc*" ! -name "*slf4j*" | head -1)
if [ -z "$HDF5_JAR" ]; then
# Try alternative naming (jarhdf5)
HDF5_JAR=$(find "$ARTIFACT_DIR" -name "jarhdf5*.jar" ! -name "*sources*" ! -name "*javadoc*" | head -1)
fi
if [ -z "$HDF5_JAR" ]; then
echo "::error::Could not find HDF5 JAR file in artifacts"
echo "Available JAR files:"
find "$ARTIFACT_DIR" -name "*.jar" -ls
exit 1
fi
echo "Found HDF5 JAR: $HDF5_JAR"
echo "JAR size: $(du -h "$HDF5_JAR" | cut -f1)"
echo ""
# Determine implementation type (FFM or JNI)
if [ "$IMPL" = "ffm" ]; then
echo "Verifying FFM implementation..."
echo "Expected package: org.hdfgroup.javahdf5.*"
# Check for key FFM classes
if jar tf "$HDF5_JAR" | grep -q "org/hdfgroup/javahdf5/hdf5_h.class"; then
CLASS_COUNT=$(jar tf "$HDF5_JAR" | grep "org/hdfgroup/javahdf5.*\.class" | wc -l)
echo "✅ JAR contains HDF5 FFM classes"
echo " Found $CLASS_COUNT FFM classes"
# List some sample classes to verify content
echo " Sample classes:"
jar tf "$HDF5_JAR" | grep "org/hdfgroup/javahdf5.*\.class" | head -5 2>/dev/null | sed 's/^/ - /' || true
else
echo "::error::JAR does not contain HDF5 FFM classes!"
echo "JAR only contains:"
jar tf "$HDF5_JAR" | head -30 2>/dev/null || true
VERIFICATION_FAILED=true
fi
else
# JNI or auto (defaults to JNI)
echo "Verifying JNI implementation..."
echo "Expected package: hdf.hdf5lib.*"
# Check for key JNI classes
if jar tf "$HDF5_JAR" | grep -q "hdf/hdf5lib/H5.class"; then
CLASS_COUNT=$(jar tf "$HDF5_JAR" | grep "hdf/hdf5lib.*\.class" | wc -l)
echo "✅ JAR contains HDF5 JNI classes"
echo " Found $CLASS_COUNT JNI classes"
# Verify key classes are present
MISSING_CLASSES=""
for key_class in "hdf/hdf5lib/H5.class" "hdf/hdf5lib/HDF5Constants.class" "hdf/hdf5lib/HDFNativeData.class"; do
if ! jar tf "$HDF5_JAR" | grep -q "$key_class"; then
MISSING_CLASSES="$MISSING_CLASSES $key_class"
fi
done
if [ -n "$MISSING_CLASSES" ]; then
echo "::warning::Some expected classes are missing:$MISSING_CLASSES"
fi
# List some sample classes to verify content
echo " Sample classes:"
jar tf "$HDF5_JAR" | grep "hdf/hdf5lib.*\.class" | head -5 2>/dev/null | sed 's/^/ - /' || true
else
echo "::error::JAR does not contain HDF5 JNI classes!"
echo "JAR only contains:"
jar tf "$HDF5_JAR" | head -30 2>/dev/null || true
VERIFICATION_FAILED=true
fi
fi
# Additional checks
echo ""
echo "Additional JAR checks:"
# Check JAR size (should be > 50KB for real HDF5 classes)
JAR_SIZE=$(stat -f%z "$HDF5_JAR" 2>/dev/null || stat -c%s "$HDF5_JAR" 2>/dev/null || echo "0")
if [ "$JAR_SIZE" -lt 51200 ]; then
echo "::warning::JAR size is suspiciously small: $JAR_SIZE bytes (expected > 50KB)"
echo " This may indicate the JAR only contains dependencies."
else
echo "✅ JAR size is reasonable: $(($JAR_SIZE / 1024)) KB"
fi
# Count total files in JAR
TOTAL_FILES=$(jar tf "$HDF5_JAR" | wc -l)
echo "✅ Total files in JAR: $TOTAL_FILES"
echo "::endgroup::"
if [ "$VERIFICATION_FAILED" = true ]; then
echo ""
echo "::error::❌ JAR verification failed!"
echo "::error::The Maven artifact does not contain HDF5 classes."
echo "::error::This would result in an incomplete/broken package being deployed."
echo "::error::"
echo "::error::Possible causes:"
echo "::error:: 1. CMake add_jar not executing correctly"
echo "::error:: 2. Wrong JAR file being collected"
echo "::error:: 3. Build failure that went undetected"
echo "::error::"
echo "::error::Please review the build logs and CMake configuration."
exit 1
fi
echo ""
echo "✅ JAR verification passed - artifact is complete!"
- name: Run validation script
shell: bash
run: |
if [ -f .github/scripts/validate-maven-artifacts.sh ]; then
echo "Running Maven artifact validation..."
.github/scripts/validate-maven-artifacts.sh "${{ runner.workspace }}/maven-artifacts"
else
echo "Validation script not found - skipping validation"
fi
- name: Install HDF5 binaries for testing
shell: bash
run: |
BUILD_ROOT="${{ runner.workspace }}/build/${{ steps.set-preset.outputs.preset }}"
INSTALL_DIR="${{ runner.workspace }}/hdf5-install"
echo "Installing HDF5 binaries to: $INSTALL_DIR"
cd "$BUILD_ROOT"
cmake --install . --prefix "$INSTALL_DIR"
echo "Installation contents:"
ls -la "$INSTALL_DIR"
if [ -d "$INSTALL_DIR/lib" ]; then
echo "Libraries:"
ls -la "$INSTALL_DIR/lib" | grep -E '\.so|\.dylib|\.dll' || echo "No shared libraries found"
fi
- name: Upload Maven artifacts
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v5
with:
name: maven-staging-artifacts-${{ matrix.artifact-suffix }}
path: ${{ runner.workspace }}/maven-artifacts
retention-days: 7
- name: Upload HDF5 installation for testing
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v5
with:
name: hdf5-install-${{ matrix.artifact-suffix }}
path: ${{ runner.workspace }}/hdf5-install
retention-days: 7
test-maven-deployment:
name: Test Maven Deployment
runs-on: ubuntu-latest
needs: [detect-changes, determine-matrix, build-maven-artifacts]
if: ${{ always() && needs.detect-changes.outputs.should-test == 'true' }}
outputs:
version: ${{ steps.extract-version.outputs.version }}
steps:
- name: Set up JDK 21
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: '21'
distribution: 'temurin'
- name: Download all Maven artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v6
with:
pattern: maven-staging-artifacts-*
path: ./artifacts
merge-multiple: false
- name: Checkout code for version extraction
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
path: source
- name: Extract version for testing
id: extract-version
run: |
# Extract version from first available POM file
POM_FILE=$(find ./artifacts -name "pom.xml" 2>/dev/null | head -1)
if [ -n "$POM_FILE" ]; then
VERSION=$(grep -o '<version>[^<]*</version>' "$POM_FILE" | head -1 | sed 's/<[^>]*>//g')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "✅ Extracted version from POM: $VERSION"
else
# Fallback: Extract version from H5public.h
echo "⚠️ No POM file found, extracting version from source..."
if [ -f "source/src/H5public.h" ]; then
H5_MAJOR=$(grep '#define H5_VERS_MAJOR' source/src/H5public.h | awk '{print $3}')
H5_MINOR=$(grep '#define H5_VERS_MINOR' source/src/H5public.h | awk '{print $3}')
H5_RELEASE=$(grep '#define H5_VERS_RELEASE' source/src/H5public.h | awk '{print $3}')
# Determine if this should be a SNAPSHOT version
if [ "${{ inputs.use_snapshot_version }}" == "true" ] || [ "${{ github.event_name }}" == "pull_request" ]; then
VERSION="${H5_MAJOR}.${H5_MINOR}.${H5_RELEASE}-SNAPSHOT"
else
VERSION="${H5_MAJOR}.${H5_MINOR}.${H5_RELEASE}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "✅ Extracted version from H5public.h: $VERSION"
else
echo "::error::Could not extract version from POM or source files"
exit 1
fi
fi
- name: Test Maven deployment (dry run)
run: |
echo "=== Maven Deployment Test (Dry Run) ==="
echo "Version: ${{ steps.extract-version.outputs.version }}"
echo "Repository: GitHub Packages (staging)"
# List artifacts to be deployed by platform
echo "Artifacts ready for deployment:"
for platform_dir in ./artifacts/*/; do
if [ -d "$platform_dir" ]; then
platform_name=$(basename "$platform_dir")
echo "Platform: $platform_name"
find "$platform_dir" -name "*.jar" -exec basename {} \; | sed 's/^/ - /'
fi
done
# Create test Maven settings
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
<servers>
<server>
<id>github</id>
<username>${env.GITHUB_ACTOR}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
</settings>
EOF
# Simulate deployment validation for each platform
total_jars=0
valid_jars=0
for jar_file in $(find ./artifacts -name "*.jar"); do
jar_name=$(basename "$jar_file")
platform=$(dirname "$jar_file" | sed 's|./artifacts/||')
total_jars=$((total_jars + 1))
echo "[$platform] Testing: $jar_name"
# Test JAR integrity
if jar tf "$jar_file" > /dev/null 2>&1; then
echo " ✓ JAR integrity verified"
valid_jars=$((valid_jars + 1))
else
echo " ❌ JAR integrity check failed"
fi
done
echo "Validation summary: $valid_jars/$total_jars JARs passed integrity check"
if [ $valid_jars -ne $total_jars ]; then
echo "❌ Some artifacts failed validation"
exit 1
fi
echo "🎉 Dry run deployment test passed!"
test-java-examples-maven:
name: "Test Java Examples with Maven Artifacts (${{ matrix.platform }} - ${{ matrix.implementation }})"
runs-on: ${{ matrix.os }}
needs: [detect-changes, determine-matrix, build-maven-artifacts]
if: ${{ always() && needs.detect-changes.outputs.should-test == 'true' && needs.build-maven-artifacts.result == 'success' }}
continue-on-error: true # Non-blocking failures
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.determine-matrix.outputs.matrix) }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up JDK (Java 25 for FFM builds)
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: ${{ matrix.implementation == 'ffm' && '25' || '21' }}
distribution: ${{ matrix.implementation == 'ffm' && 'oracle' || 'temurin' }}
- name: Install timeout command on macOS
if: ${{ startsWith(matrix.platform, 'macOS') }}
run: |
# Install GNU coreutils which includes gtimeout
brew install coreutils
echo "Installed gtimeout: $(which gtimeout)"
- name: Download Maven artifacts (${{ matrix.platform }} - ${{ matrix.implementation }})
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v6
with:
name: maven-staging-artifacts-${{ matrix.artifact-suffix }}
path: ./maven-artifacts/${{ matrix.platform }}
continue-on-error: true
- name: Cache Maven dependencies
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-examples-${{ hashFiles('**/pom-examples.xml*') }}
restore-keys: |
${{ runner.os }}-maven-examples-
${{ runner.os }}-maven-
- name: Test Java Examples (Unix)
if: ${{ matrix.platform != 'Windows' }}
id: test-examples-unix
shell: bash
run: |
echo "=== Java Examples Maven Integration Test (${{ matrix.platform }}) ==="
# Test one representative example from each category
cd HDF5Examples/JAVA
# Get absolute path to maven artifacts for this platform
MAVEN_ARTIFACTS_DIR="$(realpath ../../maven-artifacts/${{ matrix.platform }})"
echo "Maven artifacts directory (${{ matrix.platform }}): $MAVEN_ARTIFACTS_DIR"
# Find HDF5 JAR files (not dependencies like slf4j) - use platform-specific artifacts
HDF5_JAR=$(find "$MAVEN_ARTIFACTS_DIR" -name "*hdf5*.jar" -o -name "jarhdf5*.jar" 2>/dev/null | head -1)
if [ -z "$HDF5_JAR" ]; then
echo "❌ No HDF5 JAR files found for testing"
echo "Available JAR files:"
find "$MAVEN_ARTIFACTS_DIR" -name "*.jar"
exit 1
fi
echo "Using HDF5 JAR file: $HDF5_JAR"
# Detect JAR type by checking for FFM-specific classes
# FFM JARs contain org.hdfgroup.javahdf5 package, JNI JARs contain hdf.hdf5lib
if jar tf "$HDF5_JAR" | grep -q "org/hdfgroup/javahdf5/hdf5_h.class"; then
JAR_TYPE="ffm"
echo "Detected FFM JAR (contains org.hdfgroup.javahdf5 package)"
else
JAR_TYPE="jni"
echo "Detected JNI JAR (contains hdf.hdf5lib package)"
fi
# Determine which examples directory to use based on detected JAR type
# This ensures we test with examples that match the JAR's implementation
if [ "$JAR_TYPE" = "jni" ]; then
EXAMPLES_DIR="compat"
echo "Using JNI-compatible examples from compat/ directory"
else
EXAMPLES_DIR="."
echo "Using FFM examples from root directory"
fi
# Also find any dependency JARs - only include slf4j-api and slf4j-simple, exclude slf4j-nop to avoid conflicts
DEP_JARS=$(find "$MAVEN_ARTIFACTS_DIR" -name "slf4j-api*.jar" -o -name "slf4j-simple*.jar")
if [ -n "$DEP_JARS" ]; then
echo "Found dependency JARs:"
echo "$DEP_JARS"
else
echo "No SLF4J dependency JARs found in artifacts, downloading them directly..."
# Download SLF4J dependencies directly using Maven
SLF4J_VERSION="2.0.16"
TEMP_POM="$MAVEN_ARTIFACTS_DIR/temp-pom.xml"
# Create a minimal POM to download dependencies using echo
echo '<?xml version="1.0" encoding="UTF-8"?>' > "$TEMP_POM"
echo '<project xmlns="http://maven.apache.org/POM/4.0.0"' >> "$TEMP_POM"
echo ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' >> "$TEMP_POM"
echo ' xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">' >> "$TEMP_POM"
echo ' <modelVersion>4.0.0</modelVersion>' >> "$TEMP_POM"
echo ' <groupId>temp</groupId>' >> "$TEMP_POM"
echo ' <artifactId>temp</artifactId>' >> "$TEMP_POM"
echo ' <version>1.0</version>' >> "$TEMP_POM"
echo ' <dependencies>' >> "$TEMP_POM"
echo ' <dependency>' >> "$TEMP_POM"
echo ' <groupId>org.slf4j</groupId>' >> "$TEMP_POM"
echo ' <artifactId>slf4j-api</artifactId>' >> "$TEMP_POM"
echo ' <version>2.0.16</version>' >> "$TEMP_POM"
echo ' </dependency>' >> "$TEMP_POM"
echo ' <dependency>' >> "$TEMP_POM"
echo ' <groupId>org.slf4j</groupId>' >> "$TEMP_POM"
echo ' <artifactId>slf4j-simple</artifactId>' >> "$TEMP_POM"
echo ' <version>2.0.16</version>' >> "$TEMP_POM"
echo ' </dependency>' >> "$TEMP_POM"
echo ' </dependencies>' >> "$TEMP_POM"
echo '</project>' >> "$TEMP_POM"
# Download dependencies
if (cd "$MAVEN_ARTIFACTS_DIR" && mvn -f temp-pom.xml dependency:copy-dependencies -DoutputDirectory=. -DincludeScope=runtime -q); then
# Clean up temporary POM
rm -f "$TEMP_POM"
# Re-scan for dependency JARs
DEP_JARS=$(find "$MAVEN_ARTIFACTS_DIR" -name "slf4j-api*.jar" -o -name "slf4j-simple*.jar")
if [ -n "$DEP_JARS" ]; then
echo "Successfully downloaded SLF4J dependencies:"
echo "$DEP_JARS"
else
echo "Failed to download SLF4J dependencies"
fi
else
echo "Error downloading dependencies with Maven"
rm -f "$TEMP_POM"
fi
fi
FAILED_EXAMPLES=""
TOTAL_EXAMPLES=0
PASSED_EXAMPLES=0
# Save current directory (HDF5Examples/JAVA)
JAVA_DIR="$(pwd)"
# Test representative examples from each category
for category in H5D H5T H5G TUTR; do
if [ -d "$EXAMPLES_DIR/$category" ]; then
cd "$JAVA_DIR/$EXAMPLES_DIR/$category"
# Find first .java file in category
EXAMPLE_FILE=$(ls *.java | head -1)
if [ -f "$EXAMPLE_FILE" ]; then
TOTAL_EXAMPLES=$((TOTAL_EXAMPLES + 1))
example_name=$(basename "$EXAMPLE_FILE" .java)
echo "--- Testing $category/$example_name ---"
# Build classpath with HDF5 JAR and dependencies (already absolute paths)
CLASSPATH="$HDF5_JAR"
if [ -n "$DEP_JARS" ]; then
for dep_jar in $DEP_JARS; do
CLASSPATH="$CLASSPATH:$dep_jar"
done
fi
echo "Using classpath: $CLASSPATH"
# Set compilation flags based on detected JAR type
# This ensures we use correct flags for the actual JAR implementation
if [ "$JAR_TYPE" = "ffm" ]; then
# FFM requires preview features (Java 25)
JAVAC_FLAGS="--enable-preview --release 25"
JAVA_FLAGS="--enable-preview"
else
# JNI uses standard Java
JAVAC_FLAGS=""
JAVA_FLAGS=""
fi
# Test compilation
COMPILE_OUTPUT=$(javac $JAVAC_FLAGS -cp "$CLASSPATH" "$EXAMPLE_FILE" 2>&1)
if [ $? -eq 0 ]; then
echo "✓ Compilation successful for $category/$example_name"
# Test execution (with cross-platform timeout)
if command -v gtimeout >/dev/null 2>&1; then
# macOS with GNU coreutils timeout
EXEC_RESULT=$(gtimeout 10s java $JAVA_FLAGS -cp ".:$CLASSPATH" "$example_name" >/tmp/${example_name}.out 2>&1; echo $?)
elif command -v timeout >/dev/null 2>&1; then
# Linux/Windows with timeout command
EXEC_RESULT=$(timeout 10s java $JAVA_FLAGS -cp ".:$CLASSPATH" "$example_name" >/tmp/${example_name}.out 2>&1; echo $?)
else
# Fallback - run without timeout (Java examples should complete quickly)
echo "Note: Running without timeout"
java $JAVA_FLAGS -cp ".:$CLASSPATH" "$example_name" >/tmp/${example_name}.out 2>&1
EXEC_RESULT=$?
fi
if [ "$EXEC_RESULT" -eq 0 ]; then
# Basic output validation
if grep -q -i -E "(dataset|datatype|group|success|created|written|read)" /tmp/${example_name}.out && \
! grep -q -i -E "(error|exception|failed|cannot)" /tmp/${example_name}.out; then
echo "✓ Execution and validation successful for $category/$example_name"
PASSED_EXAMPLES=$((PASSED_EXAMPLES + 1))
else
echo "✗ Output validation failed for $category/$example_name"
echo "Output:"
cat /tmp/${example_name}.out
FAILED_EXAMPLES="$FAILED_EXAMPLES $category/$example_name"
fi
else
# Check if failure is due to expected native library issue (acceptable for Maven-only testing)
if grep -q "UnsatisfiedLinkError.*hdf5_java.*java.library.path" /tmp/${example_name}.out; then
echo "✓ Expected native library error for Maven-only testing: $category/$example_name"
echo " (This confirms JAR structure is correct)"
PASSED_EXAMPLES=$((PASSED_EXAMPLES + 1))
else
echo "✗ Unexpected execution failure for $category/$example_name"
echo "Output:"
cat /tmp/${example_name}.out
FAILED_EXAMPLES="$FAILED_EXAMPLES $category/$example_name"