|
| 1 | +name: Python |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + tags: |
| 7 | + - "*" |
| 8 | + pull_request: |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + collect-sdist: |
| 16 | + name: "Collect sdist" |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout the code |
| 20 | + uses: actions/checkout@v3 |
| 21 | + |
| 22 | + - name: Install Python 3.10 |
| 23 | + uses: actions/setup-python@v4 |
| 24 | + id: cpy310 |
| 25 | + with: |
| 26 | + python-version: "3.10" |
| 27 | + architecture: x64 |
| 28 | + |
| 29 | + - name: Install build |
| 30 | + run: pip install build |
| 31 | + |
| 32 | + - name: Collect sdist |
| 33 | + run: python -m build -o dist --sdist synapse |
| 34 | + |
| 35 | + - name: Upload sdist |
| 36 | + uses: actions/upload-artifact@v3 |
| 37 | + with: |
| 38 | + name: sdist |
| 39 | + path: dist |
| 40 | + |
| 41 | + build-wheels: |
| 42 | + name: "Build Python wheels" |
| 43 | + strategy: |
| 44 | + fail-fast: false |
| 45 | + matrix: |
| 46 | + include: |
| 47 | + - os: macos-latest |
| 48 | + target: x86_64-apple-darwin |
| 49 | + compatibility: manylinux2014 # Ignored on macOS |
| 50 | + |
| 51 | + - os: macos-latest |
| 52 | + target: aarch64-apple-darwin |
| 53 | + compatibility: manylinux2014 # Ignored on macOS |
| 54 | + |
| 55 | + - os: ubuntu-latest |
| 56 | + target: aarch64-unknown-linux-gnu |
| 57 | + compatibility: manylinux2014 |
| 58 | + |
| 59 | + - os: ubuntu-latest |
| 60 | + target: x86_64-unknown-linux-gnu |
| 61 | + compatibility: manylinux2014 |
| 62 | + |
| 63 | + - os: ubuntu-latest |
| 64 | + target: aarch64-unknown-linux-musl |
| 65 | + compatibility: musllinux_1_2 |
| 66 | + |
| 67 | + - os: ubuntu-latest |
| 68 | + target: x86_64-unknown-linux-musl |
| 69 | + compatibility: musllinux_1_2 |
| 70 | + |
| 71 | + runs-on: ${{ matrix.os }} |
| 72 | + steps: |
| 73 | + - name: Checkout the code |
| 74 | + uses: actions/checkout@v3 |
| 75 | + |
| 76 | + - name: Install Python 3.10 |
| 77 | + uses: actions/setup-python@v4 |
| 78 | + id: cpy310 |
| 79 | + with: |
| 80 | + python-version: "3.10" |
| 81 | + architecture: x64 |
| 82 | + update-environment: false |
| 83 | + |
| 84 | + - name: Install maturin (macOS) |
| 85 | + if: runner.os == 'macOS' |
| 86 | + run: | |
| 87 | + mkdir -p "${HOME}/.local/bin" |
| 88 | + curl -sL https://github.com/PyO3/maturin/releases/download/v0.13.6/maturin-x86_64-apple-darwin.tar.gz | tar xzf - -C "${HOME}/.local/bin" |
| 89 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 90 | +
|
| 91 | + - name: Install maturin (Linux) |
| 92 | + if: runner.os == 'Linux' |
| 93 | + run: | |
| 94 | + mkdir -p "${HOME}/.local/bin" |
| 95 | + curl -sL https://github.com/PyO3/maturin/releases/download/v0.13.6/maturin-x86_64-unknown-linux-musl.tar.gz | tar xzf - -C "${HOME}/.local/bin" |
| 96 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 97 | +
|
| 98 | + - name: Setup Zig |
| 99 | + uses: goto-bus-stop/setup-zig@v1 |
| 100 | + with: |
| 101 | + version: 0.9.1 |
| 102 | + |
| 103 | + - name: Install Rust toolchain |
| 104 | + uses: actions-rs/toolchain@v1 |
| 105 | + with: |
| 106 | + toolchain: stable |
| 107 | + profile: minimal |
| 108 | + default: true |
| 109 | + target: ${{ matrix.target }} |
| 110 | + |
| 111 | + - name: Setup Rust build cache |
| 112 | + uses: Swatinem/rust-cache@v2 |
| 113 | + with: |
| 114 | + shared-key: ${{ matrix.target }} |
| 115 | + |
| 116 | + - name: Build wheels |
| 117 | + run: | |
| 118 | + maturin build \ |
| 119 | + --release \ |
| 120 | + --out dist \ |
| 121 | + --manifest-path synapse/Cargo.toml \ |
| 122 | + -i ${{ steps.cpy310.outputs.python-path }} \ |
| 123 | + --compatibility ${{ matrix.compatibility }} \ |
| 124 | + --target ${{ matrix.target }} \ |
| 125 | + --zig |
| 126 | +
|
| 127 | + - name: Upload wheels |
| 128 | + uses: actions/upload-artifact@v3 |
| 129 | + with: |
| 130 | + name: wheels |
| 131 | + path: dist |
| 132 | + |
| 133 | + upload: |
| 134 | + name: "Upload to PyPI" |
| 135 | + runs-on: ubuntu-latest |
| 136 | + |
| 137 | + permissions: {} |
| 138 | + if: startsWith(github.ref, 'refs/tags') |
| 139 | + |
| 140 | + needs: [ collect-sdist, build-wheels ] |
| 141 | + steps: |
| 142 | + - name: Download wheels |
| 143 | + uses: actions/download-artifact@v3 |
| 144 | + with: |
| 145 | + name: wheels |
| 146 | + path: dist |
| 147 | + |
| 148 | + - name: Download sdist |
| 149 | + uses: actions/download-artifact@v3 |
| 150 | + with: |
| 151 | + name: sdist |
| 152 | + path: dist |
| 153 | + |
| 154 | + - name: Publish distribution to PyPI |
| 155 | + if: startsWith(github.ref, 'refs/tags') |
| 156 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 157 | + with: |
| 158 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments