@sigit / si Mirror · read-only
Fork 0

Mirror of github.com/getsigit/si.

Mirrored from https://github.com/getsigit/si.git

Synced Nov 24, 08:15 UTC

1 name: Release PyPI
2
3 # Publishes sigit-si-cli, the native `si` binary packaged as maturin wheels, on the same tag that
4 # release-crates.yml publishes from.
5 #
6 # Windows arm64 wheels are intentionally not built here. GitHub's hosted Windows runners provide
7 # x64 Python, and maturin refuses to build an arm64 wheel when the interpreter reports win-amd64.
8 #
9 # Auth is PyPI Trusted Publishing (OIDC), so no API token is stored. pypi.org needs a publisher
10 # for this repository and workflow (release-pypi.yml), with no environment. For the first release
11 # that is a pending publisher, which creates the project on first upload.
12
13 on:
14 push:
15 tags:
16 - "v*.*.*"
17 workflow_dispatch:
18 inputs:
19 tag:
20 description: "Release tag (e.g. v1.3.0)"
21 required: true
22
23 concurrency:
24 group: ${{ github.workflow }}-${{ github.event.inputs.tag || github.ref_name }}
25 cancel-in-progress: false
26
27 permissions:
28 contents: read
29
30 env:
31 CARGO_TERM_COLOR: always
32 PYPI_PACKAGE: sigit-si-cli
33
34 jobs:
35 verify-version:
36 runs-on: ubuntu-latest
37 steps:
38 - uses: actions/checkout@v6
39 with:
40 ref: ${{ github.event.inputs.tag || github.ref }}
41 - name: Tag matches the workspace version
42 shell: bash
43 env:
44 TAG: ${{ github.event.inputs.tag || github.ref_name }}
45 run: |
46 workspace=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
47 if [ "$TAG" != "v$workspace" ]; then
48 echo "::error::tag $TAG does not match the workspace version $workspace"
49 exit 1
50 fi
51
52 build-wheels:
53 name: Build wheel (${{ matrix.build.NAME }})
54 needs: verify-version
55 runs-on: ${{ matrix.build.OS }}
56 strategy:
57 fail-fast: false
58 matrix:
59 build:
60 - {
61 NAME: linux-x64,
62 OS: ubuntu-22.04,
63 TARGET: x86_64-unknown-linux-gnu,
64 MANYLINUX: "2_28",
65 }
66 - {
67 NAME: linux-arm64,
68 OS: ubuntu-22.04-arm,
69 TARGET: aarch64-unknown-linux-gnu,
70 MANYLINUX: "2_28",
71 }
72 - {
73 NAME: windows-x64,
74 OS: windows-2022,
75 TARGET: x86_64-pc-windows-msvc,
76 }
77 - { NAME: darwin-x64, OS: macos-26, TARGET: x86_64-apple-darwin }
78 - { NAME: darwin-arm64, OS: macos-26, TARGET: aarch64-apple-darwin }
79 steps:
80 - name: Checkout
81 uses: actions/checkout@v6
82 with:
83 ref: ${{ github.event.inputs.tag || github.ref }}
84
85 - name: Read Rust toolchain
86 shell: bash
87 run: |
88 rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
89 if [ -z "$rust_toolchain" ]; then
90 echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
91 exit 1
92 fi
93 echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
94
95 - name: Install Rust toolchain
96 uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
97 with:
98 toolchain: ${{ env.RUST_TOOLCHAIN }}
99 targets: ${{ matrix.build.TARGET }}
100
101 # The repo uses rustls and a vendored libgit2, so the manylinux container needs no extra
102 # system packages.
103 - name: Build wheel
104 uses: PyO3/maturin-action@v1
105 with:
106 target: ${{ matrix.build.TARGET }}
107 manylinux: ${{ matrix.build.MANYLINUX || 'off' }}
108 working-directory: packaging/pypi/si
109 args: --release --locked --compatibility pypi --out dist
110
111 - name: Upload wheel artifact
112 uses: actions/upload-artifact@v4
113 with:
114 name: pypi-wheels-${{ matrix.build.NAME }}
115 path: packaging/pypi/si/dist/*
116
117 build-sdist:
118 name: Build source distribution
119 needs: verify-version
120 runs-on: ubuntu-latest
121 steps:
122 - name: Checkout
123 uses: actions/checkout@v6
124 with:
125 ref: ${{ github.event.inputs.tag || github.ref }}
126
127 - name: Build sdist
128 uses: PyO3/maturin-action@v1
129 with:
130 command: sdist
131 working-directory: packaging/pypi/si
132 args: --out dist
133
134 - name: Upload sdist artifact
135 uses: actions/upload-artifact@v4
136 with:
137 name: pypi-sdist
138 path: packaging/pypi/si/dist/*
139
140 # Installing from the built wheels proves the binary loads, not just that it was packed: a
141 # missing runtime DLL or a glibc mismatch shows up here instead of on PyPI.
142 smoke-test:
143 name: Smoke test (${{ matrix.os }})
144 needs:
145 - build-wheels
146 - build-sdist
147 runs-on: ${{ matrix.os }}
148 strategy:
149 fail-fast: false
150 matrix:
151 os:
152 # The oldest image, so the Linux wheel runs against the glibc floor.
153 - ubuntu-22.04
154 - windows-2022
155 - macos-26
156 steps:
157 - name: Checkout
158 uses: actions/checkout@v6
159 with:
160 ref: ${{ github.event.inputs.tag || github.ref }}
161
162 - name: Set the release version
163 shell: bash
164 run: |
165 release_version="${{ github.event.inputs.tag || github.ref_name }}"
166 echo "RELEASE_VERSION=${release_version#v}" >> "$GITHUB_ENV"
167
168 - name: Download distribution artifacts
169 uses: actions/download-artifact@v4
170 with:
171 pattern: pypi-*
172 path: dist
173 merge-multiple: true
174
175 # --only-binary keeps pip from falling back to the sdist, which would compile instead of
176 # testing the wheel.
177 - name: Install from the built wheels
178 shell: bash
179 run: |
180 python -m venv .venv
181 if [ -d .venv/Scripts ]; then bin_dir=.venv/Scripts; else bin_dir=.venv/bin; fi
182 "${bin_dir}/python" -m pip install --no-index --only-binary :all: --find-links dist "${PYPI_PACKAGE}==${RELEASE_VERSION}"
183 echo "SI_BIN_DIR=${bin_dir}" >> "$GITHUB_ENV"
184
185 - name: Run the installed binary
186 shell: bash
187 run: |
188 output="$("${SI_BIN_DIR}/si" --version)"
189 echo "${output}"
190 case "${output}" in
191 *"${RELEASE_VERSION}"*) ;;
192 *)
193 echo "::error::si --version did not report ${RELEASE_VERSION}" >&2
194 exit 1
195 ;;
196 esac
197
198 publish-pypi:
199 name: Publish to PyPI
200 needs: smoke-test
201 runs-on: ubuntu-latest
202 permissions:
203 contents: read
204 id-token: write
205 steps:
206 - name: Set the release version
207 shell: bash
208 run: |
209 release_version="${{ github.event.inputs.tag || github.ref_name }}"
210 echo "RELEASE_VERSION=${release_version#v}" >> "$GITHUB_ENV"
211
212 - name: Download distribution artifacts
213 uses: actions/download-artifact@v4
214 with:
215 pattern: pypi-*
216 path: dist
217 merge-multiple: true
218
219 - name: Check whether release already exists on PyPI
220 id: pypi-check
221 shell: bash
222 run: |
223 # A 404 means the project or the version is not on PyPI, so publish. Anything other than
224 # 200 or 404 is an outage or a block, which must not read as "not published yet".
225 status=$(curl -sS -o /dev/null -w '%{http_code}' \
226 --retry 3 --retry-delay 2 --retry-all-errors \
227 "https://pypi.org/pypi/${PYPI_PACKAGE}/${RELEASE_VERSION}/json")
228
229 case "$status" in
230 200)
231 echo "${PYPI_PACKAGE} ${RELEASE_VERSION} already exists on PyPI, skipping publish"
232 echo "exists=true" >> "$GITHUB_OUTPUT"
233 ;;
234 404)
235 echo "exists=false" >> "$GITHUB_OUTPUT"
236 ;;
237 *)
238 echo "Unexpected ${status} from PyPI while checking whether ${PYPI_PACKAGE} ${RELEASE_VERSION} is published" >&2
239 exit 1
240 ;;
241 esac
242
243 - name: Publish distribution
244 if: steps.pypi-check.outputs.exists != 'true'
245 uses: pypa/gh-action-pypi-publish@release/v1
246 with:
247 skip-existing: true