|
| 1 | +# Publish the `docling-rs` PyPI package (the PyO3 Python bindings in |
| 2 | +# crates/docling-py) for a chosen release. Like the npm package, the bindings are |
| 3 | +# a compiled native extension, so it can't be a one-line `twine upload`: wheels |
| 4 | +# are built on a matrix of runners (one abi3 wheel per OS/arch — `abi3-py39`, so |
| 5 | +# a single wheel covers every Python ≥ 3.9), an sdist is built once, and a |
| 6 | +# publish job uploads them all to PyPI. |
| 7 | +# |
| 8 | +# Trigger: manual only (workflow_dispatch), mirroring npm-publish.yml. By default |
| 9 | +# it builds the checked-out ref at the version already declared in |
| 10 | +# crates/docling-py/pyproject.toml; pass `version` (or a release `tag`) to |
| 11 | +# override. Run it from the Actions tab (or `gh workflow run pypi-publish.yml`, |
| 12 | +# optionally `-f version=0.16.0`). |
| 13 | +# |
| 14 | +# Requires one repository secret: PYPI_TOKEN — a PyPI API token with publish |
| 15 | +# rights to the `docling-rs` project. (To switch to OIDC trusted publishing |
| 16 | +# instead, drop the `password:` line and add `id-token: write` + an |
| 17 | +# `environment:` to the publish job, as docling-core's pypi.yml does.) |
| 18 | +# |
| 19 | +# The ONNX Runtime is statically bundled at build time (`ort` `download-binaries`) |
| 20 | +# and pdfium is loaded at runtime from the model cache, so the wheels are |
| 21 | +# self-contained for the declarative path and need no extra native setup here — |
| 22 | +# same story as the npm build. |
| 23 | + |
| 24 | +name: pypi publish |
| 25 | + |
| 26 | +on: |
| 27 | + workflow_dispatch: |
| 28 | + inputs: |
| 29 | + tag: |
| 30 | + description: "Release tag to build (e.g. v0.16.0). Blank = current ref." |
| 31 | + required: false |
| 32 | + default: "" |
| 33 | + version: |
| 34 | + description: "Override the PyPI version (e.g. 0.16.0). Blank = tag, or the version in pyproject.toml." |
| 35 | + required: false |
| 36 | + default: "" |
| 37 | + |
| 38 | +concurrency: |
| 39 | + group: pypi-publish-${{ inputs.tag || github.ref }} |
| 40 | + cancel-in-progress: false |
| 41 | + |
| 42 | +defaults: |
| 43 | + run: |
| 44 | + working-directory: crates/docling-py |
| 45 | + |
| 46 | +jobs: |
| 47 | + wheels: |
| 48 | + name: wheel ${{ matrix.target }} |
| 49 | + runs-on: ${{ matrix.host }} |
| 50 | + strategy: |
| 51 | + fail-fast: false |
| 52 | + matrix: |
| 53 | + include: |
| 54 | + - target: x86_64-unknown-linux-gnu |
| 55 | + host: ubuntu-22.04 |
| 56 | + manylinux: "2_28" |
| 57 | + # Native ARM64 Linux runner — avoids cross-compiling the ONNX/ort build. |
| 58 | + - target: aarch64-unknown-linux-gnu |
| 59 | + host: ubuntu-24.04-arm |
| 60 | + manylinux: "2_28" |
| 61 | + - target: x86_64-pc-windows-msvc |
| 62 | + host: windows-latest |
| 63 | + manylinux: "auto" |
| 64 | + # macOS wheels are omitted: GitHub-hosted macOS runners are blocked in |
| 65 | + # this environment and darwin can't be cross-compiled on Linux (needs |
| 66 | + # the Apple SDK). macOS users build from source with `maturin develop`. |
| 67 | + # Re-add when runners are available: |
| 68 | + # - { target: aarch64-apple-darwin, host: macos-14, manylinux: "auto" } |
| 69 | + # - { target: x86_64-apple-darwin, host: macos-14, manylinux: "auto" } |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + with: |
| 73 | + ref: ${{ inputs.tag || github.ref }} |
| 74 | + |
| 75 | + # Version override: patch [project].version in pyproject.toml before the |
| 76 | + # build so it lands in the wheel metadata/filename. No override → keep the |
| 77 | + # version already declared in the file. |
| 78 | + - name: Resolve version |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + v="${{ inputs.version }}" |
| 82 | + if [ -z "$v" ] && [ -n "${{ inputs.tag }}" ]; then v="${{ inputs.tag }}"; v="${v#v}"; fi |
| 83 | + if [ -n "$v" ]; then |
| 84 | + sed -i.bak -E "0,/^version = \".*\"/s//version = \"$v\"/" pyproject.toml && rm -f pyproject.toml.bak |
| 85 | + echo "Building docling-rs $v" |
| 86 | + else |
| 87 | + echo "Building docling-rs $(grep -m1 '^version = ' pyproject.toml | sed -E 's/.*"([^"]+)".*/\1/') (from pyproject.toml)" |
| 88 | + fi |
| 89 | +
|
| 90 | + - name: Build wheel |
| 91 | + uses: PyO3/maturin-action@v1 |
| 92 | + with: |
| 93 | + target: ${{ matrix.target }} |
| 94 | + manylinux: ${{ matrix.manylinux }} |
| 95 | + args: --release --out dist |
| 96 | + sccache: "true" |
| 97 | + working-directory: crates/docling-py |
| 98 | + |
| 99 | + - name: Upload wheel |
| 100 | + uses: actions/upload-artifact@v4 |
| 101 | + with: |
| 102 | + name: wheel-${{ matrix.target }} |
| 103 | + path: crates/docling-py/dist/*.whl |
| 104 | + if-no-files-found: error |
| 105 | + |
| 106 | + sdist: |
| 107 | + name: sdist |
| 108 | + runs-on: ubuntu-latest |
| 109 | + steps: |
| 110 | + - uses: actions/checkout@v4 |
| 111 | + with: |
| 112 | + ref: ${{ inputs.tag || github.ref }} |
| 113 | + - name: Resolve version |
| 114 | + shell: bash |
| 115 | + run: | |
| 116 | + v="${{ inputs.version }}" |
| 117 | + if [ -z "$v" ] && [ -n "${{ inputs.tag }}" ]; then v="${{ inputs.tag }}"; v="${v#v}"; fi |
| 118 | + if [ -n "$v" ]; then |
| 119 | + sed -i.bak -E "0,/^version = \".*\"/s//version = \"$v\"/" pyproject.toml && rm -f pyproject.toml.bak |
| 120 | + fi |
| 121 | + - name: Build sdist |
| 122 | + uses: PyO3/maturin-action@v1 |
| 123 | + with: |
| 124 | + command: sdist |
| 125 | + args: --out dist |
| 126 | + working-directory: crates/docling-py |
| 127 | + - name: Upload sdist |
| 128 | + uses: actions/upload-artifact@v4 |
| 129 | + with: |
| 130 | + name: sdist |
| 131 | + path: crates/docling-py/dist/*.tar.gz |
| 132 | + if-no-files-found: error |
| 133 | + |
| 134 | + publish: |
| 135 | + name: publish to PyPI |
| 136 | + needs: [wheels, sdist] |
| 137 | + runs-on: ubuntu-latest |
| 138 | + steps: |
| 139 | + # All wheels + the sdist → a single dist/ for the upload. |
| 140 | + - name: Download artifacts |
| 141 | + uses: actions/download-artifact@v4 |
| 142 | + with: |
| 143 | + path: dist |
| 144 | + merge-multiple: true |
| 145 | + |
| 146 | + - name: Publish to PyPI |
| 147 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 148 | + with: |
| 149 | + packages-dir: dist |
| 150 | + password: ${{ secrets.PYPI_TOKEN }} |
| 151 | + # Idempotent re-runs: don't fail if a version is already uploaded. |
| 152 | + skip-existing: true |
0 commit comments