diff --git a/.github/workflows/cli-wheels.yml b/.github/workflows/cli-wheels.yml index 490a5d24d..d4d0d46f5 100644 --- a/.github/workflows/cli-wheels.yml +++ b/.github/workflows/cli-wheels.yml @@ -13,6 +13,10 @@ on: description: Published CLI release to package required: true default: v0.42.0-beta.30 + publish: + description: Request approval to publish these stable wheels to PyPI + type: boolean + default: false permissions: contents: read @@ -30,6 +34,8 @@ jobs: - uses: actions/setup-python@v6 with: python-version: '3.13' + - name: Test stable publishing checks + run: bash ci/cli_wheel/test_publish_checks.sh - run: python -m pip install wheel==0.48.0 - name: Build wheels from published release archives env: @@ -66,3 +72,48 @@ jobs: - run: python -m pip install uv==0.13.9 pipx==1.19.0 - name: Install and exercise the native CLI with uvx and pipx run: bash ci/cli_wheel/test_install.sh "$CLI_TAG" "$PWD/wheels" + + check-publish: + if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && inputs.publish + runs-on: ubuntu-24.04 + permissions: + actions: read + contents: read + steps: + - uses: actions/checkout@v6 + with: + persist-credentials: false + - name: Verify stable release and required environment approval + env: + GH_TOKEN: ${{ github.token }} + run: bash ci/cli_wheel/check_publish.sh "$CLI_TAG" + + publish: + name: Publish ${{ inputs.tag }} to PyPI + needs: [install, check-publish] + runs-on: ubuntu-24.04 + environment: + name: pypi-cli + url: https://pypi.org/project/lancedb-tools/ + concurrency: pypi-lancedb-tools-${{ inputs.tag }} + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v8 + with: + name: lancedb-tools-wheels + path: dist + - name: Upload tested wheels + uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 + with: + # A retry of this job can finish a partially uploaded release. + skip-existing: true + - name: Verify the published wheel checksums + working-directory: dist + run: | + curl --fail --silent --show-error --retry 5 --retry-all-errors \ + "https://pypi.org/pypi/lancedb-tools/${CLI_TAG#v}/json" -o "$RUNNER_TEMP/pypi.json" + for wheel in *.whl; do + digest=$(jq -er --arg wheel "$wheel" '.urls[] | select(.filename == $wheel) | .digests.sha256' "$RUNNER_TEMP/pypi.json") + echo "$digest $wheel" | sha256sum --check + done diff --git a/ci/cli_wheel/check_publish.sh b/ci/cli_wheel/check_publish.sh new file mode 100644 index 000000000..1407668a3 --- /dev/null +++ b/ci/cli_wheel/check_publish.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +tag=${1:?pass the stable release tag} +number='(0|[1-9][0-9]*)' +if ! [[ $tag =~ ^v${number}\.${number}\.${number}$ ]]; then + echo "Expected a stable release tag such as v0.42.0, got $tag" >&2 + exit 1 +fi + +if ! gh api "repos/lancedb/lancedb/releases/tags/$tag" | + jq -e --arg tag "$tag" ' + .tag_name == $tag and .draft == false and .prerelease == false and + (.published_at | type == "string" and length > 0) + ' >/dev/null; then + echo "Expected a published stable GitHub release for $tag" >&2 + exit 1 +fi + +# Referencing a missing GitHub environment would create it without protection. +if ! gh api repos/lancedb/lancedb/environments/pypi-cli | + jq -e 'any(.protection_rules[]; .type == "required_reviewers" and (.reviewers | length > 0))' >/dev/null; then + echo "Configure a required reviewer on the pypi-cli environment" >&2 + exit 1 +fi diff --git a/ci/cli_wheel/test_publish_checks.sh b/ci/cli_wheel/test_publish_checks.sh new file mode 100644 index 000000000..a10968b85 --- /dev/null +++ b/ci/cli_wheel/test_publish_checks.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Exercise the release checks without a GitHub token or a PyPI upload. +stable='{"tag_name":"v0.42.0","draft":false,"prerelease":false,"published_at":"2026-01-01T00:00:00Z"}' +protected='{"protection_rules":[{"type":"required_reviewers","reviewers":[{"type":"Team"}]}]}' +gh() { + case "$2" in + repos/lancedb/lancedb/releases/tags/*) [[ -n $release_json ]] && echo "$release_json" ;; + repos/lancedb/lancedb/environments/pypi-cli) [[ -n $environment_json ]] && echo "$environment_json" ;; + *) return 1 ;; + esac +} +export -f gh +check() { + release_json=$2 environment_json=$3 bash ci/cli_wheel/check_publish.sh "$1" +} +reject() { + if check "$@" 2>/dev/null; then + echo "Unexpectedly accepted: $*" >&2 + exit 1 + fi +} + +check v0.42.0 "$stable" "$protected" +reject v0.42.0-beta.30 "${stable/v0.42.0/v0.42.0-beta.30}" "$protected" +reject v0.42.1 "$stable" "$protected" +reject v0.42.0 "" "$protected" +reject v0.42.0 "$(jq '.draft = true' <<<"$stable")" "$protected" +reject v0.42.0 "$(jq '.prerelease = true' <<<"$stable")" "$protected" +reject v0.42.0 "$(jq '.published_at = null' <<<"$stable")" "$protected" +reject v0.42.0 "$stable" '{"protection_rules":[]}' +reject v0.42.0 "$stable" "" +reject v0.42.0 "$stable" '{"protection_rules":[{"type":"required_reviewers","reviewers":[]}]}' diff --git a/release_process.md b/release_process.md index 145427cee..bb15e4d8b 100644 --- a/release_process.md +++ b/release_process.md @@ -188,8 +188,29 @@ pipx install "$wheel" lancedb profile list ``` -This workflow produces review artifacts. Publishing the first stable wheels -to PyPI is a separate release step. +To publish a stable CLI release, wait until its three CLI archives and +`SHA256SUMS` are on GitHub Releases. Dispatch the workflow from `main` with +the exact release tag and request publication: + +```sh +gh workflow run cli-wheels.yml --repo lancedb/lancedb --ref main -f tag=v0.42.0 -f publish=true +``` + +After all three native install jobs pass, a release maintainer checks the tag +and install results and approves the `pypi-cli` deployment in the workflow run. +The upload job publishes the tested wheels and verifies their SHA-256 digests +against PyPI. If an upload stops partway, rerun the failed job in the same run +to finish uploading the original wheels. To verify the public install: + +```sh +uvx --from lancedb-tools==0.42.0 lancedb --version +``` + +Before the first upload, a repository admin creates the `pypi-cli` Actions +environment with a required reviewer and permits deployments only from the +`main` branch. A PyPI maintainer registers a pending GitHub Trusted Publisher +for the `lancedb-tools` project with owner `lancedb`, repository `lancedb`, +workflow `cli-wheels.yml`, and environment `pypi-cli`. ### Homebrew tap updates