|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Triggers on version tags like v0.1.8, v1.0.0, etc. |
| 7 | + workflow_dispatch: # Allow manual triggering |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + RUST_BACKTRACE: 1 |
| 12 | + |
| 13 | +jobs: |
| 14 | + build_wheels: |
| 15 | + name: Build wheels on ${{ matrix.os }} |
| 16 | + runs-on: ${{ matrix.os }} |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Install Rust |
| 26 | + uses: dtolnay/rust-toolchain@master |
| 27 | + with: |
| 28 | + toolchain: stable |
| 29 | + components: rustfmt, clippy |
| 30 | + |
| 31 | + - name: Cache Rust dependencies |
| 32 | + uses: actions/cache@v4 |
| 33 | + with: |
| 34 | + path: | |
| 35 | + ~/.cargo/registry |
| 36 | + ~/.cargo/git |
| 37 | + target |
| 38 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 39 | + restore-keys: | |
| 40 | + ${{ runner.os }}-cargo- |
| 41 | +
|
| 42 | + - name: Install Python |
| 43 | + uses: actions/setup-python@v4 |
| 44 | + with: |
| 45 | + python-version: '3.11' |
| 46 | + |
| 47 | + - name: Install cibuildwheel |
| 48 | + run: | |
| 49 | + python -m pip install --upgrade pip |
| 50 | + pip install cibuildwheel |
| 51 | +
|
| 52 | + - name: Build wheels |
| 53 | + run: cibuildwheel --platform ${{ matrix.os == 'ubuntu-latest' && 'linux' || matrix.os == 'windows-latest' && 'windows' || 'macos' }} |
| 54 | + env: |
| 55 | + CIBW_BUILD: cp39-* cp310-* cp311-* cp312-* |
| 56 | + CIBW_BEFORE_BUILD: pip install maturin |
| 57 | + CIBW_BUILD_COMMAND: maturin build --release --interpreter {python} |
| 58 | + |
| 59 | + - name: Upload wheels |
| 60 | + uses: actions/upload-artifact@v4 |
| 61 | + with: |
| 62 | + name: wheels-${{ matrix.os }} |
| 63 | + path: ./wheelhouse/*.whl |
| 64 | + |
| 65 | + build_sdist: |
| 66 | + name: Build source distribution |
| 67 | + runs-on: ubuntu-latest |
| 68 | + steps: |
| 69 | + - name: Checkout code |
| 70 | + uses: actions/checkout@v4 |
| 71 | + |
| 72 | + - name: Install Python |
| 73 | + uses: actions/setup-python@v4 |
| 74 | + with: |
| 75 | + python-version: '3.11' |
| 76 | + |
| 77 | + - name: Install maturin |
| 78 | + run: | |
| 79 | + python -m pip install --upgrade pip |
| 80 | + pip install maturin |
| 81 | +
|
| 82 | + - name: Build sdist |
| 83 | + run: maturin sdist |
| 84 | + |
| 85 | + - name: Upload sdist |
| 86 | + uses: actions/upload-artifact@v4 |
| 87 | + with: |
| 88 | + name: sdist |
| 89 | + path: dist/*.tar.gz |
| 90 | + |
| 91 | + publish: |
| 92 | + name: Publish to PyPI |
| 93 | + runs-on: ubuntu-latest |
| 94 | + needs: [build_wheels, build_sdist] |
| 95 | + environment: pypi # This requires you to set up a PyPI environment in GitHub |
| 96 | + |
| 97 | + steps: |
| 98 | + - name: Download wheels |
| 99 | + uses: actions/download-artifact@v4 |
| 100 | + with: |
| 101 | + name: wheels-ubuntu-latest |
| 102 | + path: dist |
| 103 | + |
| 104 | + - name: Download wheels (Windows) |
| 105 | + uses: actions/download-artifact@v4 |
| 106 | + with: |
| 107 | + name: wheels-windows-latest |
| 108 | + path: dist |
| 109 | + |
| 110 | + - name: Download wheels (macOS) |
| 111 | + uses: actions/download-artifact@v4 |
| 112 | + with: |
| 113 | + name: wheels-macos-latest |
| 114 | + path: dist |
| 115 | + |
| 116 | + - name: Download sdist |
| 117 | + uses: actions/download-artifact@v4 |
| 118 | + with: |
| 119 | + name: sdist |
| 120 | + path: dist |
| 121 | + |
| 122 | + - name: Install twine |
| 123 | + run: | |
| 124 | + python -m pip install --upgrade pip |
| 125 | + pip install twine |
| 126 | +
|
| 127 | + - name: Check distributions |
| 128 | + run: twine check dist/* |
| 129 | + |
| 130 | + - name: Publish to PyPI |
| 131 | + env: |
| 132 | + TWINE_USERNAME: __token__ |
| 133 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 134 | + run: twine upload dist/* |
0 commit comments