Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
68 changes: 49 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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<version>` 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
Expand All @@ -14,21 +15,28 @@ 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
runs-on: ubuntu-latest
outputs:
version: ${{ steps.meta.outputs.version }}
prerelease: ${{ steps.meta.outputs.prerelease }}
release: ${{ steps.meta.outputs.release }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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'))
Expand All @@ -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 `## `
Expand All @@ -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[@]}"
47 changes: 13 additions & 34 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,10 @@ was removed; revoke the token it used at <https://pypi.org/manage/account/token/
`python-wrap`, and environment name `testpypi`.

3. **Create the GitHub environments** in the repository under Settings, Environments:
`pypi` and `testpypi`. Add yourself as a required reviewer on `pypi` so every real
`pypi` and `testpypi`. Under `pypi`, "Deployment branches and tags" must allow the
`main` branch and `v*` tags. Add yourself as a required reviewer on `pypi` so every real
upload waits for one click.

## Active release branch

Use `release/0.6.0` for the combined release. It carries the fixes and features
from the earlier 0.4.2 and 0.5.0 preparation branches, along with the 0.6.0 API
removals. Its changelog compares the beta with the published `v0.4.0` tag.

Before publishing a build that includes the removals, verify the compatibility
window in the [deprecation policy](docs/project/stability.md#deprecation-policy).
That window is measured from the release that actually shipped the deprecation.

## Every release

1. **Version.** Set `__version__` in `src/python_wrap/__init__.py`. It is the only place
Expand All @@ -60,29 +51,17 @@ That window is measured from the release that actually shipped the deprecation.

The default `pytest` run includes the `tests/e2e/` happy-path scenarios.

4. **Merge to `main`**, after local checks and release-branch CI pass. Wait for CI and
the docs workflow on the merged commit before creating a release tag. The Redis integration job is
required for 0.3.0; the release workflow repeats its real-server gate before any
upload, so a skipped local Redis run cannot approve a publication.
5. **Rehearse (recommended for a big release).** Tag a pre-release such as `v0.3.0rc1`
(after setting `__version__ = "0.3.0rc1"`). Every tagged version is published to
TestPyPI and installed back from that index
in a clean environment. Pre-releases (`a`, `b`, `rc`, `.dev`) stop there; final
versions continue to PyPI only after this verification succeeds. A version can never
be reused on PyPI, so this is cheap insurance.
6. **Tag and push.**

```bash
git tag -a v0.3.0 -m "python-wrap 0.3.0"
git push origin v0.3.0
```

The workflow refuses a tag that disagrees with `__version__`, builds, checks the
wheel, uploads to TestPyPI and verifies the installed package, and then waits for
your approval of the `pypi` environment. After you approve, it uploads the same
artifacts to PyPI with attestations, verifies an installation from PyPI, and creates
the GitHub release with the files attached. `workflow_dispatch` only builds and
verifies artifacts; it never uploads.
4. **Merge to `main`**, after local checks and release-branch CI pass. **The merge
releases.** When `__version__` has no `v<version>` 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<version>` tag by hand still releases it. `workflow_dispatch` only
builds and verifies artifacts; it never uploads.
7. **Smoke-test** from a fresh directory:

```bash
Expand Down
2 changes: 1 addition & 1 deletion docs/get-started/stacking.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading