-
Notifications
You must be signed in to change notification settings - Fork 9
1114 lines (964 loc) · 42.6 KB
/
php.yml
File metadata and controls
1114 lines (964 loc) · 42.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: PHP CI
on:
push:
branches:
- main
- release-*
- v*
paths:
- valkey-glide/glide-core/src/**
- valkey-glide/glide-core/redis-rs/redis/src/**
- valkey-glide/ffi/src/**
- valkey-glide/utils/cluster_manager.py
- .github/workflows/php.yml
- .github/workflows/install-shared-dependencies/action.yml
- .github/workflows/build-php-wrapper/action.yml
- .github/workflows/test-benchmark/action.yml
- .github/workflows/install-engine/action.yml
- .github/workflows/create-test-matrices/action.yml
- .github/json_matrices/**
pull_request:
paths:
- valkey-glide/glide-core/src/**
- valkey-glide/glide-core/redis-rs/redis/src/**
- valkey-glide/ffi/src/**
- valkey-glide/utils/cluster_manager.py
- .github/workflows/php.yml
- .github/workflows/install-shared-dependencies/action.yml
- .github/workflows/build-php-wrapper/action.yml
- .github/workflows/test-benchmark/action.yml
- .github/workflows/install-engine/action.yml
- .github/workflows/create-test-matrices/action.yml
- .github/json_matrices/**
# PHP-specific paths
- "*.c"
- "*.h"
- "*.php"
- "*.stub.php"
- tests/**
- examples/**
- composer.json
- composer.lock
- config.m4
- Makefile.frag
- phpcs.xml
- phpstan.neon
- include/**
- src/**
workflow_dispatch:
inputs:
full-matrix:
description: "Run the full engine, host, and language version matrix"
type: boolean
default: false
name:
required: false
type: string
description: "(Optional) Test run name"
run-modules-tests:
description: "Run modules tests"
type: boolean
default: false
workflow_call:
concurrency:
group: php-${{ github.head_ref || github.ref }}-${{ toJson(inputs) }}
cancel-in-progress: true
run-name:
# Set custom name if job is started manually and name is given
${{ github.event_name == 'workflow_dispatch' && (inputs.name == '' && format('{0} @ {1} {2}', github.ref_name, github.sha, toJson(inputs)) || inputs.name) || '' }}
env:
CARGO_TERM_COLOR: always
BASE_PHP_VERSION: "8.2"
jobs:
get-matrices:
runs-on: ubuntu-latest
outputs:
engine-matrix-output: ${{ steps.get-matrices.outputs.engine-matrix-output }}
host-matrix-output: ${{ steps.get-matrices.outputs.host-matrix-output }}
version-matrix-output: ${{ steps.get-matrices.outputs.version-matrix-output }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- id: get-matrices
uses: ./.github/workflows/create-test-matrices
with:
language-name: php
# Run full test matrix if job started by cron or it was explictly specified by a person who triggered the workflow
run-full-matrix: ${{ github.event.inputs.full-matrix == 'true' || github.event_name == 'schedule' }}
test-php:
name: PHP Tests - ${{ matrix.php }}, EngineVersion - ${{ matrix.engine.version }}, Target - ${{ matrix.host.TARGET }}
needs: get-matrices
timeout-minutes: 35
strategy:
fail-fast: false
matrix:
php: ${{ fromJson(needs.get-matrices.outputs.version-matrix-output) }}
engine: ${{ fromJson(needs.get-matrices.outputs.engine-matrix-output) }}
host: ${{ fromJson(needs.get-matrices.outputs.host-matrix-output) }}
runs-on: ${{ matrix.host.RUNNER }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Output Matrix Parameters for this job
run: |
echo "Job running with the following matrix configuration:"
echo "${{ toJson(matrix) }}"
- name: Build PHP wrapper
uses: ./.github/workflows/build-php-wrapper
with:
os: ${{ matrix.host.OS }}
target: ${{ matrix.host.TARGET }}
php-version: ${{ matrix.php }}
github-token: ${{ secrets.GITHUB_TOKEN }}
engine-version: ${{ matrix.engine.version }}
- name: Generate test protobuf PHP classes
run: |
protoc --proto_path=./valkey-glide/glide-core/src/protobuf --php_out=./tests/ ./valkey-glide/glide-core/src/protobuf/connection_request.proto
echo "tests directory contents:"
cd tests
ls -la
- name: Install PHP dependencies
run: |
composer install --no-interaction --prefer-dist --optimize-autoloader
echo "Composer install completed. Checking for composer.lock:"
ls -la composer.lock || echo "Warning: composer.lock not found"
echo "Current directory contents:"
ls -la
- name: Run PHP Extension Tests
uses: ./.github/workflows/run-php-tests
with:
extension-path: ${{ github.workspace }}/modules/valkey_glide.so
php-version: ${{ matrix.php }}
- uses: ./.github/workflows/test-benchmark
if: ${{ matrix.engine.version == '8.0' && matrix.host.OS == 'ubuntu' && matrix.host.RUNNER == 'ubuntu-latest' && matrix.php == env.BASE_PHP_VERSION }}
with:
language-flag: -php
- name: Upload logs and reports
if: always()
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: test-report-php-${{ matrix.php }}-${{ matrix.engine.type }}-${{ matrix.engine.version }}-${{ matrix.host.RUNNER }}
path: |
utils/clusters/**
benchmarks/results/**
tests/**/*.diff
tests/**/*.exp
tests/**/*.log
tests/**/*.out
test-php-asan:
name: PHP ASAN Tests - EngineVersion ${{ matrix.engine.version }} (macOS)
if: false # Temporarily disabled
needs: get-matrices
runs-on: macos-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
engine: ${{ fromJson(needs.get-matrices.outputs.engine-matrix-output) }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Output Matrix Parameters for this job
run: |
echo "Job running with the following matrix configuration:"
echo "${{ toJson(matrix) }}"
- uses: actions/cache@v5
with:
path: |
valkey-glide/ffi/target
valkey-glide/glide-core/src/generated
include/
src/*.pb-c.c
src/*.pb-c.h
key: macos-latest-php-asan-${{ env.BASE_PHP_VERSION }}
restore-keys: |
macos-latest-php-asan
macos-latest-php
macos-latest-glide-core
macos-latest
- name: Install shared dependencies
uses: ./.github/workflows/install-shared-dependencies
with:
os: ${{ inputs.os }}
target: x86_64-apple-darwin
github-token: ${{ secrets.GITHUB_TOKEN }}
engine-version: ${{ matrix.engine.version }}
- name: Install Rust and protoc
uses: ./.github/workflows/install-rust-and-protoc
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install cbindgen
run: |
if [ -f "$HOME/.cargo/bin/cbindgen" ]; then
echo "cbindgen already installed (cached)"
else
cargo install cbindgen
fi
- uses: Swatinem/rust-cache@v2
with:
workspaces: |
valkey-glide/ffi
valkey-glide/glide-core
key: asan
- name: Pre-build Rust components
run: |
echo "=== Pre-building Rust components for make ==="
cd valkey-glide/ffi
cargo build --release
echo "Rust pre-build completed"
- name: Build FFI library
working-directory: valkey-glide/ffi
run: cargo build --release
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.BASE_PHP_VERSION }}
extensions: none
tools: none
- name: Install system dependencies for PHP ASAN build
run: |
# Install required tools via Homebrew
brew install autoconf automake libtool pkg-config protobuf-c
export DYLD_LIBRARY_PATH="/opt/homebrew/lib:$DYLD_LIBRARY_PATH"
export PATH="/opt/homebrew/bin:$PATH"
# Ensure Xcode Command Line Tools are installed (required for ASAN)
xcode-select --install || echo "Xcode Command Line Tools already installed"
- name: Install protobuf-c
run: brew install protobuf-c
- name: Export DYLD_LIBRARY_PATH
run: echo "DYLD_LIBRARY_PATH=$(brew --prefix protobuf-c)/lib" >> $GITHUB_ENV
- name: Start Valkey servers
working-directory: tests
run: |
set -e # Exit on any error
# Ensure /usr/local/bin is in PATH (where valkey-server is installed)
export PATH="/usr/local/bin:$PATH"
echo "=== Starting Valkey servers for ASAN testing ==="
# Make scripts executable
chmod +x start_valkey_with_replicas.sh create-valkey-cluster.sh
# Start standalone servers (6379, 6380, 6381)
echo "=== Starting standalone Valkey servers ==="
./start_valkey_with_replicas.sh
# Wait a moment for servers to start
echo "=== Waiting for standalone servers to start ==="
sleep 3
# Start cluster servers (7001-7006)
echo "=== Starting Valkey cluster ==="
./create-valkey-cluster.sh
# Final server status check
echo "=== Final server status check ==="
ps aux | grep -E "(valkey|redis)-server" | grep -v grep || echo "No valkey/redis-server processes found"
echo "=== Valkey servers startup completed ==="
- name: Setup and run ASAN tests
run: |
echo "=== Setting up PHP extension build system and running ASAN tests ==="
# Step 1: Clean any existing files (manual cleanup since Makefile may not exist)
echo "=== Step 1: Cleaning previous builds ==="
rm -rf ./modules/ ./libs/ ./.libs/ ./tmp-php.ini ./asan_logs/
find . -name "*.lo" -o -name "*.o" -o -name "*.la" | xargs rm -f 2>/dev/null || true
# Step 2: Initialize PHP extension build system
echo "=== Step 2: Initializing PHP extension build system ==="
phpize
# Step 3: Configure with ASAN flags - this generates Makefile with ASAN targets
echo "=== Step 3: Configuring with ASAN flags ==="
./configure --enable-valkey-glide --enable-valkey-glide-asan
# Step 4: Now we can use make clean safely
echo "=== Step 4: Clean using make (now that Makefile exists) ==="
make clean || true
# Step 5: Build and test with AddressSanitizer
echo "=== Step 5: Building and testing with AddressSanitizer ==="
# Create clean log directory
mkdir -p ./asan_logs
otool -L modules/valkey_glide.so
nm -g modules/valkey_glide.so | grep protobuf_c_empty_string
# Run ASAN tests with visible error output
echo "=== Running make test-asan ==="
make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo "4") test-asan
- name: Display ASAN logs if found
if: always()
run: |
if [ -d "./asan_logs" ] && [ "$(ls -A ./asan_logs 2>/dev/null)" ]; then
echo "=== ASAN Reports Found ==="
for log_file in ./asan_logs/*; do
if [ -f "$log_file" ]; then
echo "=== Contents of $log_file ==="
cat "$log_file"
echo "=== End of $log_file ==="
fi
done
else
echo "✓ No ASAN issues detected"
fi
- name: Stop Valkey servers
if: always()
run: |
# Stop all Valkey server processes
echo "Stopping Valkey servers..."
pkill valkey-server || true
# Clean up data directories
rm -rf $HOME/valkey-cluster || true
rm -rf tests/valkey_data || true
- name: Upload ASAN logs and reports
if: always()
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: asan-test-report-php-${{ matrix.engine.type }}-${{ matrix.engine.version }}
path: |
utils/clusters/**
asan_logs/**
tests/**/*.diff
tests/**/*.exp
tests/**/*.log
tests/**/*.out
test-php-valgrind:
name: PHP Valgrind Tests - EngineVersion ${{ matrix.engine.version }} (Ubuntu)
needs: get-matrices
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
engine: ${{ fromJson(needs.get-matrices.outputs.engine-matrix-output) }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Output Matrix Parameters for this job
run: |
echo "Job running with the following matrix configuration:"
echo "${{ toJson(matrix) }}"
- uses: actions/cache@v5
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
/var/cache/apt/archives
/var/lib/apt/lists
valkey-glide/ffi/target
valkey-glide/glide-core/src/generated
include/
src/*.pb-c.c
src/*.pb-c.h
key: ubuntu-latest-php-valgrind-${{ env.BASE_PHP_VERSION }}-${{ hashFiles('**/Cargo.lock', '.github/workflows/apt-packages.txt', 'valkey-glide/glide-core/src/protobuf/**/*.proto') }}
restore-keys: |
ubuntu-latest-php-valgrind-${{ env.BASE_PHP_VERSION }}-
ubuntu-latest-php-valgrind-
ubuntu-latest-php-
ubuntu-latest-glide-core
ubuntu-latest
- name: Cache Cargo dependencies (early)
uses: actions/cache@v5
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
valkey-glide/ffi/target/
valkey-glide/glide-core/target/
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-${{ runner.os }}-
- name: Setup ValkeyGlide with enhanced caching
uses: ./.github/workflows/setup-valkey-glide
with:
php-version: ${{ env.BASE_PHP_VERSION }}
engine-version: ${{ matrix.engine.version }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Remove optional fields from proto files
shell: bash
run: |
echo "=== Removing optional fields from proto files ==="
python3 utils/remove_optional_from_proto.py
echo "=== Proto file cleanup completed ==="
- uses: Swatinem/rust-cache@v2
with:
workspaces: |
valkey-glide/ffi
valkey-glide/glide-core
key: valgrind
- name: Pre-build Rust components
run: |
echo "=== Pre-building Rust components for make ==="
cd valkey-glide/ffi
cargo build --release
echo "Rust pre-build completed"
- name: Build FFI library with debug symbols
working-directory: valkey-glide/ffi
run: |
# Build with debug symbols for better Valgrind analysis
CFLAGS="-g -O0" cargo build --target x86_64-unknown-linux-gnu --release
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.BASE_PHP_VERSION }}
extensions: tokenizer, json, ctype, iconv, mbstring, simplexml, curl
tools: none
- name: Install system dependencies for PHP Valgrind build
run: |
sudo apt-get update
sudo apt-get install -y \
php${{ env.BASE_PHP_VERSION }}-dev \
build-essential \
autoconf \
automake \
libtool \
pkg-config \
libssl-dev \
protobuf-c-compiler \
libprotobuf-c-dev \
libprotobuf-c1 \
valgrind
- name: Start Valkey servers
working-directory: tests
run: |
set -e # Exit on any error
# Ensure /usr/local/bin is in PATH (where valkey-server is installed)
export PATH="/usr/local/bin:$PATH"
echo "=== Starting Valkey servers for Valgrind testing ==="
# Make scripts executable
chmod +x start_valkey_with_replicas.sh create-valkey-cluster.sh
# Start standalone servers (6379, 6380, 6381)
echo "=== Starting standalone Valkey servers ==="
./start_valkey_with_replicas.sh
# Wait a moment for servers to start
echo "=== Waiting for standalone servers to start ==="
sleep 3
# Start cluster servers (7001-7006)
echo "=== Starting Valkey cluster ==="
./create-valkey-cluster.sh
# Final server status check
echo "=== Final server status check ==="
ps aux | grep -E "(valkey|redis)-server" | grep -v grep || echo "No valkey/redis-server processes found"
echo "=== Valkey servers startup completed ==="
- name: Check Valgrind PATH
run: which valgrind && valgrind --version
- name: Setup and run Valgrind tests
run: |
echo "=== Setting up PHP extension build system for Valgrind testing ==="
# Step 1: Clean any existing files
echo "=== Step 1: Cleaning previous builds ==="
rm -rf ./modules/ ./libs/ ./.libs/ ./tmp-php.ini ./valgrind_logs/
find . -name "*.lo" -o -name "*.o" -o -name "*.la" | xargs rm -f 2>/dev/null || true
# Step 2: Initialize PHP extension build system
echo "=== Step 2: Initializing PHP extension build system ==="
phpize
# Step 3: Configure with debug flags for better Valgrind analysis
echo "=== Step 3: Configuring with debug flags ==="
CFLAGS="-g -O0" ./configure --enable-valkey-glide --enable-debug
# Step 5: Build extension with debug symbols
echo "=== Step 5: Building extension with debug symbols ==="
CFLAGS="-g -O0" make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo "4") build-modules-pre
CFLAGS="-g -O0" make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo "4")
# Check for undefined symbols in built extension
echo "=== Checking for undefined symbols in built extension ==="
if [[ "${{ matrix.host.OS }}" == "macos" ]]; then
# macOS: Use nm to check for undefined symbols (exclude system symbols)
echo "Running: nm -u modules/valkey_glide.so | grep -v dyld_stub_binder"
UNDEFINED_SYMBOLS=$(nm -u modules/valkey_glide.so 2>/dev/null | grep -v "dyld_stub_binder" | grep -E "^_zim_|^_execute_.*command" || true)
if [ -n "$UNDEFINED_SYMBOLS" ]; then
echo "❌ ERROR: Found undefined symbols in extension:"
echo "$UNDEFINED_SYMBOLS"
echo ""
echo "=== All undefined symbols (for debugging) ==="
nm -u modules/valkey_glide.so 2>/dev/null | head -20 || true
exit 1
fi
else
# Linux: Use objdump to check for undefined symbols
echo "Running: objdump -T modules/valkey_glide.so | grep UND"
UNDEFINED_SYMBOLS=$(objdump -T modules/valkey_glide.so 2>/dev/null | grep "UND" | grep -E "zim_|execute_.*command" || true)
if [ -n "$UNDEFINED_SYMBOLS" ]; then
echo "❌ ERROR: Found undefined symbols in extension:"
echo "$UNDEFINED_SYMBOLS"
echo ""
echo "=== All undefined symbols (for debugging) ==="
objdump -T modules/valkey_glide.so 2>/dev/null | grep "UND" | head -20 || true
exit 1
fi
fi
echo "✅ SUCCESS: No problematic undefined symbols detected"
# Test extension loading
echo "=== Testing extension loading ==="
php -n -d extension=./modules/valkey_glide.so -r "
if (!extension_loaded('valkey_glide')) {
echo 'ERROR: Extension failed to load' . PHP_EOL;
exit(1);
}
if (!class_exists('ValkeyGlide') || !class_exists('ValkeyGlideCluster')) {
echo 'ERROR: Extension classes not available' . PHP_EOL;
exit(1);
}
echo 'SUCCESS: Extension loads correctly' . PHP_EOL;
" 2>&1 | tee extension_test.log
if grep -q "ERROR:" extension_test.log; then
echo "Extension loading test failed"
exit 1
fi
# Check for undefined symbols in built extension
echo "=== Checking for undefined symbols in built extension ==="
if [[ "${{ matrix.host.OS }}" == "macos" ]]; then
# macOS: Use nm to check for undefined symbols (exclude system symbols)
echo "Running: nm -u modules/valkey_glide.so | grep -v dyld_stub_binder"
UNDEFINED_SYMBOLS=$(nm -u modules/valkey_glide.so 2>/dev/null | grep -v "dyld_stub_binder" | grep -E "^_zim_|^_execute_.*command" || true)
if [ -n "$UNDEFINED_SYMBOLS" ]; then
echo "❌ ERROR: Found undefined symbols in extension:"
echo "$UNDEFINED_SYMBOLS"
echo ""
echo "=== All undefined symbols (for debugging) ==="
nm -u modules/valkey_glide.so 2>/dev/null | head -20 || true
exit 1
fi
else
# Linux: Use objdump to check for undefined symbols
echo "Running: objdump -T modules/valkey_glide.so | grep UND"
UNDEFINED_SYMBOLS=$(objdump -T modules/valkey_glide.so 2>/dev/null | grep "UND" | grep -E "zim_|execute_.*command" || true)
if [ -n "$UNDEFINED_SYMBOLS" ]; then
echo "❌ ERROR: Found undefined symbols in extension:"
echo "$UNDEFINED_SYMBOLS"
echo ""
echo "=== All undefined symbols (for debugging) ==="
objdump -T modules/valkey_glide.so 2>/dev/null | grep "UND" | head -20 || true
exit 1
fi
fi
echo "✅ SUCCESS: No problematic undefined symbols detected"
# Step 6: Generate test protobuf PHP classes
echo "=== Step 6: Generating test protobuf PHP classes ==="
protoc --proto_path=./valkey-glide/glide-core/src/protobuf --php_out=./tests/ ./valkey-glide/glide-core/src/protobuf/connection_request.proto
echo "tests directory contents:"
cd tests
ls -la
cd ..
# Step 7: Install PHP dependencies
echo "=== Step 7: Installing PHP dependencies ==="
composer install --no-interaction --prefer-dist --optimize-autoloader
echo "Composer install completed. Checking for composer.lock:"
ls -la composer.lock || echo "Warning: composer.lock not found"
# Step 8: Create valgrind logs directory and verify setup
mkdir -p ./valgrind_logs
echo "=== Step 8: Verifying Valgrind setup ==="
echo "Working directory: $(pwd)"
echo "Extension exists: $(ls -la modules/valkey_glide.so 2>/dev/null || echo 'NOT FOUND')"
echo "Config file exists: $(ls -la ext.ini 2>/dev/null || echo 'NOT FOUND')"
echo "Test file exists: $(ls -la tests/TestValkeyGlide.php 2>/dev/null || echo 'NOT FOUND')"
echo "Suppressions file exists: $(ls -la valgrind.supp 2>/dev/null || echo 'NOT FOUND')"
echo "Valgrind version: $(valgrind --version)"
# Step 9: Run Valgrind tests
echo ""
echo "=== Step 9: Running Valgrind memory analysis ==="
echo "Command: valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --suppressions=valgrind.supp php -n -c ext.ini tests/TestValkeyGlide.php"
echo ""
# Run Valgrind with output to both terminal and log file
SUPPRESSIONS_FLAG=""
if [ -f "valgrind.supp" ]; then
SUPPRESSIONS_FLAG="--suppressions=valgrind.supp"
echo "Using suppressions file: valgrind.supp"
else
echo "No suppressions file found"
fi
valgrind \
--tool=memcheck \
--leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--verbose \
--error-exitcode=1 \
$SUPPRESSIONS_FLAG \
php -n -c ext.ini tests/TestValkeyGlide.php 2>&1 | tee ./valgrind_logs/valgrind_output.log
VALGRIND_EXIT_CODE=${PIPESTATUS[0]}
echo ""
echo "=== Valgrind analysis completed with exit code: $VALGRIND_EXIT_CODE ==="
# Store exit code for later use
echo "$VALGRIND_EXIT_CODE" > ./valgrind_logs/exit_code.txt
- name: Display Valgrind results
if: always()
run: |
echo "=== Valgrind Analysis Results Summary ==="
echo "Log directory contents:"
ls -la ./valgrind_logs/ 2>/dev/null || echo "No valgrind_logs directory found"
echo ""
if [ -f "./valgrind_logs/valgrind_output.log" ]; then
LOG_SIZE=$(wc -c < ./valgrind_logs/valgrind_output.log)
echo "=== Valgrind log file found (${LOG_SIZE} bytes) ==="
# Since we used tee, the output should already be visible above
# But let's extract key information for summary
echo ""
echo "=== Extracting Key Results ==="
# Show test completion status
if grep -q "All tests passed" ./valgrind_logs/valgrind_output.log; then
echo "✅ All tests passed"
elif grep -q "FAILED" ./valgrind_logs/valgrind_output.log; then
echo "❌ Some tests failed"
fi
# Check for memory leaks
DEFINITELY_LOST=$(grep "definitely lost:" ./valgrind_logs/valgrind_output.log | grep -o '[0-9,]* bytes' | head -1 | tr -d ',' || echo "0")
if [ "$DEFINITELY_LOST" -gt 0 ] 2>/dev/null; then
echo "⚠️ CRITICAL: Definite memory leaks detected ($DEFINITELY_LOST bytes)"
grep -A 3 -B 1 "definitely lost:" ./valgrind_logs/valgrind_output.log || true
else
echo "✅ No definite memory leaks detected"
fi
# Check for indirect leaks
INDIRECTLY_LOST=$(grep "indirectly lost:" ./valgrind_logs/valgrind_output.log | grep -o '[0-9,]* bytes' | head -1 | tr -d ',' || echo "0")
if [ "$INDIRECTLY_LOST" -gt 0 ] 2>/dev/null; then
echo "⚠️ CRITICAL: Indirect memory leaks detected ($INDIRECTLY_LOST bytes)"
grep -A 3 -B 1 "indirectly lost:" ./valgrind_logs/valgrind_output.log || true
else
echo "✅ No indirect memory leaks detected"
fi
# Check for possibly lost memory (treat as error, use suppressions for safe cases)
POSSIBLY_LOST=$(grep "possibly lost:" ./valgrind_logs/valgrind_output.log | head -1 | grep -o '[0-9,]* bytes' | head -1 | tr -d ',' || echo "0")
if [ "$POSSIBLY_LOST" -gt 0 ] 2>/dev/null; then
echo "❌ CRITICAL: Possibly lost memory detected ($POSSIBLY_LOST bytes)"
echo "Add suppressions to valgrind.supp if these are known safe allocations"
grep -A 3 -B 1 "possibly lost:" ./valgrind_logs/valgrind_output.log || true
else
echo "✅ No possibly lost memory detected"
fi
# Show leak summary if present
if grep -q "LEAK SUMMARY:" ./valgrind_logs/valgrind_output.log; then
echo ""
echo "=== Memory Leak Summary ==="
grep -A 6 "LEAK SUMMARY:" ./valgrind_logs/valgrind_output.log | head -7 || true
fi
# Show error summary
if grep -q "ERROR SUMMARY:" ./valgrind_logs/valgrind_output.log; then
echo ""
echo "=== Error Summary ==="
ERROR_COUNT=$(grep "ERROR SUMMARY:" ./valgrind_logs/valgrind_output.log | grep -o '[0-9]* errors' | head -1 | grep -o '[0-9]*')
if [ "$ERROR_COUNT" -gt 0 ] 2>/dev/null; then
echo "❌ CRITICAL: $ERROR_COUNT memory errors detected"
echo "=== Memory Error Details ==="
# Show the actual error details (not just leaks)
grep -B 5 -A 10 "Invalid\|Conditional\|Uninitialised\|Source and destination\|Address.*is.*bytes.*inside\|Use of uninitialised" ./valgrind_logs/valgrind_output.log || true
else
echo "✅ No memory errors detected"
fi
grep "ERROR SUMMARY:" ./valgrind_logs/valgrind_output.log || true
fi
echo ""
echo "📝 Full Valgrind output was displayed above during test execution"
echo "📎 Complete log is also saved as artifact for detailed analysis"
else
echo "❌ No Valgrind output file found"
echo "This indicates the Valgrind command may have failed to execute properly"
echo "Check the previous step output for any error messages"
fi
- name: Check test results and fail if needed
run: |
echo "=== Final Test Results Check ==="
# Check if exit code file exists
if [ -f "./valgrind_logs/exit_code.txt" ]; then
EXIT_CODE=$(cat ./valgrind_logs/exit_code.txt)
echo "Valgrind/PHP test exit code: $EXIT_CODE"
if [ "$EXIT_CODE" -ne 0 ]; then
echo "❌ FAILURE: PHP tests failed with exit code $EXIT_CODE"
echo "The workflow will fail even if no memory leaks were detected"
exit $EXIT_CODE
else
echo "✅ SUCCESS: PHP tests passed (exit code 0)"
fi
else
echo "❌ FAILURE: Could not determine test exit code"
echo "This indicates the valgrind command may not have run properly"
exit 1
fi
# Additional check for memory issues (fail on any leaks or possibly lost)
if [ -f "./valgrind_logs/valgrind_output.log" ]; then
# Check for all types of memory issues
DEFINITELY_LOST=$(grep "definitely lost:" ./valgrind_logs/valgrind_output.log | head -1 | grep -o '[0-9,]* bytes' | head -1 | tr -d ',' || echo "0")
INDIRECTLY_LOST=$(grep "indirectly lost:" ./valgrind_logs/valgrind_output.log | head -1 | grep -o '[0-9,]* bytes' | head -1 | tr -d ',' || echo "0")
POSSIBLY_LOST=$(grep "possibly lost:" ./valgrind_logs/valgrind_output.log | head -1 | grep -o '[0-9,]* bytes' | head -1 | tr -d ',' || echo "0")
if [ "$DEFINITELY_LOST" -gt 0 ] 2>/dev/null || [ "$INDIRECTLY_LOST" -gt 0 ] 2>/dev/null || [ "$POSSIBLY_LOST" -gt 0 ] 2>/dev/null; then
echo "❌ FAILURE: Memory issues detected"
echo "- Definitely lost: $DEFINITELY_LOST bytes"
echo "- Indirectly lost: $INDIRECTLY_LOST bytes"
echo "- Possibly lost: $POSSIBLY_LOST bytes"
echo "Fix memory leaks or add suppressions to valgrind.supp for known safe allocations"
exit 1
fi
fi
echo "=== All checks passed ==="
- name: Stop Valkey servers
if: always()
run: |
# Stop all Valkey server processes
echo "Stopping Valkey servers..."
pkill valkey-server || true
# Clean up data directories
rm -rf $HOME/valkey-cluster || true
rm -rf tests/valkey_data || true
- name: Upload Valgrind logs and reports
if: always()
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: valgrind-test-report-php-${{ matrix.engine.type }}-${{ matrix.engine.version }}
path: |
utils/clusters/**
valgrind_logs/**
tests/**/*.diff
tests/**/*.exp
tests/**/*.log
tests/**/*.out
lint:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.BASE_PHP_VERSION }}
extensions: none
tools: phpcs, phpstan
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
php${{ env.BASE_PHP_VERSION }}-dev \
build-essential \
autoconf \
automake \
libtool \
pkg-config \
libssl-dev \
protobuf-c-compiler \
libprotobuf-c-dev \
libprotobuf-c1
# Install clang-format-18 and set it as default.
sudo apt-get install -y clang-format-18
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-18 100
- name: Install protoc
uses: ./.github/workflows/install-rust-and-protoc
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install cbindgen
run: |
if [ -f "$HOME/.cargo/bin/cbindgen" ]; then
echo "cbindgen already installed (cached)"
else
cargo install cbindgen
fi
- name: Remove optional fields from proto files
shell: bash
run: |
echo "=== Removing optional fields from proto files ==="
python3 utils/remove_optional_from_proto.py
echo "=== Proto file cleanup completed ==="
- uses: actions/cache@v5
with:
path: |
valkey-glide/ffi/target
valkey-glide/glide-core/src/generated
include/
key: x86_64-unknown-linux-gnu-php-lint
restore-keys: |
x86_64-unknown-linux-gnu-php
x86_64-unknown-linux-gnu-glide-core
x86_64-unknown-linux-gnu
- name: Initialize PHP extension build system
run: |
phpize
- name: Configure PHP extension
run: |
./configure --enable-valkey-glide --disable-header-generation
- name: Run linters
run: |
./lint.sh
get-containers:
runs-on: ubuntu-latest
if: ${{ github.event.inputs.full-matrix == 'true' || github.event_name == 'schedule' }}
outputs:
engine-matrix-output: ${{ steps.get-matrices.outputs.engine-matrix-output }}
host-matrix-output: ${{ steps.get-matrices.outputs.host-matrix-output }}
version-matrix-output: ${{ steps.get-matrices.outputs.version-matrix-output }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- id: get-matrices
uses: ./.github/workflows/create-test-matrices
with:
language-name: php
run-full-matrix: true
containers: true
test-php-container:
runs-on: ${{ matrix.host.RUNNER }}
needs: get-containers
timeout-minutes: 35
strategy:
fail-fast: false
matrix:
php: ${{ fromJson(needs.get-containers.outputs.version-matrix-output) }}
engine: ${{ fromJson(needs.get-containers.outputs.engine-matrix-output) }}
host: ${{ fromJson(needs.get-containers.outputs.host-matrix-output) }}
container:
image: ${{ matrix.host.IMAGE }}
options: ${{ join(' -q ', matrix.host.CONTAINER_OPTIONS) }} # adding `-q` to bypass empty options
steps:
- name: Install git and dependencies
run: |
yum update
yum install -y git tar php php-devel gcc make autoconf automake libtool pkgconfig openssl openssl-devel unzip
git config --global --add safe.directory "$GITHUB_WORKSPACE"
echo IMAGE=amazonlinux:latest | sed -r 's/:/-/g' >> $GITHUB_ENV
# Replace `:` in the variable otherwise it can't be used in `upload-artifact`
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/cache@v5
with:
path: |
valkey-glide/ffi/target
valkey-glide/glide-core/src/generated
include/
key: ${{ matrix.host.IMAGE }}-php-${{ matrix.php }}
restore-keys: ${{ matrix.host.IMAGE }}-php
- name: Build PHP wrapper
uses: ./.github/workflows/build-php-wrapper
with:
os: ${{ matrix.host.OS }}
target: ${{ matrix.host.TARGET }}
php-version: ${{ matrix.php }}
github-token: ${{ secrets.GITHUB_TOKEN }}
engine-version: ${{ matrix.engine.version }}
- name: Start Valkey servers
working-directory: tests
run: |
set -e # Exit on any error
# Ensure /usr/local/bin is in PATH (where valkey-server is installed)
export PATH="/usr/local/bin:$PATH"
echo "=== DEBUG: Current directory and files ==="
pwd
ls -la
echo "=== DEBUG: Current PATH ==="
echo "PATH=$PATH"
echo "=== DEBUG: Checking for installed binaries in /usr/local/bin ==="
ls -la /usr/local/bin/ | grep -E "(valkey|redis)" || echo "No valkey/redis binaries in /usr/local/bin"
echo "=== DEBUG: Checking script permissions ==="
ls -la start_valkey_with_replicas.sh create-valkey-cluster.sh
# Make scripts executable
chmod +x start_valkey_with_replicas.sh create-valkey-cluster.sh
echo "=== DEBUG: After chmod ==="
ls -la start_valkey_with_replicas.sh create-valkey-cluster.sh
# Check if valkey-server is available
echo "=== DEBUG: Checking for valkey-server ==="
which valkey-server || echo "valkey-server not found in PATH"
# Check alternative locations and names
echo "=== DEBUG: Checking alternative binary names ==="
which redis-server || echo "redis-server not found in PATH"
which valkey-cli || echo "valkey-cli not found in PATH"
which redis-cli || echo "redis-cli not found in PATH"
# Start standalone servers (6379, 6380, 6381)
echo "=== Starting standalone Valkey servers ==="
./start_valkey_with_replicas.sh
# Wait a moment for servers to start
echo "=== Waiting for standalone servers to start ==="
sleep 3