From 1d56d0a0cfff837851aaf44cd7507ae0743a40a6 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 v1 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/143 is merged and the CI
image ships the interpreter itself. 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 c0dc5ba0360..9ceef9e9c1d 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/143 is
+      # merged and the CI image ships python3-i386/pytest-i386 itself.
+      #
+      # 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.54.0

