Skip to content

Commit 567f8bd

Browse files
authored
Generate and test PIE packages (#31)
* Support PIE package distribution Support distributing the extension as a PIE package on Packagist. Add a CD pipeline for validating that the package can be put on a local Composer repo, then built and installed from the repo using the pie command. The installed package is then run against the same integration tests as the dev pipeline. Rework Makefile.frag so that the extension can be built with the standard set of commands that the pie command runs: - phpize - ./configure - make - make install This also requires loading the valkey-glide sub-module, generating protobufs, running the FFI build internally within the Makefile. Create shared setup action for running PHP tests. Signed-off-by: James Duong <[email protected]>
1 parent 4046155 commit 567f8bd

File tree

9 files changed

+529
-433
lines changed

9 files changed

+529
-433
lines changed

.github/workflows/build-php-wrapper/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ runs:
158158
- name: Generate protobuf and bindings
159159
shell: bash
160160
run: |
161-
make build-modules-pre
161+
make include/glide_bindings.h
162162
163163
- name: Debug PHP extension linking
164164
shell: bash

.github/workflows/ort.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ jobs:
367367
- name: Warn of outdated attributions due to the PR
368368
if: ${{ env.FOUND_DIFF == 'true' && github.event_name == 'pull_request' }}
369369
run: |
370-
ATTRIBUTION_FILES=(
370+
ATTRIBUTION_FILES=(
371371
"${{ env.PHP_ATTRIBUTIONS }}"
372372
)
373373

.github/workflows/php.yml

Lines changed: 14 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -155,88 +155,11 @@ jobs:
155155
echo "Current directory contents:"
156156
ls -la
157157
158-
- name: Start Valkey servers
159-
working-directory: tests
160-
run: |
161-
set -e # Exit on any error
162-
163-
# Ensure /usr/local/bin is in PATH (where valkey-server is installed)
164-
export PATH="/usr/local/bin:$PATH"
165-
166-
echo "=== DEBUG: Current directory and files ==="
167-
pwd
168-
ls -la
169-
170-
echo "=== DEBUG: Current PATH ==="
171-
echo "PATH=$PATH"
172-
173-
echo "=== DEBUG: Checking for installed binaries in /usr/local/bin ==="
174-
ls -la /usr/local/bin/ | grep -E "(valkey|redis)" || echo "No valkey/redis binaries in /usr/local/bin"
175-
176-
echo "=== DEBUG: Checking script permissions ==="
177-
ls -la start_valkey_with_replicas.sh create-valkey-cluster.sh
178-
179-
# Make scripts executable
180-
chmod +x start_valkey_with_replicas.sh create-valkey-cluster.sh
181-
182-
echo "=== DEBUG: After chmod ==="
183-
ls -la start_valkey_with_replicas.sh create-valkey-cluster.sh
184-
185-
# Check if valkey-server is available
186-
echo "=== DEBUG: Checking for valkey-server ==="
187-
which valkey-server || echo "valkey-server not found in PATH"
188-
189-
# Check alternative locations and names
190-
echo "=== DEBUG: Checking alternative binary names ==="
191-
which redis-server || echo "redis-server not found in PATH"
192-
which valkey-cli || echo "valkey-cli not found in PATH"
193-
which redis-cli || echo "redis-cli not found in PATH"
194-
195-
# Start standalone servers (6379, 6380, 6381)
196-
echo "=== Starting standalone Valkey servers ==="
197-
./start_valkey_with_replicas.sh
198-
199-
# Wait a moment for servers to start
200-
echo "=== Waiting for standalone servers to start ==="
201-
sleep 3
202-
203-
# Check if servers are running
204-
echo "=== Checking standalone server status ==="
205-
ps aux | grep -E "(valkey|redis)-server" | grep -v grep || echo "No valkey/redis-server processes found"
206-
207-
# Start cluster servers (7001-7006)
208-
echo "=== Starting Valkey cluster ==="
209-
./create-valkey-cluster.sh
210-
211-
# Final server status check
212-
echo "=== Final server status check ==="
213-
ps aux | grep -E "(valkey|redis)-server" | grep -v grep || echo "No valkey/redis-server processes found"
214-
echo "=== Valkey servers startup completed ==="
215-
216-
- name: Run PHP extension tests
217-
run: |
218-
# Run tests using direct extension loading with absolute path
219-
php -n -d extension=$(pwd)/modules/valkey_glide.so tests/TestValkeyGlide.php
220-
221-
- name: Run integration tests
222-
run: |
223-
# All tests are now run through the main TestValkeyGlide.php runner
224-
echo "All 4 test classes are already included in the main test runner"
225-
echo "TestValkeyGlide.php now runs all classes by default:"
226-
echo "- ValkeyGlide_Test (standalone)"
227-
echo "- ValkeyGlide_Cluster_Test (cluster)"
228-
echo "- ValkeyGlide_Features_Test (standalone features)"
229-
echo "- ValkeyGlide_Cluster_Features_Test (cluster features)"
230-
231-
- name: Stop Valkey servers
232-
if: always()
233-
run: |
234-
# Stop all Valkey server processes
235-
echo "Stopping Valkey servers..."
236-
pkill valkey-server || true
237-
# Clean up data directories
238-
rm -rf $HOME/valkey-cluster || true
239-
rm -rf tests/valkey_data || true
158+
- name: Run PHP Extension Tests
159+
uses: ./.github/workflows/run-php-tests
160+
with:
161+
extension-path: ${{ github.workspace }}/modules/valkey_glide.so
162+
php-version: ${{ matrix.php }}
240163

241164
- uses: ./.github/workflows/test-benchmark
242165
if: ${{ matrix.engine.version == '8.0' && matrix.host.OS == 'ubuntu' && matrix.host.RUNNER == 'ubuntu-latest' && matrix.php == env.BASE_PHP_VERSION }}
@@ -588,7 +511,7 @@ jobs:
588511
echo "Test file exists: $(ls -la tests/TestValkeyGlide.php 2>/dev/null || echo 'NOT FOUND')"
589512
echo "Suppressions file exists: $(ls -la valgrind.supp 2>/dev/null || echo 'NOT FOUND')"
590513
echo "Valgrind version: $(valgrind --version)"
591-
514+
592515
# Step 7: Run Valgrind tests
593516
echo ""
594517
echo "=== Step 7: Running Valgrind memory analysis ==="
@@ -619,51 +542,51 @@ jobs:
619542
if [ -f "./valgrind_logs/valgrind_output.log" ]; then
620543
LOG_SIZE=$(wc -c < ./valgrind_logs/valgrind_output.log)
621544
echo "=== Valgrind log file found (${LOG_SIZE} bytes) ==="
622-
545+
623546
# Since we used tee, the output should already be visible above
624547
# But let's extract key information for summary
625548
echo ""
626549
echo "=== Extracting Key Results ==="
627-
550+
628551
# Show test completion status
629552
if grep -q "All tests passed" ./valgrind_logs/valgrind_output.log; then
630553
echo "✅ All tests passed"
631554
elif grep -q "FAILED" ./valgrind_logs/valgrind_output.log; then
632555
echo "❌ Some tests failed"
633556
fi
634-
557+
635558
# Check for memory leaks
636559
if grep -q "definitely lost:" ./valgrind_logs/valgrind_output.log; then
637560
echo "⚠️ CRITICAL: Definite memory leaks detected"
638561
grep -A 3 -B 1 "definitely lost:" ./valgrind_logs/valgrind_output.log || true
639562
else
640563
echo "✅ No definite memory leaks detected"
641564
fi
642-
565+
643566
# Check for possible leaks
644567
if grep -q "possibly lost:" ./valgrind_logs/valgrind_output.log; then
645568
POSSIBLY_LOST=$(grep "possibly lost:" ./valgrind_logs/valgrind_output.log | head -1)
646569
echo "⚠️ Possible leaks: $POSSIBLY_LOST"
647570
fi
648-
571+
649572
# Show leak summary if present
650573
if grep -q "LEAK SUMMARY:" ./valgrind_logs/valgrind_output.log; then
651574
echo ""
652575
echo "=== Memory Leak Summary ==="
653576
grep -A 6 "LEAK SUMMARY:" ./valgrind_logs/valgrind_output.log | head -7 || true
654577
fi
655-
578+
656579
# Show error summary
657580
if grep -q "ERROR SUMMARY:" ./valgrind_logs/valgrind_output.log; then
658581
echo ""
659582
echo "=== Error Summary ==="
660583
grep "ERROR SUMMARY:" ./valgrind_logs/valgrind_output.log || true
661584
fi
662-
585+
663586
echo ""
664587
echo "📝 Full Valgrind output was displayed above during test execution"
665588
echo "📎 Complete log is also saved as artifact for detailed analysis"
666-
589+
667590
else
668591
echo "❌ No Valgrind output file found"
669592
echo "This indicates the Valgrind command may have failed to execute properly"

.github/workflows/run-ort-tools/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ runs:
4444
echo "ERROR: Source folder does not exist!"
4545
exit 1
4646
fi
47-
47+
4848
# Create output directory
4949
echo "Creating output directory: $FOLDER/ort_results"
5050
mkdir -p "$FOLDER/ort_results"
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Run PHP Extension Tests
2+
description: Common steps for running PHP extension tests with Valkey servers
3+
4+
inputs:
5+
extension-path:
6+
description: Path to the built extension (.so file)
7+
required: true
8+
php-version:
9+
description: PHP version to use for testing
10+
required: true
11+
default: "8.1"
12+
13+
runs:
14+
using: composite
15+
steps:
16+
- name: Start Valkey servers
17+
working-directory: tests
18+
shell: bash
19+
run: |
20+
set -e # Exit on any error
21+
22+
# Ensure /usr/local/bin is in PATH (where valkey-server is installed)
23+
export PATH="/usr/local/bin:$PATH"
24+
25+
echo "=== DEBUG: Current directory and files ==="
26+
pwd
27+
ls -la
28+
29+
echo "=== DEBUG: Environment ==="
30+
echo "PATH=$PATH"
31+
32+
echo "=== DEBUG: Checking for installed binaries in /usr/local/bin ==="
33+
ls -la /usr/local/bin/ | grep -E "(valkey|redis)" || echo "No valkey/redis binaries in /usr/local/bin"
34+
35+
echo "=== DEBUG: Checking script permissions ==="
36+
ls -la start_valkey_with_replicas.sh create-valkey-cluster.sh
37+
38+
# Make scripts executable
39+
chmod +x start_valkey_with_replicas.sh create-valkey-cluster.sh
40+
41+
echo "=== DEBUG: After chmod ==="
42+
ls -la start_valkey_with_replicas.sh create-valkey-cluster.sh
43+
44+
# Check if valkey-server is available
45+
echo "=== DEBUG: Checking for valkey-server ==="
46+
which valkey-server || echo "valkey-server not found in PATH"
47+
48+
# Check alternative locations and names
49+
echo "=== DEBUG: Checking alternative binary names ==="
50+
which redis-server || echo "redis-server not found in PATH"
51+
which valkey-cli || echo "valkey-cli not found in PATH"
52+
which redis-cli || echo "redis-cli not found in PATH"
53+
54+
# Start standalone servers (6379, 6380, 6381)
55+
echo "=== Starting standalone Valkey servers ==="
56+
./start_valkey_with_replicas.sh
57+
58+
# Wait a moment for servers to start
59+
echo "=== Waiting for standalone servers to start ==="
60+
sleep 3
61+
62+
# Check if servers are running
63+
echo "=== Checking standalone server status ==="
64+
ps aux | grep -E "(valkey|redis)-server" | grep -v grep || echo "No valkey/redis-server processes found"
65+
66+
# Start cluster servers (7001-7006)
67+
echo "=== Starting Valkey cluster ==="
68+
./create-valkey-cluster.sh
69+
70+
# Final server status check
71+
echo "=== Final server status check ==="
72+
ps aux | grep -E "(valkey|redis)-server" | grep -v grep || echo "No valkey/redis-server processes found"
73+
echo "=== Valkey servers startup completed ==="
74+
75+
- name: Run PHP extension tests
76+
shell: bash
77+
env:
78+
EXTENSION_PATH: ${{ inputs.extension-path }}
79+
run: |
80+
# Debug: Check if extension is loaded and classes exist
81+
echo "=== Extension Debug Info ==="
82+
echo "Extension path: $EXTENSION_PATH"
83+
84+
php -n -d "extension=$EXTENSION_PATH" -r "
85+
echo 'Extension loaded: ' . (extension_loaded('valkey_glide') ? 'YES' : 'NO') . PHP_EOL;
86+
echo 'Extension version: ' . phpversion('valkey_glide') . PHP_EOL;
87+
echo 'Extension functions: ' . PHP_EOL;
88+
foreach (get_extension_funcs('valkey_glide') as \$func) {
89+
echo ' - ' . \$func . PHP_EOL;
90+
}
91+
echo 'All declared classes: ' . PHP_EOL;
92+
foreach (get_declared_classes() as \$class) {
93+
if (strpos(\$class, 'Valkey') !== false || strpos(\$class, 'Client') !== false || strpos(\$class, 'Mock') !== false) {
94+
echo ' - ' . \$class . PHP_EOL;
95+
}
96+
}
97+
echo 'ClientConstructorMock exists: ' . (class_exists('ClientConstructorMock') ? 'YES' : 'NO') . PHP_EOL;
98+
if (class_exists('ClientConstructorMock')) {
99+
echo 'ClientConstructorMock methods: ' . PHP_EOL;
100+
foreach (get_class_methods('ClientConstructorMock') as \$method) {
101+
echo ' - ' . \$method . PHP_EOL;
102+
}
103+
}
104+
"
105+
106+
# Run tests using extension loading
107+
php -n -d "extension=$EXTENSION_PATH" tests/TestValkeyGlide.php
108+
109+
- name: Run integration tests
110+
shell: bash
111+
run: |
112+
# All tests are now run through the main TestValkeyGlide.php runner
113+
echo "All 4 test classes are already included in the main test runner"
114+
echo "TestValkeyGlide.php now runs all classes by default:"
115+
echo "- ValkeyGlide_Test (standalone)"
116+
echo "- ValkeyGlide_Cluster_Test (cluster)"
117+
echo "- ValkeyGlide_Features_Test (standalone features)"
118+
echo "- ValkeyGlide_Cluster_Features_Test (cluster features)"
119+
120+
- name: Stop Valkey servers
121+
if: always()
122+
shell: bash
123+
run: |
124+
# Stop all Valkey server processes
125+
echo "Stopping Valkey servers..."
126+
pkill valkey-server || true
127+
# Clean up data directories
128+
rm -rf $HOME/valkey-cluster || true
129+
rm -rf tests/valkey_data || true
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Setup PHP Extension Build Environment
2+
description: Common setup steps for building PHP extension
3+
4+
inputs:
5+
php-version:
6+
description: PHP version to use
7+
required: true
8+
default: "8.1"
9+
install-composer-deps:
10+
description: Whether to install composer dependencies
11+
required: false
12+
default: "true"
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Install shared dependencies
18+
uses: ./.github/workflows/install-shared-dependencies
19+
with:
20+
target: x86_64-unknown-linux-gnu
21+
github-token: ${{ github.token }}
22+
engine-version: "7.2.5"
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ inputs.php-version }}
28+
extensions: none
29+
tools: pie, jq
30+
31+
- name: Install system dependencies
32+
shell: bash
33+
env:
34+
PHP_VERSION: ${{ inputs.php-version }}
35+
run: |
36+
sudo apt-get update
37+
sudo apt-get install -y \
38+
"php${PHP_VERSION}-dev" \
39+
"php${PHP_VERSION}-curl" \
40+
"php${PHP_VERSION}-xml" \
41+
build-essential \
42+
autoconf \
43+
automake \
44+
libtool \
45+
pkg-config \
46+
libssl-dev \
47+
clang-format \
48+
protobuf-c-compiler \
49+
libprotobuf-c-dev \
50+
libprotobuf-c1
51+
52+
- name: Install Rust and protoc
53+
uses: ./.github/workflows/install-rust-and-protoc
54+
with:
55+
github-token: ${{ github.token }}
56+
57+
- name: Install cbindgen
58+
shell: bash
59+
run: cargo install cbindgen
60+
61+
- name: Install Composer dependencies
62+
if: inputs.install-composer-deps == 'true'
63+
shell: bash
64+
run: composer install --ignore-platform-reqs
65+
66+
- name: Generate test protobuf PHP classes
67+
if: inputs.install-composer-deps == 'true'
68+
shell: bash
69+
run: |
70+
protoc --proto_path=./valkey-glide/glide-core/src/protobuf --php_out=./tests/ ./valkey-glide/glide-core/src/protobuf/connection_request.proto
71+
echo "tests directory contents:"
72+
cd tests
73+
ls -la

0 commit comments

Comments
 (0)