From 84aa19081c033745a3d98b3118fcc9754e78ba0c Mon Sep 17 00:00:00 2001 From: Pythondeveloper6 Date: Fri, 4 Dec 2026 16:08:59 +0200 Subject: [PATCH 1/2] Release automatically when a new version is merged to main --- .github/workflows/ci.yml | 1 + .github/workflows/release.yml | 68 +++++++++++++++++++++++++---------- RELEASING.md | 47 +++++++----------------- 3 files changed, 63 insertions(+), 53 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 71312e0..6b7323d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ on: branches: [main, 'fix/**', 'release/**'] pull_request: workflow_dispatch: + workflow_call: # release.yml runs this suite before publishing # A force-push should not leave the previous run burning minutes on a dead commit. concurrency: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 976e806..84e7aa1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,11 +1,12 @@ -# Publish on a version tag, using PyPI Trusted Publishing. +# Publish when a merge to main carries a version that has no `v` tag yet (the +# workflow creates the tag with the GitHub release), or when such a tag is pushed by hand. +# `.dev` versions and already-tagged versions only build. # # One-time setup (a publisher registered on PyPI and TestPyPI, and two GitHub -# environments) is described in RELEASING.md. It must exist before the first tag: a tag -# pushed against an unregistered publisher fails at the upload, and a version number on -# PyPI can never be reused. +# environments; `pypi` must allow the `main` branch and `v*` tags) is described in +# RELEASING.md. A version number on PyPI can never be reused. # -# Every tagged version goes to TestPyPI and is installed back from that index first. +# Every released version goes to TestPyPI and is installed back from that index first. # Final versions then go to PyPI; pre-releases remain on TestPyPI only. # # No API token is involved anywhere in this file, and none should be added. Trusted @@ -14,14 +15,20 @@ name: Release on: push: + branches: [main] tags: - "v*" - # Lets the build-and-verify half be exercised without cutting a tag. + # Lets the build-and-verify half be exercised without releasing. workflow_dispatch: permissions: contents: read +# One release at a time: a second merge waits, then finds the tag and only builds. +concurrency: + group: release-publish + cancel-in-progress: false + jobs: build: name: Build and verify the distributions @@ -29,6 +36,7 @@ jobs: outputs: version: ${{ steps.meta.outputs.version }} prerelease: ${{ steps.meta.outputs.prerelease }} + release: ${{ steps.meta.outputs.release }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: @@ -48,6 +56,8 @@ jobs: # wrong number, and that is unfixable afterwards. - name: The tag must match the packaged version id: meta + env: + GH_TOKEN: ${{ github.token }} run: | packaged=$(sed -nE 's/^__version__ *= *"([^"]+)".*/\1/p' src/python_wrap/__init__.py | head -n1) if [ -z "$packaged" ]; then @@ -68,9 +78,20 @@ jobs: exit 1 fi fi + release=false + if [ "${GITHUB_REF_TYPE}" = "tag" ]; then + release=true + elif [ "${GITHUB_EVENT_NAME}" = "push" ] && [ "${GITHUB_REF}" = "refs/heads/main" ] \ + && ! printf '%s' "$packaged" | grep -q 'dev'; then + # matching-refs matches prefixes, so compare the whole ref. + tagged=$(gh api "repos/$GITHUB_REPOSITORY/git/matching-refs/tags/v$packaged" \ + --jq "[.[] | select(.ref == \"refs/tags/v$packaged\")] | length") + if [ "$tagged" = "0" ]; then release=true; fi + fi + echo "release=$release" | tee -a "$GITHUB_OUTPUT" - name: Check changelog and stability metadata - if: github.ref_type == 'tag' + if: steps.meta.outputs.release == 'true' run: uv run --frozen --no-sync python scripts/check_release.py --tag - name: Install Redis for the release integration gate @@ -100,14 +121,20 @@ jobs: - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 with: - name: dist + name: release-dist path: dist/ if-no-files-found: error + # The full CI suite must pass on the released commit before anything is uploaded. + ci: + needs: build + if: needs.build.outputs.release == 'true' + uses: ./.github/workflows/ci.yml + publish-testpypi: name: Publish to TestPyPI - needs: build - if: github.ref_type == 'tag' + needs: [build, ci] + if: needs.build.outputs.release == 'true' runs-on: ubuntu-latest environment: name: testpypi @@ -118,7 +145,7 @@ jobs: steps: - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 with: - name: dist + name: release-dist path: dist/ - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 with: @@ -130,7 +157,7 @@ jobs: verify-testpypi: name: Install and verify from TestPyPI needs: [build, publish-testpypi] - if: github.ref_type == 'tag' + if: needs.build.outputs.release == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -157,7 +184,7 @@ jobs: publish-pypi: name: Publish to PyPI needs: [build, verify-testpypi] - if: github.ref_type == 'tag' && needs.build.outputs.prerelease == 'false' + if: needs.build.outputs.release == 'true' && needs.build.outputs.prerelease == 'false' runs-on: ubuntu-latest environment: # Add a required reviewer to this environment to make every real upload wait for @@ -169,7 +196,7 @@ jobs: steps: - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 with: - name: dist + name: release-dist path: dist/ - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 with: @@ -179,7 +206,7 @@ jobs: verify-pypi: name: Install and verify from PyPI needs: [build, publish-pypi] - if: github.ref_type == 'tag' && needs.build.outputs.prerelease == 'false' + if: needs.build.outputs.release == 'true' && needs.build.outputs.prerelease == 'false' runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -208,7 +235,7 @@ jobs: needs: [build, verify-testpypi, publish-pypi, verify-pypi] # Whichever publish job applied must have succeeded; the other is skipped. if: >- - !cancelled() && github.ref_type == 'tag' && needs.build.result == 'success' + !cancelled() && needs.build.outputs.release == 'true' && needs.build.result == 'success' && needs.verify-testpypi.result == 'success' && ((needs.build.outputs.prerelease == 'true' && needs.publish-pypi.result == 'skipped') || (needs.publish-pypi.result == 'success' && needs.verify-pypi.result == 'success')) @@ -222,7 +249,7 @@ jobs: - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 with: - name: dist + name: release-dist path: dist/ # The release notes are the CHANGELOG section for this version: from its `## ` @@ -247,12 +274,15 @@ jobs: - name: Create the release env: GH_TOKEN: ${{ github.token }} + VERSION: ${{ needs.build.outputs.version }} PRERELEASE: ${{ needs.build.outputs.prerelease }} run: | flags=() if [ "$PRERELEASE" = "true" ]; then flags+=(--prerelease); fi - gh release create "$GITHUB_REF_NAME" dist/* \ + # --target creates the tag on the released commit when none was pushed. + gh release create "v$VERSION" dist/* \ --repo "$GITHUB_REPOSITORY" \ - --title "$GITHUB_REF_NAME" \ + --target "$GITHUB_SHA" \ + --title "v$VERSION" \ --notes-file release-notes.md \ "${flags[@]}" diff --git a/RELEASING.md b/RELEASING.md index 0dee5f6..d563cf9 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -24,19 +24,10 @@ was removed; revoke the token it used at ` tag yet, `release.yml` runs the full + CI suite, builds, checks the wheel, uploads to TestPyPI and verifies the installed + package. A final version then waits for your approval of the `pypi` environment, + uploads the same artifacts to PyPI with attestations and verifies an installation + from PyPI. Last, it creates the tag and the GitHub release with the files attached. +5. **Pre-releases** (`a`, `b`, `rc`) stop after TestPyPI. Merge one first to rehearse a big + release; a version can never be reused on PyPI. +6. **No release.** A merge that keeps an already-tagged version, or a `.dev` version, only + builds. Pushing a `v` tag by hand still releases it. `workflow_dispatch` only + builds and verifies artifacts; it never uploads. 7. **Smoke-test** from a fresh directory: ```bash From 12fdb711f5897085d25860fa2c9532cc4ed7ee1a Mon Sep 17 00:00:00 2001 From: Pythondeveloper6 Date: Fri, 4 Dec 2026 16:14:56 +0200 Subject: [PATCH 2/2] Make the timing example independent of retry jitter --- docs/get-started/stacking.md | 2 +- docs/llms-full.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/get-started/stacking.md b/docs/get-started/stacking.md index 77c6625..406ad60 100644 --- a/docs/get-started/stacking.md +++ b/docs/get-started/stacking.md @@ -26,7 +26,7 @@ outer: list[TimingRecord] = [] inner: list[TimingRecord] = [] @timing(callback=outer.append) # one record for the whole call -@retry(max_attempts=3, delay=0.01, on=ValueError) +@retry(max_attempts=3, delay=0.01, backoff=1, jitter=0, on=ValueError) @timing(callback=inner.append) # one record per attempt def flaky() -> None: raise ValueError diff --git a/docs/llms-full.txt b/docs/llms-full.txt index 931b0d1..4e79593 100644 --- a/docs/llms-full.txt +++ b/docs/llms-full.txt @@ -902,7 +902,7 @@ outer: list[TimingRecord] = [] inner: list[TimingRecord] = [] @timing(callback=outer.append) # one record for the whole call -@retry(max_attempts=3, delay=0.01, on=ValueError) +@retry(max_attempts=3, delay=0.01, backoff=1, jitter=0, on=ValueError) @timing(callback=inner.append) # one record per attempt def flaky() -> None: raise ValueError