diff --git a/.claude/skills/release/SKILL.md b/.claude/skills/release/SKILL.md index d290dc6f09..b21d9430d5 100644 --- a/.claude/skills/release/SKILL.md +++ b/.claude/skills/release/SKILL.md @@ -85,6 +85,12 @@ git worktree remove It must print `X.Y.Z` exactly. If it does not, stop: delete the local tag (`git tag -d vX.Y.Z`) and do not publish. If it does, push the tag: `git push origin vX.Y.Z`. +`release.yml` repeats the check on the runner, where the checkout holds only the release's tag: +its build job runs `.github/scripts/check-release-version.sh`, which fails before the upload +unless every wheel and sdist carries the version of the tag. The `Release check` workflow +(Actions > Release check, also run on a pull request that changes the release files) builds every +package at a local tag and runs that script, without the `pypi` environment, so it cannot publish. + ## 5. Publish the GitHub release (ask first) ```bash @@ -99,11 +105,19 @@ generated notes by using the `--notes` flag"). The CHANGELOG section is not copi ## 6. Check what was published -- `gh run list -R GetStream/Agents --workflow release.yml --limit 1` must show the new tag with - `success`. +- `gh run list -R GetStream/Agents --workflow release.yml --limit 1` shows the run of the new tag. + Do not read its conclusion: the `integration` job is in the same run and does not gate the + publish (a provider outage must not hold back a release), so a good publish can end `failure`. + `gh run view -R GetStream/Agents --json jobs --jq '.jobs[] | [.name, .conclusion]'` must + show `success` for `Build & Test Core SDK` (build, version check and upload) and for + `Verify PIP install works`. - `curl -s https://pypi.org/pypi/vision-agents/json | jq -r .info.version` must print `X.Y.Z`. `release.yml` has never succeeded: of its 41 runs, 34 ended `failure`, 3 `startup_failure`, 3 `cancelled` and 1 `skipped`. The packages of 0.6.5 to 0.6.9 reached PyPI outside it, and 0.6.9 -has no Trusted Publishing provenance (AI-3561). Until AI-3561 is fixed, step 6 is unverified. If the run does not succeed, the packages are not on PyPI. Report it -on AI-3561, and do not upload by hand. +has no Trusted Publishing provenance (AI-3561). The first run of the fixed workflow is the first +check of PyPI's side, which the repo cannot read: every PyPI project of the 41 packages must list +`GetStream/Agents`, `release.yml` and the environment `pypi` as a trusted publisher, and +`vision-agents-plugins-omni` and `vision-agents-plugins-stream` are not on PyPI yet, so each needs a +pending publisher. If the run does not succeed, some packages may be on PyPI and others not. Report +it on AI-3561, and do not upload by hand. diff --git a/.github/actions/build-python-packages/action.yml b/.github/actions/build-python-packages/action.yml new file mode 100644 index 0000000000..c19ae5b33e --- /dev/null +++ b/.github/actions/build-python-packages/action.yml @@ -0,0 +1,40 @@ +name: Build the Python packages +description: Build every workspace package and check that each carries the version of the release tag. Never uploads. +inputs: + tag: + description: The release tag, vX.Y.Z. The checkout must see it. + required: true +outputs: + version: + description: The version, X.Y.Z, that every built file carries + value: ${{ steps.check.outputs.version }} +runs: + using: composite + steps: + # No dependency cache in a job that holds an OIDC token: a cache poisoned by another + # run would hand that token to whatever it planted. + - uses: ./.github/actions/python-uv-setup + with: + enable-cache: "false" + # `uv build` makes its own build environments and needs none of the dev dependencies. + sync: "false" + + - name: Clean dist directory + shell: bash + run: | + rm -rf dist + + - name: Build all distributions + shell: bash + env: + UV_BUILD_CONSTRAINT: ${{ github.workspace }}/.github/release-build-constraints.txt + run: | + uv build --all + + - name: Check that every file has the release version + id: check + shell: bash + env: + TAG: ${{ inputs.tag }} + run: | + .github/scripts/check-release-version.sh "$TAG" dist diff --git a/.github/actions/python-uv-setup/action.yml b/.github/actions/python-uv-setup/action.yml index 5bdd365dba..e8c12edd67 100644 --- a/.github/actions/python-uv-setup/action.yml +++ b/.github/actions/python-uv-setup/action.yml @@ -17,6 +17,10 @@ inputs: description: Restore and save uv's download cache; "false" in a job that holds an OIDC token required: false default: "true" + sync: + description: Run uv sync; "false" in a job that only builds, with `uv build`, and needs no environment + required: false + default: "true" cpu-torch: description: Install the CPU build of torch, without the CUDA packages its PyPI build needs on Linux required: false @@ -43,6 +47,7 @@ runs: echo "uv download cache hit: ${{ steps.setup_uv.outputs['cache-hit'] }}" - name: Install the project dependencies + if: inputs.sync == 'true' shell: bash working-directory: ${{ inputs.working-directory }} env: diff --git a/.github/scripts/check-release-version.sh b/.github/scripts/check-release-version.sh new file mode 100755 index 0000000000..207169ad7c --- /dev/null +++ b/.github/scripts/check-release-version.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# Fails unless the Python packages built in all carry the version of the release tag. +# +# Each package takes its version from the nearest git tag (hatch-vcs). When the checkout does not +# see the release tag, the build does not fail: it gets a dev version from another tag, or 0.0.0 +# (`fallback_version` in each pyproject.toml). PyPI never takes a version twice, so this runs +# before the upload. +# +# Usage: check-release-version.sh [] (tag: vX.Y.Z; dist-dir: dist) +# Writes `version=X.Y.Z` to $GITHUB_OUTPUT when it is set. +set -euo pipefail + +tag=${1:?usage: check-release-version.sh []} +dist=${2:-dist} + +fail() { + echo "::error::$*" + exit 1 +} + +[[ $tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || fail "release tag '$tag' is not vX.Y.Z" +want=${tag#v} + +# `uv publish` uploads everything in the directory, so every file there must be checked. +shopt -s nullglob dotglob +files=() +for f in "$dist"/*; do + case $(basename "$f") in + .gitignore) ;; + *.whl | *.tar.gz) files+=("$f") ;; + *) fail "$f is neither a wheel nor an sdist, and 'uv publish' would upload it" ;; + esac +done +(( ${#files[@]} > 0 )) || fail "no wheel or sdist in $dist" +for f in "${files[@]}"; do + name=$(basename "$f") + case $name in + # A wheel is {name}-{version}-{python}-{abi}-{platform}.whl, and name has no '-'. + *.whl) version=$(cut -d- -f2 <<<"$name") ;; + # An sdist is {name}-{version}.tar.gz. + *) stem=${name%.tar.gz}; version=${stem##*-} ;; + esac + [[ $version == "$want" ]] || fail "$name has version '$version', expected '$want'" +done + +echo "${#files[@]} files in $dist, all at version $want" +if [[ -n ${GITHUB_OUTPUT:-} ]]; then + echo "version=$want" >> "$GITHUB_OUTPUT" +fi diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml new file mode 100644 index 0000000000..61a24bafc8 --- /dev/null +++ b/.github/workflows/release-check.yml @@ -0,0 +1,120 @@ +name: Release check +# Proves, without publishing, that a release would build every Python package at the tag's +# version. It runs the build steps of release.yml (the build-python-packages action) on a local +# tag, and has no `uv publish`, no `pypi` environment and no `id-token` permission, so it can +# never reach PyPI. Run it by hand (Actions > Release check) before you tag a release. +on: + pull_request: + branches: [ "**" ] + # A draft runs nothing: CI starts when the pull request is marked ready (ready_for_review). + types: [ opened, synchronize, reopened, ready_for_review ] + paths: + - '.github/workflows/release.yml' + - '.github/workflows/release-check.yml' + - '.github/actions/build-python-packages/**' + - '.github/actions/python-uv-setup/**' + - '.github/scripts/check-release-version.sh' + - '.github/release-build-constraints.txt' + - '**/pyproject.toml' + - 'uv.lock' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: release-check-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Build every package at the release version + if: github.event.pull_request.draft != true + runs-on: ubuntu-latest + env: + # A version no release has, so the check never meets a real tag. + TAG: v99.0.0 + steps: + # The release job checks out the same way: one commit, no tags but the release's. + - name: Checkout + uses: actions/checkout@v6 + + - name: Tag this commit as the release + run: | + git tag "$TAG" + git tag --list + + - name: Build all distributions + id: build + uses: ./.github/actions/build-python-packages + with: + tag: ${{ env.TAG }} + + # The action's output is what release.yml hands to the install check, so it must be the + # tag's version. This fails if the action no longer runs the version check or no longer + # reports its result. + - name: The build reports the tag's version + run: | + echo "build output: '${{ steps.build.outputs.version }}', tag: '$TAG'" + test "${{ steps.build.outputs.version }}" = "${TAG#v}" + + # Each wrong input must fail the version check. If one passes, the check no longer guards + # the upload. + - name: A wrong tag or a wrong file version must fail the check + run: | + fails() { + if "$@" > /dev/null 2>&1; then + echo "::error::passed, but must fail: $*" + exit 1 + fi + echo "failed as expected: $*" + } + fails .github/scripts/check-release-version.sh v99.0.1 dist + fails .github/scripts/check-release-version.sh 99.0.0 dist + fails .github/scripts/check-release-version.sh v99.0.0-rc1 dist + wheels=(dist/*.whl) + sdists=(dist/*.tar.gz) + wrong_wheel=$(basename "${wheels[0]}" | sed 's/-99\.0\.0-/-99.0.1-/') + wrong_sdist=$(basename "${sdists[0]}" | sed 's/-99\.0\.0\.tar/-99.0.1.tar/') + four_wheel=$(basename "${wheels[0]}" | sed 's/-99\.0\.0-/-99.0.0.1-/') + four_sdist=$(basename "${sdists[0]}" | sed 's/-99\.0\.0\.tar/-99.0.0.1.tar/') + post_sdist=$(basename "${sdists[0]}" | sed 's/-99\.0\.0\.tar/-99.0.0.post1.tar/') + mkdir empty wheel-wrong sdist-wrong four post stray + # One wrong file of a kind, beside a right file of the other kind. + cp "${wheels[0]}" "wheel-wrong/$wrong_wheel" + cp "${sdists[0]}" wheel-wrong/ + cp "${sdists[0]}" "sdist-wrong/$wrong_sdist" + cp "${wheels[0]}" sdist-wrong/ + fails .github/scripts/check-release-version.sh "$TAG" wheel-wrong + fails .github/scripts/check-release-version.sh "$TAG" sdist-wrong + fails .github/scripts/check-release-version.sh "$TAG" empty + # A version that merely starts with the tag's must fail. So must a tag that is not + # vX.Y.Z even when the files carry its version: hatch-vcs builds 99.0.0.1 from v99.0.0.1. + cp "${wheels[0]}" "post/${wheels[0]##*/}" + cp "${sdists[0]}" "post/$post_sdist" + fails .github/scripts/check-release-version.sh "$TAG" post + cp "${wheels[0]}" "four/$four_wheel" + cp "${sdists[0]}" "four/$four_sdist" + fails .github/scripts/check-release-version.sh v99.0.0.1 four + # `uv publish` uploads every file in dist, so a file that is no wheel or sdist must fail. + cp "${wheels[0]}" "${sdists[0]}" stray/ + touch stray/notes.zip + fails .github/scripts/check-release-version.sh "$TAG" stray + + # Metadata PyPI refuses, such as a long description that does not render. + - name: Check the package metadata + run: uvx -q --from twine==7.0.0 twine check dist/* + + # PyPI takes an upload to a project that does not exist only from a pending trusted + # publisher. This repo cannot read that setting, so the step lists the projects to look at. + - name: List the projects PyPI does not have yet + run: | + missing="" + for wheel in dist/*.whl; do + name=$(basename "$wheel" | cut -d- -f1 | tr _ -) + code=$(curl -s -o /dev/null -w '%{http_code}' "https://pypi.org/pypi/$name/json") + [ "$code" = 200 ] || missing="$missing $name($code)" + done + if [ -n "$missing" ]; then + echo "::warning::not on PyPI, needs a pending trusted publisher before a release:$missing" + fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 272477384c..ab717b52a8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,41 +24,31 @@ jobs: if: startsWith(github.event.release.tag_name, 'v') runs-on: ubuntu-latest environment: pypi + # Not gated on `integration`, by decision: a provider outage must not hold back a release, so + # this run can end `failure` after a good publish. Check this job, not the run's conclusion. # The OIDC token is this job's alone, so the integration job, which holds every # provider secret, cannot mint one. permissions: contents: read id-token: write # REQUIRED for PyPI Trusted Publishing (OIDC) outputs: - version: ${{ steps.get_version.outputs.version }} + version: ${{ steps.build.outputs.version }} steps: - name: Checkout uses: actions/checkout@v6 - # No dependency cache in a job that holds an OIDC token: a cache poisoned by another - # run would hand that token to whatever it planted. - - uses: ./.github/actions/python-uv-setup - with: - enable-cache: "false" - - - name: Clean dist directory - run: | - rm -rf dist - + # Builds every package and fails, before anything is uploaded, unless each file carries the + # tag's version. release-check.yml runs the same steps without the PyPI environment. - name: Build all distributions - env: - UV_BUILD_CONSTRAINT: ${{ github.workspace }}/.github/release-build-constraints.txt - run: | - uv build --all - - - name: Extract package version (hatch via uv) - id: get_version - working-directory: sdks/python - run: | - VERSION=$(uvx -q --from 'hatch==1.18.2' hatch version) - echo "version=$VERSION" >> "$GITHUB_OUTPUT" + id: build + uses: ./.github/actions/build-python-packages + with: + tag: ${{ github.event.release.tag_name }} + # `always`: the default, `automatic`, carries on without credentials when uv cannot get a + # token. Each PyPI project must list this workflow file and the `pypi` environment as a + # trusted publisher. - name: Publish to PyPI (Trusted Publishing) - run: uv publish + run: uv publish --trusted-publishing always test-core-index: name: Verify PIP install works