Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 185 additions & 0 deletions .github/workflows/build-python-wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
name: Build Python Wheels

on:
workflow_call:
inputs:
upload-artifacts:
description: 'Upload wheel artifacts'
required: false
default: true
type: boolean
test-wheels:
description: 'Test the built wheels'
required: false
default: true
type: boolean

jobs:
build-wheels:
name: Build wheel (${{ matrix.platform }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# macOS Apple Silicon
- os: macos-14
platform: darwin-aarch64
wheel_platform: macosx_14_0_arm64
rust_target: aarch64-apple-darwin

# Linux x86_64 glibc
- os: ubuntu-22.04
platform: linux-x86_64-gnu
wheel_platform: manylinux_2_35_x86_64
rust_target: x86_64-unknown-linux-gnu

# Linux ARM64 glibc
- os: ubuntu-22.04-arm
platform: linux-aarch64-gnu
wheel_platform: manylinux_2_35_aarch64
rust_target: aarch64-unknown-linux-gnu

# Windows x64
- os: windows-latest
platform: windows-x86_64
wheel_platform: win_amd64
rust_target: x86_64-pc-windows-msvc

steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.rust_target }}

- name: Build pg0 CLI (Unix)
if: runner.os != 'Windows'
env:
BUNDLE_POSTGRESQL: "true"
run: |
cargo build --release --target ${{ matrix.rust_target }}
ls -la target/${{ matrix.rust_target }}/release/pg0*

- name: Build pg0 CLI (Windows)
if: runner.os == 'Windows'
env:
BUNDLE_POSTGRESQL: "true"
run: |
cargo build --release --target ${{ matrix.rust_target }}
dir target\${{ matrix.rust_target }}\release\pg0*

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Build wheel (Unix)
if: runner.os != 'Windows'
working-directory: sdk/python
env:
PG0_BINARY_PATH: ${{ github.workspace }}/target/${{ matrix.rust_target }}/release/pg0
run: uv build --wheel

- name: Build wheel (Windows)
if: runner.os == 'Windows'
working-directory: sdk/python
env:
PG0_BINARY_PATH: ${{ github.workspace }}\target\${{ matrix.rust_target }}\release\pg0.exe
run: uv build --wheel

- name: Rename wheel to platform-specific
working-directory: sdk/python/dist
run: |
for f in *.whl; do
newname=$(echo "$f" | sed 's/py3-none-any/py3-none-${{ matrix.wheel_platform }}/g')
if [ "$f" != "$newname" ]; then
echo "Renaming $f -> $newname"
mv "$f" "$newname"
fi
done
ls -la
shell: bash

- name: Test wheel (Unix)
if: inputs.test-wheels && runner.os != 'Windows'
working-directory: sdk/python
run: |
uv venv test-env
source test-env/bin/activate
pip install dist/*.whl

python -c "
from pg0 import _get_bundled_binary, Pg0
bundled = _get_bundled_binary()
assert bundled is not None, 'Bundled binary not found!'
assert bundled.exists(), f'Bundled binary does not exist: {bundled}'
print(f'Bundled binary found: {bundled}')

pg = Pg0(name='wheel-test')
info = pg.start()
print(f'Started PostgreSQL: {info.uri}')
pg.stop()
pg.drop()
print('Wheel test passed!')
"

- name: Test wheel (Windows)
if: inputs.test-wheels && runner.os == 'Windows'
working-directory: sdk/python
run: |
uv venv test-env
test-env\Scripts\activate
pip install (Get-ChildItem dist\*.whl).FullName

python -c "
from pg0 import _get_bundled_binary, Pg0
bundled = _get_bundled_binary()
assert bundled is not None, 'Bundled binary not found!'
assert bundled.exists(), f'Bundled binary does not exist: {bundled}'
print(f'Bundled binary found: {bundled}')

pg = Pg0(name='wheel-test')
info = pg.start()
print(f'Started PostgreSQL: {info.uri}')
pg.stop()
pg.drop()
print('Wheel test passed!')
"
shell: pwsh

- name: Upload wheel artifact
if: inputs.upload-artifacts
uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.platform }}
path: sdk/python/dist/*.whl

build-sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Build sdist
working-directory: sdk/python
run: uv build --sdist

- name: Upload sdist artifact
if: inputs.upload-artifacts
uses: actions/upload-artifact@v4
with:
name: sdist
path: sdk/python/dist/*.tar.gz
85 changes: 27 additions & 58 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
name: pg0-macos
path: target/release/pg0

sdk-python:
name: Python SDK Tests
sdk-tests:
name: SDK Tests (macOS)
needs: build
runs-on: macos-latest
steps:
Expand All @@ -49,77 +49,46 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Install dependencies
- name: Run Python SDK tests
working-directory: sdk/python
run: uv sync --dev

- name: Run tests
working-directory: sdk/python
run: |
export PATH="$HOME/.local/bin:$PATH"
uv run pytest tests/ -v

sdk-node:
name: Node.js SDK Tests
needs: build
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- name: Download CLI
uses: actions/download-artifact@v4
with:
name: pg0-macos
path: ~/.local/bin

- name: Make CLI executable
run: chmod +x ~/.local/bin/pg0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
working-directory: sdk/node
run: npm install

- name: Run tests
working-directory: sdk/node
run: |
export PATH="$HOME/.local/bin:$PATH"
npm test
uv pip install --system -e ".[dev]"
pytest tests/ -v

# Docker tests - one job per platform, runs both CLI and Python SDK tests
# Note: ARM64 tests are skipped because QEMU emulation is too slow for PostgreSQL setup
docker-tests:
name: Docker Tests (${{ matrix.platform }})
runs-on: ${{ matrix.runner }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- platform: debian-amd64
runner: ubuntu-latest
script: docker-tests/test_debian_amd64.sh
- platform: debian-arm64
runner: ubuntu-latest
script: docker-tests/test_debian_arm64.sh
cli_script: docker-tests/test_debian_amd64.sh
python_script: docker-tests/python/test_debian_amd64.sh
- platform: alpine-amd64
runner: ubuntu-latest
script: docker-tests/test_alpine_amd64.sh
- platform: alpine-arm64
runner: ubuntu-latest
script: docker-tests/test_alpine_arm64.sh
cli_script: docker-tests/test_alpine_amd64.sh
python_script: docker-tests/python/test_alpine_amd64.sh

steps:
- uses: actions/checkout@v4

- name: Set up QEMU (for ARM64 emulation)
if: contains(matrix.platform, 'arm64')
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Run CLI Docker test
run: |
chmod +x ${{ matrix.cli_script }}
bash ${{ matrix.cli_script }}

- name: Run Docker test
- name: Run Python SDK Docker test
run: |
chmod +x ${{ matrix.script }}
bash ${{ matrix.script }}
chmod +x ${{ matrix.python_script }}
bash ${{ matrix.python_script }}

# Python wheel builds - test that wheel building works
python-wheels:
name: Python Wheels
uses: ./.github/workflows/build-python-wheels.yml
with:
upload-artifacts: false
test-wheels: true
Loading
Loading