|
| 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 | +# First publish: add repo secrets PYPI_API_TOKEN and/or TEST_PYPI_API_TOKEN (from pypi.org / test.pypi.org); |
| 23 | +# CI will use them. After Trusted Publishing is set up on PyPI/TestPyPI, you can remove the secrets. |
| 24 | + |
| 25 | +name: Release Python |
| 26 | + |
| 27 | +on: |
| 28 | + push: |
| 29 | + tags: |
| 30 | + - "*" |
| 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 | + sdist: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Install protoc |
| 46 | + run: sudo apt-get update && sudo apt-get install -y protobuf-compiler |
| 47 | + |
| 48 | + - uses: PyO3/maturin-action@v1 |
| 49 | + with: |
| 50 | + working-directory: bindings/python |
| 51 | + command: sdist |
| 52 | + args: -o dist |
| 53 | + |
| 54 | + - name: Upload sdist |
| 55 | + uses: actions/upload-artifact@v4 |
| 56 | + with: |
| 57 | + name: wheels-sdist |
| 58 | + path: bindings/python/dist |
| 59 | + |
| 60 | + wheels: |
| 61 | + runs-on: ${{ matrix.os }} |
| 62 | + strategy: |
| 63 | + matrix: |
| 64 | + include: |
| 65 | + - { os: windows-latest } |
| 66 | + - { os: macos-15-intel, target: "x86_64-apple-darwin" } |
| 67 | + - { os: macos-15, target: "aarch64-apple-darwin" } |
| 68 | + - { os: ubuntu-latest, target: "x86_64" } |
| 69 | + - { os: ubuntu-latest, target: "aarch64", manylinux: "manylinux_2_28" } |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: Install protoc (Linux) |
| 74 | + if: runner.os == 'Linux' |
| 75 | + run: sudo apt-get update && sudo apt-get install -y protobuf-compiler |
| 76 | + |
| 77 | + - name: Install protoc (macOS) |
| 78 | + if: runner.os == 'macOS' |
| 79 | + run: brew install protobuf |
| 80 | + |
| 81 | + - name: Install protoc (Windows) |
| 82 | + if: runner.os == 'Windows' |
| 83 | + run: choco install protobuf -y |
| 84 | + shell: pwsh |
| 85 | + |
| 86 | + - uses: PyO3/maturin-action@v1 |
| 87 | + with: |
| 88 | + working-directory: bindings/python |
| 89 | + target: ${{ matrix.target }} |
| 90 | + command: build |
| 91 | + args: --release -o dist -i python3.11 |
| 92 | + manylinux: ${{ matrix.manylinux || 'auto' }} |
| 93 | + - uses: PyO3/maturin-action@v1 |
| 94 | + with: |
| 95 | + working-directory: bindings/python |
| 96 | + target: ${{ matrix.target }} |
| 97 | + command: build |
| 98 | + args: --release -o dist -i python3.12 |
| 99 | + manylinux: ${{ matrix.manylinux || 'auto' }} |
| 100 | + |
| 101 | + - name: Upload wheels |
| 102 | + uses: actions/upload-artifact@v4 |
| 103 | + with: |
| 104 | + name: wheels-${{ matrix.os }}-${{ matrix.target || 'native' }} |
| 105 | + path: bindings/python/dist |
| 106 | + |
| 107 | + release: |
| 108 | + name: Publish to PyPI |
| 109 | + runs-on: ubuntu-latest |
| 110 | + permissions: |
| 111 | + contents: read |
| 112 | + id-token: write |
| 113 | + needs: [sdist, wheels] |
| 114 | + if: startsWith(github.ref, 'refs/tags/') |
| 115 | + steps: |
| 116 | + - uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + pattern: wheels-* |
| 119 | + merge-multiple: true |
| 120 | + path: bindings/python/dist |
| 121 | + |
| 122 | + - name: Publish to TestPyPI (pre-release tags) |
| 123 | + if: contains(github.ref, '-') |
| 124 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 125 | + with: |
| 126 | + repository-url: https://test.pypi.org/legacy/ |
| 127 | + skip-existing: true |
| 128 | + packages-dir: bindings/python/dist |
| 129 | + password: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 130 | + |
| 131 | + - name: Publish to PyPI (release tags) |
| 132 | + if: ${{ !contains(github.ref, '-') }} |
| 133 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 134 | + with: |
| 135 | + skip-existing: true |
| 136 | + packages-dir: bindings/python/dist |
| 137 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments