|
| 1 | +# PyPI publishing workflow for bashkit Python bindings |
| 2 | +# Builds pre-compiled wheels for all major platforms and publishes to PyPI. |
| 3 | +# Triggered alongside publish.yml on GitHub Release or manual dispatch. |
| 4 | +# Adapted from https://github.com/pydantic/monty CI wheel-building pattern. |
| 5 | +# |
| 6 | +# Prerequisites: |
| 7 | +# - PyPI trusted publisher configured for this repo + workflow |
| 8 | +# - GitHub environment "release-python" created in repo settings |
| 9 | + |
| 10 | +name: Publish Python |
| 11 | + |
| 12 | +on: |
| 13 | + release: |
| 14 | + types: [published] |
| 15 | + workflow_dispatch: |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +env: |
| 21 | + CARGO_TERM_COLOR: always |
| 22 | + PYTHON_VERSIONS: "3.9 3.10 3.11 3.12 3.13" |
| 23 | + |
| 24 | +jobs: |
| 25 | + # Source distribution (platform-independent) |
| 26 | + build-sdist: |
| 27 | + name: Build sdist |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v6 |
| 31 | + |
| 32 | + - uses: actions/setup-python@v6 |
| 33 | + with: |
| 34 | + python-version: "3.12" |
| 35 | + |
| 36 | + - uses: PyO3/maturin-action@v1 |
| 37 | + with: |
| 38 | + command: sdist |
| 39 | + args: --out dist |
| 40 | + rust-toolchain: stable |
| 41 | + working-directory: crates/bashkit-python |
| 42 | + |
| 43 | + - uses: actions/upload-artifact@v6 |
| 44 | + with: |
| 45 | + name: pypi_files-sdist |
| 46 | + path: crates/bashkit-python/dist |
| 47 | + |
| 48 | + # Pre-compiled binary wheels for each platform |
| 49 | + build: |
| 50 | + name: Build wheel - ${{ matrix.os }} (${{ matrix.target }}, ${{ matrix.manylinux || 'auto' }}) |
| 51 | + strategy: |
| 52 | + fail-fast: false |
| 53 | + matrix: |
| 54 | + include: |
| 55 | + # Linux glibc |
| 56 | + - os: linux |
| 57 | + target: x86_64 |
| 58 | + runs-on: ubuntu-latest |
| 59 | + - os: linux |
| 60 | + target: aarch64 |
| 61 | + runs-on: ubuntu-latest |
| 62 | + |
| 63 | + # Linux musl |
| 64 | + - os: linux |
| 65 | + target: x86_64 |
| 66 | + manylinux: musllinux_1_1 |
| 67 | + runs-on: ubuntu-latest |
| 68 | + - os: linux |
| 69 | + target: aarch64 |
| 70 | + manylinux: musllinux_1_1 |
| 71 | + runs-on: ubuntu-latest |
| 72 | + |
| 73 | + # macOS |
| 74 | + - os: macos |
| 75 | + target: x86_64 |
| 76 | + runs-on: macos-latest |
| 77 | + - os: macos |
| 78 | + target: aarch64 |
| 79 | + runs-on: macos-latest |
| 80 | + |
| 81 | + # Windows |
| 82 | + - os: windows |
| 83 | + target: x86_64 |
| 84 | + runs-on: windows-latest |
| 85 | + |
| 86 | + runs-on: ${{ matrix.runs-on }} |
| 87 | + steps: |
| 88 | + - uses: actions/checkout@v6 |
| 89 | + |
| 90 | + - uses: actions/setup-python@v6 |
| 91 | + with: |
| 92 | + python-version: "3.12" |
| 93 | + |
| 94 | + - name: Build wheels |
| 95 | + uses: PyO3/maturin-action@v1 |
| 96 | + with: |
| 97 | + target: ${{ matrix.target }} |
| 98 | + manylinux: ${{ matrix.manylinux || 'auto' }} |
| 99 | + args: --release --out dist -i ${{ env.PYTHON_VERSIONS }} |
| 100 | + rust-toolchain: stable |
| 101 | + docker-options: -e CI |
| 102 | + working-directory: crates/bashkit-python |
| 103 | + |
| 104 | + - uses: actions/upload-artifact@v6 |
| 105 | + with: |
| 106 | + name: pypi_files-${{ matrix.os }}-${{ matrix.target }}-${{ matrix.manylinux || 'manylinux' }} |
| 107 | + path: crates/bashkit-python/dist |
| 108 | + |
| 109 | + # Verify built artifacts |
| 110 | + inspect: |
| 111 | + name: Inspect artifacts |
| 112 | + needs: [build, build-sdist] |
| 113 | + runs-on: ubuntu-latest |
| 114 | + steps: |
| 115 | + - uses: actions/download-artifact@v7 |
| 116 | + with: |
| 117 | + pattern: pypi_files-* |
| 118 | + merge-multiple: true |
| 119 | + path: dist |
| 120 | + |
| 121 | + - name: List dist files |
| 122 | + run: | |
| 123 | + ls -lhR dist/ |
| 124 | + echo "---" |
| 125 | + echo "Total files: $(ls -1 dist/ | wc -l)" |
| 126 | +
|
| 127 | + - uses: astral-sh/setup-uv@v7 |
| 128 | + - run: uvx twine check dist/* |
| 129 | + |
| 130 | + # Smoke-test wheels on each OS |
| 131 | + test-builds: |
| 132 | + name: Test wheel on ${{ matrix.os }} |
| 133 | + needs: [build] |
| 134 | + strategy: |
| 135 | + fail-fast: false |
| 136 | + matrix: |
| 137 | + include: |
| 138 | + - os: linux |
| 139 | + runs-on: ubuntu-latest |
| 140 | + - os: macos |
| 141 | + runs-on: macos-latest |
| 142 | + - os: windows |
| 143 | + runs-on: windows-latest |
| 144 | + runs-on: ${{ matrix.runs-on }} |
| 145 | + steps: |
| 146 | + - uses: actions/setup-python@v6 |
| 147 | + with: |
| 148 | + python-version: "3.12" |
| 149 | + |
| 150 | + - uses: actions/download-artifact@v7 |
| 151 | + with: |
| 152 | + pattern: pypi_files-${{ matrix.os }}-* |
| 153 | + merge-multiple: true |
| 154 | + path: dist |
| 155 | + |
| 156 | + - name: Install from wheel |
| 157 | + run: pip install bashkit --no-index --find-links dist --force-reinstall |
| 158 | + |
| 159 | + - name: Smoke test |
| 160 | + run: python -c "from bashkit import BashTool; t = BashTool(); r = t.execute_sync('echo hello'); print(r); assert r.exit_code == 0" |
| 161 | + |
| 162 | + # Publish to PyPI using trusted publishing (OIDC) |
| 163 | + publish: |
| 164 | + name: Publish to PyPI |
| 165 | + needs: [inspect, test-builds] |
| 166 | + if: success() |
| 167 | + runs-on: ubuntu-latest |
| 168 | + |
| 169 | + environment: |
| 170 | + name: release-python |
| 171 | + |
| 172 | + permissions: |
| 173 | + id-token: write |
| 174 | + |
| 175 | + steps: |
| 176 | + - uses: actions/download-artifact@v7 |
| 177 | + with: |
| 178 | + pattern: pypi_files-* |
| 179 | + merge-multiple: true |
| 180 | + path: dist |
| 181 | + |
| 182 | + - name: List dist files |
| 183 | + run: ls -lhR dist/ |
| 184 | + |
| 185 | + - uses: astral-sh/setup-uv@v7 |
| 186 | + |
| 187 | + - name: Publish to PyPI |
| 188 | + run: uv publish --trusted-publishing always dist/* |
0 commit comments