|
| 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 |
0 commit comments