Skip to content

Commit c433748

Browse files
committed
fix: build Linux binary for missing-libs test and fix heredoc issues
- Add Rust build step in CI for the missing-libs test so it uses the PR binary (with shared lib detection) instead of the released one - Rewrite test script to use a mounted script file instead of nested heredocs to avoid bash quoting issues - Require PG0_BINARY_PATH to be set (test needs the PR binary)
1 parent ecd038f commit c433748

2 files changed

Lines changed: 46 additions & 37 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ jobs:
7878
steps:
7979
- uses: actions/checkout@v4
8080

81+
- name: Install Rust
82+
if: matrix.platform == 'missing-libs-debian-amd64'
83+
uses: dtolnay/rust-toolchain@stable
84+
85+
- name: Build Linux binary
86+
if: matrix.platform == 'missing-libs-debian-amd64'
87+
run: |
88+
cargo build --release
89+
echo "PG0_BINARY_PATH=$(pwd)/target/release/pg0" >> $GITHUB_ENV
90+
8191
- name: Run CLI Docker test
8292
run: |
8393
chmod +x ${{ matrix.cli_script }}

docker-tests/test_missing_libs.sh

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ echo "============================================="
1111
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1212
INSTALL_SCRIPT="$SCRIPT_DIR/../install.sh"
1313

14-
# Check if PG0_BINARY_PATH is set (local binary to test)
15-
VOLUME_ARGS=""
16-
BINARY_ENV=""
17-
if [ -n "${PG0_BINARY_PATH:-}" ]; then
18-
echo "Using local binary: $PG0_BINARY_PATH"
19-
VOLUME_ARGS="-v $PG0_BINARY_PATH:/tmp/pg0-binary:ro"
20-
BINARY_ENV="-e PG0_BINARY_URL=file:///tmp/pg0-binary"
14+
# PG0_BINARY_PATH is required - this test must use a binary built from source
15+
# (with the shared library detection code), not the released binary
16+
if [ -z "${PG0_BINARY_PATH:-}" ]; then
17+
echo "ERROR: PG0_BINARY_PATH must be set to a Linux binary built from this branch"
18+
exit 1
2119
fi
2220

23-
docker run --rm --platform=linux/amd64 \
24-
$BINARY_ENV \
25-
-v "$INSTALL_SCRIPT:/tmp/install.sh:ro" \
26-
$VOLUME_ARGS \
27-
python:3.11-slim bash -c '
21+
echo "Using local binary: $PG0_BINARY_PATH"
22+
23+
# Create a temporary test script to run inside the container
24+
# This avoids nested heredoc quoting issues
25+
TEMP_SCRIPT=$(mktemp)
26+
cat > "$TEMP_SCRIPT" << 'INNERSCRIPT'
27+
#!/bin/bash
2828
set -e
2929
3030
echo "=== System Info ==="
@@ -43,69 +43,61 @@ useradd -m -s /bin/bash pguser
4343
echo "pguser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
4444
4545
echo ""
46-
echo "=== Copying local install.sh ==="
47-
cp /tmp/install.sh /usr/local/bin/install.sh
48-
chmod 755 /usr/local/bin/install.sh
46+
echo "=== Installing pg0 from local binary ==="
47+
cp /tmp/pg0-binary /usr/local/bin/pg0
48+
chmod 755 /usr/local/bin/pg0
4949
5050
echo ""
51-
echo "=== Phase 1: Install pg0 and do initial extraction ==="
52-
su - pguser << EOF
51+
echo "=== Phase 1: Initial extraction with all deps present ==="
52+
su -s /bin/bash - pguser -c '
5353
set -e
54-
export PG0_BINARY_URL="${PG0_BINARY_URL}"
55-
56-
echo "=== Installing pg0 ==="
57-
bash /usr/local/bin/install.sh
58-
export PATH="\$HOME/.local/bin:\$PATH"
54+
export PATH="/usr/local/bin:$PATH"
5955
60-
echo ""
6156
echo "=== Starting PostgreSQL (initial extraction) ==="
6257
pg0 start
6358
sleep 3
6459
65-
echo ""
6660
echo "=== Stopping PostgreSQL ==="
6761
pg0 stop
6862
sleep 1
6963
70-
echo ""
7164
echo "=== Removing extracted installation to force re-extraction ==="
7265
rm -rf ~/.pg0/installation
7366
echo "Installation directory cleared."
74-
EOF
67+
'
7568
7669
echo ""
7770
echo "=== Phase 2: Remove libxml2 to simulate missing library ==="
7871
apt-get remove -y libxml2 2>&1 | tail -3
7972
8073
echo ""
8174
echo "=== Phase 3: Verify pg0 detects missing libraries ==="
82-
su - pguser << EOF
75+
su -s /bin/bash - pguser -c '
8376
set -e
84-
export PATH="\$HOME/.local/bin:\$PATH"
77+
export PATH="/usr/local/bin:$PATH"
8578
8679
echo "=== Starting pg0 (should fail with missing library error) ==="
87-
OUTPUT=\$(pg0 start 2>&1 || true)
88-
EXIT_CODE=\${PIPESTATUS[0]:-\$?}
89-
echo "\$OUTPUT"
80+
OUTPUT=$(pg0 start 2>&1 || true)
81+
echo "$OUTPUT"
9082
9183
echo ""
9284
echo "=== Checking error message ==="
9385
94-
if echo "\$OUTPUT" | grep -q "missing required system libraries"; then
95-
echo "PASS: Found 'missing required system libraries' message"
86+
if echo "$OUTPUT" | grep -q "missing required system libraries"; then
87+
echo "PASS: Found missing required system libraries message"
9688
else
9789
echo "FAIL: Missing expected error message about shared libraries"
9890
exit 1
9991
fi
10092
101-
if echo "\$OUTPUT" | grep -q "libxml2"; then
102-
echo "PASS: Found 'libxml2' in the missing library list"
93+
if echo "$OUTPUT" | grep -qi "libxml2"; then
94+
echo "PASS: Found libxml2 in the missing library list"
10395
else
10496
echo "FAIL: Expected libxml2 to be listed as missing"
10597
exit 1
10698
fi
10799
108-
if echo "\$OUTPUT" | grep -q "Install the missing libraries"; then
100+
if echo "$OUTPUT" | grep -q "Install the missing libraries"; then
109101
echo "PASS: Found install guidance message"
110102
else
111103
echo "FAIL: Missing install guidance"
@@ -116,8 +108,15 @@ echo ""
116108
echo "============================================="
117109
echo "ALL CHECKS PASSED - Missing libs detected"
118110
echo "============================================="
119-
EOF
120111
'
112+
INNERSCRIPT
113+
114+
docker run --rm --platform=linux/amd64 \
115+
-v "$PG0_BINARY_PATH:/tmp/pg0-binary:ro" \
116+
-v "$TEMP_SCRIPT:/tmp/test_script.sh:ro" \
117+
python:3.11-slim bash /tmp/test_script.sh
118+
119+
rm -f "$TEMP_SCRIPT"
121120

122121
echo ""
123122
echo "Test completed successfully!"

0 commit comments

Comments
 (0)