Skip to content

Commit 4483ec5

Browse files
authored
add bundled cli to python (#1)
* add bundled cli to python * add bundled cli to python * add bundled cli to python * better jobs * better jobs * better jobs * better jobs
1 parent 7a25d7d commit 4483ec5

21 files changed

+1265
-127
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
name: Build Python Wheels
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
upload-artifacts:
7+
description: 'Upload wheel artifacts'
8+
required: false
9+
default: true
10+
type: boolean
11+
test-wheels:
12+
description: 'Test the built wheels'
13+
required: false
14+
default: true
15+
type: boolean
16+
17+
jobs:
18+
build-wheels:
19+
name: Build wheel (${{ matrix.platform }})
20+
runs-on: ${{ matrix.os }}
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
include:
25+
# macOS Apple Silicon
26+
- os: macos-14
27+
platform: darwin-aarch64
28+
wheel_platform: macosx_14_0_arm64
29+
rust_target: aarch64-apple-darwin
30+
31+
# Linux x86_64 glibc
32+
- os: ubuntu-22.04
33+
platform: linux-x86_64-gnu
34+
wheel_platform: manylinux_2_35_x86_64
35+
rust_target: x86_64-unknown-linux-gnu
36+
37+
# Linux ARM64 glibc
38+
- os: ubuntu-22.04-arm
39+
platform: linux-aarch64-gnu
40+
wheel_platform: manylinux_2_35_aarch64
41+
rust_target: aarch64-unknown-linux-gnu
42+
43+
# Windows x64
44+
- os: windows-latest
45+
platform: windows-x86_64
46+
wheel_platform: win_amd64
47+
rust_target: x86_64-pc-windows-msvc
48+
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- name: Install Rust
53+
uses: dtolnay/rust-toolchain@stable
54+
with:
55+
targets: ${{ matrix.rust_target }}
56+
57+
- name: Build pg0 CLI (Unix)
58+
if: runner.os != 'Windows'
59+
env:
60+
BUNDLE_POSTGRESQL: "true"
61+
run: |
62+
cargo build --release --target ${{ matrix.rust_target }}
63+
ls -la target/${{ matrix.rust_target }}/release/pg0*
64+
65+
- name: Build pg0 CLI (Windows)
66+
if: runner.os == 'Windows'
67+
env:
68+
BUNDLE_POSTGRESQL: "true"
69+
run: |
70+
cargo build --release --target ${{ matrix.rust_target }}
71+
dir target\${{ matrix.rust_target }}\release\pg0*
72+
73+
- name: Set up Python
74+
uses: actions/setup-python@v5
75+
with:
76+
python-version: '3.11'
77+
78+
- name: Install uv
79+
uses: astral-sh/setup-uv@v4
80+
81+
- name: Build wheel (Unix)
82+
if: runner.os != 'Windows'
83+
working-directory: sdk/python
84+
env:
85+
PG0_BINARY_PATH: ${{ github.workspace }}/target/${{ matrix.rust_target }}/release/pg0
86+
run: uv build --wheel
87+
88+
- name: Build wheel (Windows)
89+
if: runner.os == 'Windows'
90+
working-directory: sdk/python
91+
env:
92+
PG0_BINARY_PATH: ${{ github.workspace }}\target\${{ matrix.rust_target }}\release\pg0.exe
93+
run: uv build --wheel
94+
95+
- name: Rename wheel to platform-specific
96+
working-directory: sdk/python/dist
97+
run: |
98+
for f in *.whl; do
99+
newname=$(echo "$f" | sed 's/py3-none-any/py3-none-${{ matrix.wheel_platform }}/g')
100+
if [ "$f" != "$newname" ]; then
101+
echo "Renaming $f -> $newname"
102+
mv "$f" "$newname"
103+
fi
104+
done
105+
ls -la
106+
shell: bash
107+
108+
- name: Test wheel (Unix)
109+
if: inputs.test-wheels && runner.os != 'Windows'
110+
working-directory: sdk/python
111+
run: |
112+
uv venv test-env
113+
source test-env/bin/activate
114+
pip install dist/*.whl
115+
116+
python -c "
117+
from pg0 import _get_bundled_binary, Pg0
118+
bundled = _get_bundled_binary()
119+
assert bundled is not None, 'Bundled binary not found!'
120+
assert bundled.exists(), f'Bundled binary does not exist: {bundled}'
121+
print(f'Bundled binary found: {bundled}')
122+
123+
pg = Pg0(name='wheel-test')
124+
info = pg.start()
125+
print(f'Started PostgreSQL: {info.uri}')
126+
pg.stop()
127+
pg.drop()
128+
print('Wheel test passed!')
129+
"
130+
131+
- name: Test wheel (Windows)
132+
if: inputs.test-wheels && runner.os == 'Windows'
133+
working-directory: sdk/python
134+
run: |
135+
uv venv test-env
136+
test-env\Scripts\activate
137+
pip install (Get-ChildItem dist\*.whl).FullName
138+
139+
python -c "
140+
from pg0 import _get_bundled_binary, Pg0
141+
bundled = _get_bundled_binary()
142+
assert bundled is not None, 'Bundled binary not found!'
143+
assert bundled.exists(), f'Bundled binary does not exist: {bundled}'
144+
print(f'Bundled binary found: {bundled}')
145+
146+
pg = Pg0(name='wheel-test')
147+
info = pg.start()
148+
print(f'Started PostgreSQL: {info.uri}')
149+
pg.stop()
150+
pg.drop()
151+
print('Wheel test passed!')
152+
"
153+
shell: pwsh
154+
155+
- name: Upload wheel artifact
156+
if: inputs.upload-artifacts
157+
uses: actions/upload-artifact@v4
158+
with:
159+
name: wheel-${{ matrix.platform }}
160+
path: sdk/python/dist/*.whl
161+
162+
build-sdist:
163+
name: Build source distribution
164+
runs-on: ubuntu-latest
165+
steps:
166+
- uses: actions/checkout@v4
167+
168+
- name: Set up Python
169+
uses: actions/setup-python@v5
170+
with:
171+
python-version: '3.11'
172+
173+
- name: Install uv
174+
uses: astral-sh/setup-uv@v4
175+
176+
- name: Build sdist
177+
working-directory: sdk/python
178+
run: uv build --sdist
179+
180+
- name: Upload sdist artifact
181+
if: inputs.upload-artifacts
182+
uses: actions/upload-artifact@v4
183+
with:
184+
name: sdist
185+
path: sdk/python/dist/*.tar.gz

.github/workflows/ci.yml

Lines changed: 27 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
name: pg0-macos
2626
path: target/release/pg0
2727

28-
sdk-python:
29-
name: Python SDK Tests
28+
sdk-tests:
29+
name: SDK Tests (macOS)
3030
needs: build
3131
runs-on: macos-latest
3232
steps:
@@ -49,77 +49,46 @@ jobs:
4949
- name: Install uv
5050
uses: astral-sh/setup-uv@v4
5151

52-
- name: Install dependencies
52+
- name: Run Python SDK tests
5353
working-directory: sdk/python
54-
run: uv sync --dev
55-
56-
- name: Run tests
57-
working-directory: sdk/python
58-
run: |
59-
export PATH="$HOME/.local/bin:$PATH"
60-
uv run pytest tests/ -v
61-
62-
sdk-node:
63-
name: Node.js SDK Tests
64-
needs: build
65-
runs-on: macos-latest
66-
steps:
67-
- uses: actions/checkout@v4
68-
69-
- name: Download CLI
70-
uses: actions/download-artifact@v4
71-
with:
72-
name: pg0-macos
73-
path: ~/.local/bin
74-
75-
- name: Make CLI executable
76-
run: chmod +x ~/.local/bin/pg0
77-
78-
- name: Set up Node.js
79-
uses: actions/setup-node@v4
80-
with:
81-
node-version: "20"
82-
83-
- name: Install dependencies
84-
working-directory: sdk/node
85-
run: npm install
86-
87-
- name: Run tests
88-
working-directory: sdk/node
8954
run: |
9055
export PATH="$HOME/.local/bin:$PATH"
91-
npm test
56+
uv pip install --system -e ".[dev]"
57+
pytest tests/ -v
9258
59+
# Docker tests - one job per platform, runs both CLI and Python SDK tests
60+
# Note: ARM64 tests are skipped because QEMU emulation is too slow for PostgreSQL setup
9361
docker-tests:
9462
name: Docker Tests (${{ matrix.platform }})
95-
runs-on: ${{ matrix.runner }}
63+
runs-on: ubuntu-latest
9664
strategy:
9765
fail-fast: false
9866
matrix:
9967
include:
10068
- platform: debian-amd64
101-
runner: ubuntu-latest
102-
script: docker-tests/test_debian_amd64.sh
103-
- platform: debian-arm64
104-
runner: ubuntu-latest
105-
script: docker-tests/test_debian_arm64.sh
69+
cli_script: docker-tests/test_debian_amd64.sh
70+
python_script: docker-tests/python/test_debian_amd64.sh
10671
- platform: alpine-amd64
107-
runner: ubuntu-latest
108-
script: docker-tests/test_alpine_amd64.sh
109-
- platform: alpine-arm64
110-
runner: ubuntu-latest
111-
script: docker-tests/test_alpine_arm64.sh
72+
cli_script: docker-tests/test_alpine_amd64.sh
73+
python_script: docker-tests/python/test_alpine_amd64.sh
11274

11375
steps:
11476
- uses: actions/checkout@v4
11577

116-
- name: Set up QEMU (for ARM64 emulation)
117-
if: contains(matrix.platform, 'arm64')
118-
uses: docker/setup-qemu-action@v3
119-
with:
120-
platforms: arm64
78+
- name: Run CLI Docker test
79+
run: |
80+
chmod +x ${{ matrix.cli_script }}
81+
bash ${{ matrix.cli_script }}
12182
122-
- name: Run Docker test
83+
- name: Run Python SDK Docker test
12384
run: |
124-
chmod +x ${{ matrix.script }}
125-
bash ${{ matrix.script }}
85+
chmod +x ${{ matrix.python_script }}
86+
bash ${{ matrix.python_script }}
87+
88+
# Python wheel builds - test that wheel building works
89+
python-wheels:
90+
name: Python Wheels
91+
uses: ./.github/workflows/build-python-wheels.yml
92+
with:
93+
upload-artifacts: false
94+
test-wheels: true

0 commit comments

Comments
 (0)