|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +# Publish the fluss Python binding to PyPI. |
| 19 | +# Trigger: push tag only (e.g. v0.1.0). |
| 20 | +# Pre-release tags (containing '-') publish to TestPyPI; release tags publish to PyPI. |
| 21 | +# |
| 22 | +# Token auth: set repo variable PYPI_USE_TOKEN_AUTH = 'true' and add secrets PYPI_API_TOKEN / TEST_PYPI_API_TOKEN. |
| 23 | +# Trusted Publishing (OIDC): leave PYPI_USE_TOKEN_AUTH unset; do not pass password so the action uses OIDC. |
| 24 | + |
| 25 | +name: Release Python |
| 26 | + |
| 27 | +on: |
| 28 | + push: |
| 29 | + tags: |
| 30 | + - "v*" # Only version-like tags (e.g. v0.1.0, v0.1.0-rc1); avoids running on arbitrary tags |
| 31 | + |
| 32 | +concurrency: |
| 33 | + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} |
| 34 | + cancel-in-progress: true |
| 35 | + |
| 36 | +permissions: |
| 37 | + contents: read |
| 38 | + |
| 39 | +jobs: |
| 40 | + version-check: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + - uses: ./.github/actions/verify-tag-version |
| 45 | + |
| 46 | + sdist: |
| 47 | + runs-on: ubuntu-latest |
| 48 | + needs: [version-check] |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v4 |
| 51 | + |
| 52 | + - name: Install protoc |
| 53 | + run: sudo apt-get update && sudo apt-get install -y protobuf-compiler |
| 54 | + |
| 55 | + - uses: PyO3/maturin-action@v1 |
| 56 | + with: |
| 57 | + working-directory: bindings/python |
| 58 | + command: sdist |
| 59 | + args: -o dist |
| 60 | + |
| 61 | + - name: Upload sdist |
| 62 | + uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: wheels-sdist |
| 65 | + path: bindings/python/dist |
| 66 | + |
| 67 | + wheels: |
| 68 | + runs-on: ${{ matrix.os }} |
| 69 | + needs: [version-check] |
| 70 | + strategy: |
| 71 | + matrix: |
| 72 | + include: |
| 73 | + - { os: windows-latest } |
| 74 | + - { os: macos-15-intel, target: "x86_64-apple-darwin" } |
| 75 | + - { os: macos-15, target: "aarch64-apple-darwin" } |
| 76 | + - { os: ubuntu-latest, target: "x86_64" } |
| 77 | + - { os: ubuntu-latest, target: "aarch64", manylinux: "manylinux_2_28" } |
| 78 | + steps: |
| 79 | + - uses: actions/checkout@v4 |
| 80 | + |
| 81 | + - name: Install protoc (Linux) |
| 82 | + if: runner.os == 'Linux' |
| 83 | + run: sudo apt-get update && sudo apt-get install -y protobuf-compiler |
| 84 | + |
| 85 | + - name: Install protoc (macOS) |
| 86 | + if: runner.os == 'macOS' |
| 87 | + run: brew install protobuf |
| 88 | + |
| 89 | + - name: Install protoc (Windows) |
| 90 | + if: runner.os == 'Windows' |
| 91 | + run: choco install protobuf -y |
| 92 | + shell: pwsh |
| 93 | + |
| 94 | + - uses: PyO3/maturin-action@v1 |
| 95 | + with: |
| 96 | + working-directory: bindings/python |
| 97 | + target: ${{ matrix.target }} |
| 98 | + command: build |
| 99 | + args: --release -o dist -i python3.9 |
| 100 | + manylinux: ${{ matrix.manylinux || 'auto' }} |
| 101 | + - uses: PyO3/maturin-action@v1 |
| 102 | + with: |
| 103 | + working-directory: bindings/python |
| 104 | + target: ${{ matrix.target }} |
| 105 | + command: build |
| 106 | + args: --release -o dist -i python3.10 |
| 107 | + manylinux: ${{ matrix.manylinux || 'auto' }} |
| 108 | + - uses: PyO3/maturin-action@v1 |
| 109 | + with: |
| 110 | + working-directory: bindings/python |
| 111 | + target: ${{ matrix.target }} |
| 112 | + command: build |
| 113 | + args: --release -o dist -i python3.11 |
| 114 | + manylinux: ${{ matrix.manylinux || 'auto' }} |
| 115 | + - uses: PyO3/maturin-action@v1 |
| 116 | + with: |
| 117 | + working-directory: bindings/python |
| 118 | + target: ${{ matrix.target }} |
| 119 | + command: build |
| 120 | + args: --release -o dist -i python3.12 |
| 121 | + manylinux: ${{ matrix.manylinux || 'auto' }} |
| 122 | + |
| 123 | + - name: Upload wheels |
| 124 | + uses: actions/upload-artifact@v4 |
| 125 | + with: |
| 126 | + name: wheels-${{ matrix.os }}-${{ matrix.target || 'native' }} |
| 127 | + path: bindings/python/dist |
| 128 | + |
| 129 | + release: |
| 130 | + name: Publish to PyPI |
| 131 | + runs-on: ubuntu-latest |
| 132 | + permissions: |
| 133 | + contents: read |
| 134 | + id-token: write |
| 135 | + needs: [version-check, sdist, wheels] |
| 136 | + if: startsWith(github.ref, 'refs/tags/') |
| 137 | + steps: |
| 138 | + - uses: actions/download-artifact@v4 |
| 139 | + with: |
| 140 | + pattern: wheels-* |
| 141 | + merge-multiple: true |
| 142 | + path: bindings/python/dist |
| 143 | + |
| 144 | + - name: Publish to TestPyPI (token) |
| 145 | + if: contains(github.ref, '-') && vars.PYPI_USE_TOKEN_AUTH == 'true' |
| 146 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 147 | + with: |
| 148 | + repository-url: https://test.pypi.org/legacy/ |
| 149 | + skip-existing: true |
| 150 | + packages-dir: bindings/python/dist |
| 151 | + password: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 152 | + |
| 153 | + - name: Publish to TestPyPI (Trusted Publishing) |
| 154 | + if: contains(github.ref, '-') && vars.PYPI_USE_TOKEN_AUTH != 'true' |
| 155 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 156 | + with: |
| 157 | + repository-url: https://test.pypi.org/legacy/ |
| 158 | + skip-existing: true |
| 159 | + packages-dir: bindings/python/dist |
| 160 | + |
| 161 | + - name: Publish to PyPI (token) |
| 162 | + if: ${{ !contains(github.ref, '-') && vars.PYPI_USE_TOKEN_AUTH == 'true' }} |
| 163 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 164 | + with: |
| 165 | + skip-existing: true |
| 166 | + packages-dir: bindings/python/dist |
| 167 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 168 | + |
| 169 | + - name: Publish to PyPI (Trusted Publishing) |
| 170 | + if: ${{ !contains(github.ref, '-') && vars.PYPI_USE_TOKEN_AUTH != 'true' }} |
| 171 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 172 | + with: |
| 173 | + skip-existing: true |
| 174 | + packages-dir: bindings/python/dist |
0 commit comments