-
Notifications
You must be signed in to change notification settings - Fork 0
1454 lines (1247 loc) · 52.6 KB
/
Copy pathci.yml
File metadata and controls
1454 lines (1247 loc) · 52.6 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: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
release:
types: [published]
# Global permissions for the entire workflow
permissions:
contents: read
issues: write
checks: write
pull-requests: write
actions: read
env:
CONAN_USER_HOME: "${{ github.workspace }}/conan-cache"
jobs:
# ============================================================================
# YAML Validation
# ============================================================================
yaml-validation:
name: "YAML Validation"
runs-on: ubuntu-latest
if: contains(github.event.head_commit.modified, '.yml') || contains(github.event.head_commit.added, '.yml') || contains(github.event.head_commit.modified, '.yaml') || contains(github.event.head_commit.added, '.yaml')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install YAML validation tools
run: |
pip install pyyaml yamllint
- name: Find changed YAML files
id: changed-files
run: |
# Get list of changed YAML files
if [ "${{ github.event_name }}" = "pull_request" ]; then
# For PRs, compare with base branch
git fetch origin ${{ github.base_ref }}
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.(yml|yaml)$' || true)
else
# For pushes, use the commit range
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }}..${{ github.sha }} | grep -E '\.(yml|yaml)$' || true)
fi
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
if [ -n "$CHANGED_FILES" ]; then
echo "Found changed YAML files:"
echo "$CHANGED_FILES"
else
echo "No YAML files changed"
fi
- name: Validate YAML syntax
if: steps.changed-files.outputs.changed_files != ''
run: |
echo "Validating YAML syntax for changed files..."
echo "${{ steps.changed-files.outputs.changed_files }}" | while IFS= read -r file; do
if [ -n "$file" ] && [ -f "$file" ]; then
echo "🔍 Validating: $file"
# Basic Python YAML syntax check
python -c "import yaml; yaml.safe_load(open('$file', 'r'))" || {
echo "❌ YAML syntax error in: $file"
exit 1
}
echo "✅ Valid YAML syntax: $file"
fi
done
- name: Lint YAML files with yamllint
if: steps.changed-files.outputs.changed_files != ''
run: |
echo "Running yamllint on changed files..."
# Create yamllint config for GitHub Actions workflows
cat > .yamllint.yml << 'EOF'
extends: default
rules:
line-length:
max: 120
indentation:
spaces: 2
truthy:
allowed-values: ['true', 'false']
check-keys: false
comments:
min-spaces-from-content: 1
EOF
echo "${{ steps.changed-files.outputs.changed_files }}" | while IFS= read -r file; do
if [ -n "$file" ] && [ -f "$file" ]; then
echo "🔍 Linting: $file"
yamllint -c .yamllint.yml "$file" || {
echo "❌ YAML linting failed for: $file"
exit 1
}
echo "✅ YAML linting passed: $file"
fi
done
- name: Validate GitHub Actions workflow syntax
if: steps.changed-files.outputs.changed_files != ''
run: |
echo "Validating GitHub Actions workflow syntax..."
echo "${{ steps.changed-files.outputs.changed_files }}" | while IFS= read -r file; do
if [ -n "$file" ] && [ -f "$file" ] && [[ "$file" == .github/workflows/* ]]; then
echo "🔍 Validating GitHub Actions workflow: $file"
# Check for required fields in GitHub Actions workflows
python << 'PYEOF'
import yaml
import sys
try:
with open("$file", 'r') as f:
workflow = yaml.safe_load(f)
# Check required fields for GitHub Actions workflows
if 'name' not in workflow:
print(f"❌ Missing 'name' field in workflow: $file")
sys.exit(1)
if 'on' not in workflow:
print(f"❌ Missing 'on' field in workflow: $file")
sys.exit(1)
if 'jobs' not in workflow:
print(f"❌ Missing 'jobs' field in workflow: $file")
sys.exit(1)
# Validate each job has required fields
for job_name, job_config in workflow['jobs'].items():
if not isinstance(job_config, dict):
print(f"❌ Job '{job_name}' must be a dictionary in: $file")
sys.exit(1)
if 'runs-on' not in job_config:
print(f"❌ Job '{job_name}' missing 'runs-on' field in: $file")
sys.exit(1)
print(f"✅ Valid GitHub Actions workflow: $file")
except Exception as e:
print(f"❌ Error validating workflow {file}: {e}")
sys.exit(1)
PYEOF
fi
done
# ============================================================================
# Linux x64 - GCC 13
# ============================================================================
linux-gcc:
name: "Linux GCC 13 (x64)"
runs-on: ubuntu-24.04
needs: [yaml-validation]
if: always() && (needs.yaml-validation.result == 'success' || needs.yaml-validation.result == 'skipped')
strategy:
matrix:
build_type: [Debug, Release]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt update
sudo apt install -y cmake python3-pip git clang-format
# Install exact GCC version 13.3.0 to match local development environment
sudo apt install -y gcc-13 g++-13
# Set up alternatives to ensure we use GCC 13
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Conan
run: |
pip3 install --user conan
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup Conan profile
run: |
conan profile detect --force
# Use static profile for GCC 13 with C++23
sed -i 's/compiler=.*/compiler=gcc/' ~/.conan2/profiles/default
sed -i 's/compiler.version=.*/compiler.version=13/' ~/.conan2/profiles/default
sed -i 's/compiler.libcxx=.*/compiler.libcxx=libstdc++11/' ~/.conan2/profiles/default
sed -i 's/compiler.cppstd=.*/compiler.cppstd=23/' ~/.conan2/profiles/default
sed -i 's/os=.*/os=Linux/' ~/.conan2/profiles/default
sed -i 's/arch=.*/arch=x86_64/' ~/.conan2/profiles/default
echo "=== Conan Profile ==="
conan profile show --profile:host=default
- name: Cache Conan packages
uses: actions/cache@v4
with:
path: ~/.conan2
key: conan-linux-gcc-${{ matrix.build_type }}-${{ hashFiles('conanfile.py') }}
restore-keys: |
conan-linux-gcc-${{ matrix.build_type }}-
conan-linux-gcc-
- name: Install dependencies
run: |
export CC=gcc
export CXX=g++
conan install . -s os=Linux -s build_type=${{ matrix.build_type }} --output-folder=build --build=missing -o with_gperftools=True
- name: Configure CMake
run: |
export CC=gcc
export CXX=g++
if [[ "${{ matrix.build_type }}" == "Debug" ]]; then
cmake --preset conan-debug \
-DCOMPILER_TYPE=GCC \
-DUSE_LTO=ON \
-DUSE_NATIVE_ARCH=ON \
-DENABLE_SHARED_LIBRARY=ON
else
cmake --preset conan-release \
-DCOMPILER_TYPE=GCC \
-DUSE_LTO=ON \
-DUSE_NATIVE_ARCH=ON \
-DENABLE_SHARED_LIBRARY=ON
fi
- name: Build
run: |
if [[ "${{ matrix.build_type }}" == "Debug" ]]; then
cmake --build --preset conan-debug --parallel
else
cmake --build --preset conan-release --parallel
fi
- name: Test
run: |
# Both Debug and Release builds use build/build directory with Conan presets
cd build/build
if [[ "${{ matrix.build_type }}" == "Debug" ]]; then
./utf_strings-tests --gtest_output=xml:test_results_gcc_debug.xml
else
./utf_strings-tests --gtest_output=xml:test_results_gcc_release.xml
fi
- name: Benchmark (Release only)
if: matrix.build_type == 'Release'
run: |
cd build/build
./utf_strings-bench --benchmark_min_time=0.1s --benchmark_format=json --benchmark_out=benchmark_results_gcc.json
- name: Check code formatting (Release only)
if: matrix.build_type == 'Release'
run: cmake --build --preset conan-release --target format-check
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-linux-gcc-${{ matrix.build_type }}
path: |
build/build/test_results_gcc_debug.xml
build/build/test_results_gcc_release.xml
build/build/benchmark_results_gcc.json
# ============================================================================
# Linux x64 - Clang 18
# ============================================================================
linux-clang:
name: "Linux Clang 18 (x64)"
runs-on: ubuntu-24.04
needs: [yaml-validation]
if: always() && (needs.yaml-validation.result == 'success' || needs.yaml-validation.result == 'skipped')
strategy:
matrix:
build_type: [Debug, Release]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install system dependencies
timeout-minutes: 15
run: |
set -e # Exit on any error
# Update package list first
sudo apt update
# Install basic dependencies first (these are fast and reliable)
sudo apt install -y cmake python3-pip git wget curl
# Install Clang 18 with timeout and retry logic
echo "Installing Clang 18..."
for i in {1..3}; do
if timeout 10m bash -c "
wget -q https://apt.llvm.org/llvm.sh &&
chmod +x llvm.sh &&
sudo ./llvm.sh 18
"; then
echo "LLVM installation successful on attempt $i"
break
else
echo "LLVM installation attempt $i failed, retrying..."
rm -f llvm.sh
if [ $i -eq 3 ]; then
echo "All LLVM installation attempts failed"
exit 1
fi
sleep 30
fi
done
# Install additional tools
sudo apt install -y clang-format-18 || {
echo "clang-format-18 not available, trying alternatives..."
sudo apt install -y clang-format || echo "clang-format installation failed"
}
# Set up symlinks
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++
if command -v clang-format-18 >/dev/null 2>&1; then
sudo ln -sf /usr/bin/clang-format-18 /usr/bin/clang-format
fi
# Verify installation
clang --version
clang++ --version
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Conan
run: |
pip3 install --user conan
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup Conan profile
run: |
conan profile detect --force
# Use static profile for Clang 18 with C++23
sed -i 's/compiler=.*/compiler=clang/' ~/.conan2/profiles/default
sed -i 's/compiler.version=.*/compiler.version=18/' ~/.conan2/profiles/default
sed -i 's/compiler.libcxx=.*/compiler.libcxx=libstdc++11/' ~/.conan2/profiles/default
sed -i 's/compiler.cppstd=.*/compiler.cppstd=23/' ~/.conan2/profiles/default
sed -i 's/os=.*/os=Linux/' ~/.conan2/profiles/default
sed -i 's/arch=.*/arch=x86_64/' ~/.conan2/profiles/default
echo "=== Conan Profile ==="
conan profile show --profile:host=default
- name: Cache Conan packages
uses: actions/cache@v4
with:
path: ~/.conan2
key: conan-linux-clang-${{ matrix.build_type }}-${{ hashFiles('conanfile.py') }}
restore-keys: |
conan-linux-clang-${{ matrix.build_type }}-
conan-linux-clang-
- name: Install dependencies
run: |
export CC=clang
export CXX=clang++
conan install . -s os=Linux -s build_type=${{ matrix.build_type }} --output-folder=build --build=missing -o with_gperftools=True
- name: Configure CMake
run: |
export CC=clang
export CXX=clang++
if [[ "${{ matrix.build_type }}" == "Debug" ]]; then
cmake --preset conan-debug \
-DCOMPILER_TYPE=CLANG \
-DUSE_LTO=ON \
-DUSE_NATIVE_ARCH=ON \
-DUSE_LIBC_PLUS_PLUS=OFF \
-DENABLE_SHARED_LIBRARY=ON
else
cmake --preset conan-release \
-DCOMPILER_TYPE=CLANG \
-DUSE_LTO=ON \
-DUSE_NATIVE_ARCH=ON \
-DUSE_LIBC_PLUS_PLUS=OFF \
-DENABLE_SHARED_LIBRARY=ON
fi
- name: Build
run: |
if [[ "${{ matrix.build_type }}" == "Debug" ]]; then
cmake --build --preset conan-debug --parallel
else
cmake --build --preset conan-release --parallel
fi
- name: Test
run: |
# Both Debug and Release builds use build/build directory with Conan presets
cd build/build
if [[ "${{ matrix.build_type }}" == "Debug" ]]; then
./utf_strings-tests --gtest_output=xml:test_results_clang_debug.xml
else
./utf_strings-tests --gtest_output=xml:test_results_clang_release.xml
fi
- name: Benchmark (Release only)
if: matrix.build_type == 'Release'
run: |
cd build/build
./utf_strings-bench --benchmark_min_time=0.1s --benchmark_format=json --benchmark_out=benchmark_results_clang.json
- name: Check code formatting (Release only)
if: matrix.build_type == 'Release'
run: cmake --build --preset conan-release --target format-check
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-linux-clang-${{ matrix.build_type }}
path: |
build/build/test_results_clang_debug.xml
build/build/test_results_clang_release.xml
build/build/benchmark_results_clang.json
# ============================================================================
# Linux x64 - Clang Debug with Code Coverage
# ============================================================================
linux-clang-coverage:
name: "Linux Clang Code Coverage (x64)"
runs-on: ubuntu-24.04
needs: [yaml-validation]
if: always() && (needs.yaml-validation.result == 'success' || needs.yaml-validation.result == 'skipped')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install system dependencies
timeout-minutes: 15
run: |
set -e # Exit on any error
# Update package list first
sudo apt update
# Install basic dependencies first (these are fast and reliable)
sudo apt install -y cmake python3-pip git wget curl bc
# Install Clang 18 with timeout and retry logic
echo "Installing Clang 18..."
for i in {1..3}; do
if timeout 10m bash -c "
wget -q https://apt.llvm.org/llvm.sh &&
chmod +x llvm.sh &&
sudo ./llvm.sh 18
"; then
echo "LLVM installation successful on attempt $i"
break
else
echo "LLVM installation attempt $i failed, retrying..."
rm -f llvm.sh
if [ $i -eq 3 ]; then
echo "All LLVM installation attempts failed"
exit 1
fi
sleep 30
fi
done
# Install code coverage tools
sudo apt install -y llvm-18 llvm-18-dev clang-format-18 || {
echo "Some LLVM tools not available, trying alternatives..."
sudo apt install -y llvm llvm-dev clang-format || echo "Some tools installation failed"
}
# Set up symlinks
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++
sudo ln -sf /usr/bin/llvm-profdata-18 /usr/bin/llvm-profdata || sudo ln -sf /usr/bin/llvm-profdata /usr/bin/llvm-profdata
sudo ln -sf /usr/bin/llvm-cov-18 /usr/bin/llvm-cov || sudo ln -sf /usr/bin/llvm-cov /usr/bin/llvm-cov
if command -v clang-format-18 >/dev/null 2>&1; then
sudo ln -sf /usr/bin/clang-format-18 /usr/bin/clang-format
fi
# Verify installation
clang --version
clang++ --version
llvm-profdata-18 --version || echo "llvm-profdata not available"
llvm-cov-18 --version || echo "llvm-cov not available"
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Conan
run: |
pip3 install --user conan
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup Conan profile
run: |
conan profile detect --force
# Use static profile for Clang 18 with C++23 (code coverage)
sed -i 's/compiler=.*/compiler=clang/' ~/.conan2/profiles/default
sed -i 's/compiler.version=.*/compiler.version=18/' ~/.conan2/profiles/default
sed -i 's/compiler.libcxx=.*/compiler.libcxx=libstdc++11/' ~/.conan2/profiles/default
sed -i 's/compiler.cppstd=.*/compiler.cppstd=23/' ~/.conan2/profiles/default
sed -i 's/os=.*/os=Linux/' ~/.conan2/profiles/default
sed -i 's/arch=.*/arch=x86_64/' ~/.conan2/profiles/default
echo "=== Conan Profile ==="
conan profile show --profile:host=default
- name: Cache Conan packages
uses: actions/cache@v4
with:
path: ~/.conan2
key: conan-linux-clang-coverage-${{ hashFiles('conanfile.py') }}
restore-keys: |
conan-linux-clang-coverage-
conan-linux-clang-
- name: Install dependencies
run: |
export CC=clang
export CXX=clang++
conan install . -s os=Linux -s build_type=Debug --output-folder=build --build=missing -o with_gperftools=True
- name: Configure CMake with Coverage
run: |
export CC=clang
export CXX=clang++
cmake -S . -B build/Coverage \
-DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang \
-DCOMPILER_TYPE=CLANG \
-DUSE_LTO=OFF \
-DUSE_NATIVE_ARCH=OFF \
-DENABLE_SHARED_LIBRARY=ON \
-DUTF_STRINGS_BUILD_TESTS=ON \
-DUTF_STRINGS_BUILD_BENCHMARKS=OFF \
-DUTF_STRINGS_BUILD_FUZZ_TESTS=OFF \
-DUTF_STRINGS_WITH_GPERFTOOLS=OFF \
-DCMAKE_CXX_FLAGS="--coverage -fprofile-instr-generate -fcoverage-mapping" \
-DCMAKE_C_FLAGS="--coverage -fprofile-instr-generate -fcoverage-mapping" \
-DCMAKE_EXE_LINKER_FLAGS="--coverage"
- name: Build with Coverage
run: cmake --build build/Coverage --parallel
- name: Run Tests with Coverage
run: |
cd build/Coverage
# Set up coverage data collection
export LLVM_PROFILE_FILE="utf_strings_coverage.profraw"
# Run the tests
./utf_strings-tests --gtest_output=xml:test_results_coverage.xml
# Verify coverage data was generated
ls -la *.profraw || echo "No .profraw files found"
- name: Process Coverage Data
run: |
cd build/Coverage
# Convert raw profile data to indexed format
if [ -f "utf_strings_coverage.profraw" ]; then
echo "Converting coverage data..."
# Try versioned commands first, fall back to unversioned
if command -v llvm-profdata-18 >/dev/null 2>&1; then
LLVM_PROFDATA=llvm-profdata-18
LLVM_COV=llvm-cov-18
else
LLVM_PROFDATA=llvm-profdata
LLVM_COV=llvm-cov
fi
$LLVM_PROFDATA merge -sparse utf_strings_coverage.profraw -o utf_strings_coverage.profdata
# Generate coverage report in text format
echo "Generating text coverage report..."
$LLVM_COV report ./utf_strings-tests \
-instr-profile=utf_strings_coverage.profdata \
-ignore-filename-regex="(test|gtest|benchmark|conan|build)" \
> coverage_report.txt
# Generate detailed coverage report in HTML format
echo "Generating HTML coverage report..."
$LLVM_COV show ./utf_strings-tests \
-instr-profile=utf_strings_coverage.profdata \
-format=html \
-output-dir=coverage_html \
-ignore-filename-regex="(test|gtest|benchmark|conan|build)" \
-show-line-counts-or-regions \
-show-instantiations
# Generate coverage summary in JSON format
echo "Generating JSON coverage summary..."
$LLVM_COV export ./utf_strings-tests \
-instr-profile=utf_strings_coverage.profdata \
-format=text \
-ignore-filename-regex="(test|gtest|benchmark|conan|build)" \
> coverage_summary.json
# Display coverage summary
echo "=== Coverage Summary ==="
cat coverage_report.txt
echo "========================"
else
echo "❌ No coverage data found!"
echo "Available files:"
ls -la
exit 1
fi
- name: Generate Coverage Badge Data
run: |
cd build/Coverage
if [ -f "coverage_summary.json" ]; then
# Extract coverage percentage from JSON report
COVERAGE=$(python3 -c "
import json
import sys
try:
with open('coverage_summary.json', 'r') as f:
data = json.load(f)
# Extract totals from llvm-cov JSON format
totals = data['data'][0]['totals']
lines = totals['lines']
covered = lines['covered']
count = lines['count']
if count > 0:
percentage = round((covered / count) * 100, 1)
print(f'{percentage}')
else:
print('0.0')
except Exception as e:
print(f'Error: {e}', file=sys.stderr)
print('0.0')
")
echo "COVERAGE_PERCENTAGE=$COVERAGE" >> $GITHUB_ENV
echo "Coverage: $COVERAGE%"
# Create badge color based on coverage percentage
if (( $(echo "$COVERAGE >= 90" | bc -l) )); then
BADGE_COLOR="brightgreen"
elif (( $(echo "$COVERAGE >= 80" | bc -l) )); then
BADGE_COLOR="green"
elif (( $(echo "$COVERAGE >= 70" | bc -l) )); then
BADGE_COLOR="yellowgreen"
elif (( $(echo "$COVERAGE >= 60" | bc -l) )); then
BADGE_COLOR="yellow"
elif (( $(echo "$COVERAGE >= 50" | bc -l) )); then
BADGE_COLOR="orange"
else
BADGE_COLOR="red"
fi
echo "BADGE_COLOR=$BADGE_COLOR" >> $GITHUB_ENV
# Create a simple coverage summary for artifact
cat > coverage_summary.txt << EOF
UTF Strings Library - Code Coverage Report
==========================================
Generated: $(date)
Build: Clang Debug with Coverage
Test Suite: All unit tests
Coverage: $COVERAGE%
Badge Color: $BADGE_COLOR
Detailed reports available in coverage_html/ directory
EOF
else
echo "COVERAGE_PERCENTAGE=0.0" >> $GITHUB_ENV
echo "BADGE_COLOR=red" >> $GITHUB_ENV
fi
- name: Upload Coverage Reports
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-reports-linux-clang
path: |
build/Coverage/coverage_report.txt
build/Coverage/coverage_summary.json
build/Coverage/coverage_summary.txt
build/Coverage/coverage_html/
build/Coverage/test_results_coverage.xml
retention-days: 30
- name: Upload Coverage to Codecov (Optional)
uses: codecov/codecov-action@v3
if: always()
with:
files: build/Coverage/coverage_summary.json
flags: unittests
name: utf-strings-coverage
fail_ci_if_error: false
verbose: true
- name: Comment Coverage on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const coverage = process.env.COVERAGE_PERCENTAGE;
const badgeColor = process.env.BADGE_COLOR;
const comment = `## 📊 Code Coverage Report
**Coverage:** ${coverage}%

<details>
<summary>📋 Coverage Details</summary>
- **Build:** Clang Debug with Coverage Instrumentation
- **Test Suite:** All unit tests (65 tests across 22 test suites)
- **Generated:** ${new Date().toISOString()}
📁 **Artifacts Generated:**
- 📄 Text report: \`coverage_report.txt\`
- 🌐 HTML report: \`coverage_html/index.html\`
- 📊 JSON summary: \`coverage_summary.json\`
- ✅ Test results: \`test_results_coverage.xml\`
</details>
> 💡 **Tip:** Download the coverage artifacts to view detailed line-by-line coverage reports.`;
try {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
console.log('✅ Coverage comment posted successfully');
} catch (error) {
console.log('❌ Failed to post coverage comment:', error.message);
console.log('This is likely due to insufficient permissions or the PR being from a fork');
}
# ============================================================================
# Linux x64 - Clang with Fuzz Testing
# ============================================================================
linux-clang-fuzz:
name: "Linux Clang Fuzz Testing (x64)"
runs-on: ubuntu-24.04
needs: [yaml-validation]
if: always() && (needs.yaml-validation.result == 'success' || needs.yaml-validation.result == 'skipped')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install system dependencies
timeout-minutes: 15
run: |
set -e # Exit on any error
# Update package list first
sudo apt update
# Install basic dependencies first (these are fast and reliable)
sudo apt install -y cmake python3-pip git wget curl
# Install Clang 18 with timeout and retry logic
echo "Installing Clang 18..."
for i in {1..3}; do
if timeout 10m bash -c "
wget -q https://apt.llvm.org/llvm.sh &&
chmod +x llvm.sh &&
sudo ./llvm.sh 18
"; then
echo "LLVM installation successful on attempt $i"
break
else
echo "LLVM installation attempt $i failed, retrying..."
rm -f llvm.sh
if [ $i -eq 3 ]; then
echo "All LLVM installation attempts failed"
exit 1
fi
sleep 30
fi
done
# Install additional tools
sudo apt install -y clang-format-18 || {
echo "clang-format-18 not available, trying alternatives..."
sudo apt install -y clang-format || echo "clang-format installation failed"
}
# Set up symlinks
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++
if command -v clang-format-18 >/dev/null 2>&1; then
sudo ln -sf /usr/bin/clang-format-18 /usr/bin/clang-format
fi
# Verify installation
clang --version
clang++ --version
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Conan
run: |
pip3 install --user conan
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup Conan profile
run: |
conan profile detect --force
# Use static profile for Clang 18 with C++23 (fuzz testing)
sed -i 's/compiler=.*/compiler=clang/' ~/.conan2/profiles/default
sed -i 's/compiler.version=.*/compiler.version=18/' ~/.conan2/profiles/default
sed -i 's/compiler.libcxx=.*/compiler.libcxx=libstdc++11/' ~/.conan2/profiles/default
sed -i 's/compiler.cppstd=.*/compiler.cppstd=23/' ~/.conan2/profiles/default
sed -i 's/os=.*/os=Linux/' ~/.conan2/profiles/default
sed -i 's/arch=.*/arch=x86_64/' ~/.conan2/profiles/default
echo "=== Conan Profile ==="
conan profile show --profile:host=default
- name: Cache Conan packages
uses: actions/cache@v4
with:
path: ~/.conan2
key: conan-linux-clang-fuzz-${{ hashFiles('conanfile.py') }}
restore-keys: |
conan-linux-clang-fuzz-
conan-linux-clang-
- name: Install dependencies
run: |
export CC=clang
export CXX=clang++
conan install . -s os=Linux -s build_type=Debug --output-folder=build --build=missing -o with_gperftools=True
- name: Configure CMake with Fuzz Testing
run: |
export CC=clang
export CXX=clang++
cmake -S . -B build/Fuzz \
-DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_COMPILER=clang++ \
-DCOMPILER_TYPE=CLANG \
-DUSE_LTO=OFF \
-DUSE_NATIVE_ARCH=OFF \
-DENABLE_SHARED_LIBRARY=OFF \
-DUTF_STRINGS_BUILD_TESTS=OFF \
-DUTF_STRINGS_BUILD_BENCHMARKS=OFF \
-DUTF_STRINGS_BUILD_FUZZ_TESTS=ON \
-DUTF_STRINGS_WITH_GPERFTOOLS=OFF
- name: Build Fuzz Targets
run: cmake --build build/Fuzz --parallel
- name: Run Fuzz Tests (Short Duration for CI)
run: |
cd build/Fuzz
echo "Running UTF-8 fuzz tests..."
timeout 60s ./fuzz_utf8 -max_total_time=30 -print_final_stats=1 || true
echo "Running UTF-16 BE fuzz tests..."
timeout 60s ./fuzz_utf16_be -max_total_time=30 -print_final_stats=1 || true
echo "Running UTF-16 LE fuzz tests..."
timeout 60s ./fuzz_utf16_le -max_total_time=30 -print_final_stats=1 || true
echo "Running UTF-32 BE fuzz tests..."
timeout 60s ./fuzz_utf32_be -max_total_time=30 -print_final_stats=1 || true
echo "Running UTF-32 LE fuzz tests..."
timeout 60s ./fuzz_utf32_le -max_total_time=30 -print_final_stats=1 || true
- name: Upload fuzz artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: fuzz-results-linux-clang
path: |
build/Fuzz/*.log
build/Fuzz/crash-*
build/Fuzz/leak-*
build/Fuzz/timeout-*
# ============================================================================
# Linux x64 - Sanitizer Testing (GCC & Clang)
# ============================================================================
linux-sanitizers:
name: "Linux Sanitizer Testing (x64)"
runs-on: ubuntu-24.04
needs: [yaml-validation]
if: always() && (needs.yaml-validation.result == 'success' || needs.yaml-validation.result == 'skipped')
strategy:
matrix:
sanitizer: [asan, tsan]
compiler: [clang]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install system dependencies
timeout-minutes: 15
run: |
set -e # Exit on any error
# Update package list first
sudo apt update
# Install basic dependencies first
sudo apt install -y cmake python3-pip git wget curl
# Install Clang 18 with retry logic (sanitizers use Clang only)
echo "Installing Clang 18..."
for i in {1..3}; do
if timeout 10m bash -c "
wget -q https://apt.llvm.org/llvm.sh &&
chmod +x llvm.sh &&
sudo ./llvm.sh 18
"; then
echo "LLVM installation successful on attempt $i"
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++
break
else
echo "LLVM installation attempt $i failed, retrying..."
rm -f llvm.sh
if [ $i -eq 3 ]; then
echo "All LLVM installation attempts failed"
exit 1
fi
sleep 30
fi
done
# Verify Clang installation
clang --version
clang++ --version
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Conan
run: |
pip3 install --user conan
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup Conan profile
run: |
conan profile detect --force
# Use static profile for Clang 18 with C++23 (sanitizers use Clang only)
sed -i 's/compiler=.*/compiler=clang/' ~/.conan2/profiles/default
sed -i 's/compiler.version=.*/compiler.version=18/' ~/.conan2/profiles/default
sed -i 's/compiler.libcxx=.*/compiler.libcxx=libstdc++11/' ~/.conan2/profiles/default
sed -i 's/compiler.cppstd=.*/compiler.cppstd=23/' ~/.conan2/profiles/default
sed -i 's/os=.*/os=Linux/' ~/.conan2/profiles/default
sed -i 's/arch=.*/arch=x86_64/' ~/.conan2/profiles/default
echo "=== Conan Profile ==="
conan profile show --profile:host=default