@@ -142,6 +142,10 @@ jobs:
142142 git config --global url."ssh://git@github.com-http-handler/platformatic/http-handler.git".insteadOf "ssh://git@github.com/platformatic/http-handler.git"
143143 git config --global url."ssh://git@github.com-http-rewriter/platformatic/http-rewriter.git".insteadOf "ssh://git@github.com/platformatic/http-rewriter.git"
144144
145+ # Set Python-related environment variables for the build
146+ export PYO3_PYTHON=$(which python3)
147+ export PYTHON_SYS_EXECUTABLE=$(which python3)
148+
145149 ${{ matrix.settings.build }}
146150 - name : Build
147151 run : ${{ matrix.settings.build }}
@@ -326,15 +330,94 @@ jobs:
326330 uses : addnab/docker-run-action@v3
327331 with :
328332 image : ${{ steps.docker.outputs.IMAGE }}
329- options : -v ${{ steps.docker.outputs.PNPM_STORE_PATH }}:${{ steps.docker.outputs.PNPM_STORE_PATH }} -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }}
333+ options : -v ${{ steps.docker.outputs.PNPM_STORE_PATH }}:${{ steps.docker.outputs.PNPM_STORE_PATH }} -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }} -e CI=true -e GITHUB_ACTIONS=true
330334 run : |
331335 # Install Python 3.9+ (any version will work with abi3-py39)
332336 apt-get update -y
333- apt-get install -y python3 python3-dev
337+ apt-get install -y python3 python3-dev patchelf
338+
339+ echo "=== Starting test setup ==="
340+ echo "Current directory: $(pwd)"
341+ echo "Python version: $(python3 --version)"
342+ echo "Patchelf version: $(patchelf --version)"
343+ echo "CI environment: CI=$CI, GITHUB_ACTIONS=$GITHUB_ACTIONS"
344+
345+ # Check what .node files exist
346+ echo "=== Available .node files ==="
347+ ls -la *.node || echo "No .node files found"
348+
349+ # Check what Python version the binary was built with and patch SONAME if needed
350+ echo "=== Checking .node file Python dependencies ==="
351+ for file in *.node; do
352+ if [ -f "$file" ]; then
353+ case "$file" in
354+ *linux*)
355+ echo "Checking $file..."
356+ echo "Python dependencies before patching:"
357+ ldd "$file" 2>/dev/null | grep python || echo "No Python dependencies found"
358+
359+ # Check if we need to patch SONAME
360+ current_python_lib=$(ldd "$file" 2>/dev/null | grep "libpython" | head -1 | awk '{print $1}')
361+ if [ -n "$current_python_lib" ]; then
362+ echo "Current Python library: $current_python_lib"
363+
364+ # Find the actual Python library on the system
365+ system_python_lib=$(find /usr/lib* -name "libpython3*.so.*" -type f 2>/dev/null | head -1)
366+ if [ -n "$system_python_lib" ]; then
367+ system_python_soname=$(basename "$system_python_lib")
368+ echo "System Python library: $system_python_soname"
369+
370+ # Only patch if they're different
371+ if [ "$current_python_lib" != "$system_python_soname" ]; then
372+ echo "Patching SONAME from $current_python_lib to $system_python_soname"
373+ patchelf --replace-needed "$current_python_lib" "$system_python_soname" "$file"
374+ echo "SONAME patching completed"
375+ else
376+ echo "SONAME already matches system Python"
377+ fi
378+ else
379+ echo "Warning: Could not find system Python library"
380+ fi
381+ else
382+ echo "No Python library dependency found"
383+ fi
384+
385+ echo "Python dependencies after patching:"
386+ ldd "$file" 2>/dev/null | grep python || echo "No Python dependencies found"
387+ echo "---"
388+ ;;
389+ *)
390+ echo "Skipping non-Linux file: $file"
391+ ;;
392+ esac
393+ fi
394+ done
334395
335396 # Install pnpm and run tests
397+ echo "=== Installing pnpm ==="
336398 corepack disable
337399 npm i -gf pnpm
400+
401+ echo "=== Running pnpm install ==="
402+ # Should be non-interactive in CI environment
403+ pnpm install --prefer-offline
404+
405+ echo "=== Setting up Python library path ==="
406+ export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
407+ echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
408+
409+ # Find and preload the Python library
410+ echo "=== Finding Python library to preload ==="
411+ PYTHON_LIB=$(find /usr/lib* -name "libpython3*.so.*" -type f 2>/dev/null | head -1)
412+ if [ -n "$PYTHON_LIB" ]; then
413+ echo "Found Python library: $PYTHON_LIB"
414+ export LD_PRELOAD=$PYTHON_LIB
415+ echo "LD_PRELOAD: $LD_PRELOAD"
416+ else
417+ echo "Warning: Could not find Python library to preload"
418+ fi
419+
420+ echo "=== Running tests ==="
338421 pnpm test
339422
340423 publish :
0 commit comments