From b82c8044407cb8577e1e1e7779257123dbb66ae2 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sat, 15 Aug 2026 20:47:44 +0200
Subject: [PATCH v2 03/12] ci: temporarily install a 32-bit Python in the
 32-bit job

TEMPORARY: This patch can be dropped from the patchset once
https://github.com/anarazel/pg-vm-images/pull/144 is merged and the 32bit
job switches to the native i386 image it adds. For now this installs a
32bit python interpreter on every run so that we can run tests using a
32bit python interpreter against our 32bit postgres/libpq build in CI.
---
 .github/workflows/pg-ci.yml | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/.github/workflows/pg-ci.yml b/.github/workflows/pg-ci.yml
index 94e8e755f1d..522bf043d50 100644
--- a/.github/workflows/pg-ci.yml
+++ b/.github/workflows/pg-ci.yml
@@ -559,6 +559,42 @@ jobs:
       - *ccache_restore_branch_step
       - *linux_prepare_workspace_step
 
+      # TEMPORARY: this whole step goes away, together with the commit that
+      # added it, once https://github.com/anarazel/pg-vm-images/pull/144 is
+      # merged and this job uses the native i386 image it adds.
+      #
+      # We lift the interpreter out of the .deb instead of installing the
+      # package, because python3.X-minimal is not Multi-Arch: same (it cannot
+      # be, it ships an arch-specific /usr/bin/python3.X), so installing the
+      # i386 one would replace the amd64 python3 stack instead of joining it.
+      # The libpython packages it needs are Multi-Arch: same and do co-install,
+      # because their extension modules carry the architecture in the file name
+      # (_ctypes.cpython-313-i386-linux-gnu.so).
+      - name: Install 32-bit Python
+        run: |
+          set -ex
+          pyver=$(python3 -c 'import sys; print("%d.%d" % sys.version_info[:2])')
+          apt-get update
+          apt-get install -y --no-install-recommends \
+            "libpython${pyver}-minimal:i386" "libpython${pyver}-stdlib:i386"
+          tmp=$(mktemp -d)
+          ( cd "$tmp" && apt-get download "python${pyver}-minimal:i386" )
+          dpkg-deb --fsys-tarfile "$tmp"/python${pyver}-minimal_*_i386.deb \
+            | tar -xOf - "./usr/bin/python${pyver}" \
+            > /usr/local/bin/python3-i386
+          chmod 755 /usr/local/bin/python3-i386
+          rm -rf "$tmp"
+
+          # pytest itself needs no separate install: /usr/lib/python3/dist-packages
+          # is on this interpreter's sys.path too and pytest is pure python. A
+          # wrapper is still needed, because meson's PYTEST option takes a
+          # program path and so cannot spell "python3-i386 -m pytest" itself.
+          cat > /usr/local/bin/pytest-i386 <<'PYTEST_I386'
+          #! /bin/sh
+          exec /usr/local/bin/python3-i386 -m pytest "$@"
+          PYTEST_I386
+          chmod 755 /usr/local/bin/pytest-i386
+
       - name: Configure
         shell: *su_postgres_shell
         run: |
-- 
2.55.0

