Skip to content
Draft
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
68 changes: 60 additions & 8 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency:

jobs:
test-lint-scan:
if: github.ref == 'refs/heads/main'
if: startsWith(github.ref, 'refs/heads/release/')
permissions:
contents: read # Needed to check out repository
security-events: write # Needed by CodeQL to upload SARIF results
Expand All @@ -20,7 +20,7 @@ jobs:
build:
name: Build Release
needs: test-lint-scan
if: github.ref == 'refs/heads/main'
if: startsWith(github.ref, 'refs/heads/release/')
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
Expand All @@ -29,11 +29,14 @@ jobs:
attestations: write # Needed to persist SLSA build provenance attestations on GitHub
outputs:
version: ${{ steps.version.outputs.version }}
commit: ${{ steps.version.outputs.commit }}
latest: ${{ steps.version.outputs.latest }}
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
- name: Set up uv
uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
with:
Expand All @@ -42,14 +45,41 @@ jobs:
enable-cache: false
- name: Install dependencies
run: uv sync --locked --no-default-groups --group test --no-install-project
- name: Extract version and release notes from CHANGELOG.md
- name: Extract version, release commit, and release notes from CHANGELOG.md
id: version
run: |
uv run --no-sync python -m local.verify_release changelog \
--resolve-commit \
--notes-out "$RUNNER_TEMP/release-notes.md" \
--github-output "$GITHUB_OUTPUT"
- name: Verify release branch and release commit
env:
VERSION: ${{ steps.version.outputs.version }}
COMMIT: ${{ steps.version.outputs.commit }}
REF_NAME: ${{ github.ref_name }}
EVENT_SHA: ${{ github.sha }}
run: |
if [[ ! "$VERSION" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "Invalid version from verify_release: $VERSION" >&2
exit 1
fi
if [[ ! "$COMMIT" =~ ^[0-9a-f]{40}$ ]]; then
echo "Invalid release commit from verify_release: $COMMIT" >&2
exit 1
fi
if [[ "$REF_NAME" != "release/$VERSION" ]]; then
echo "Workflow must be dispatched on release/$VERSION, got: $REF_NAME" >&2
exit 1
fi
HEAD_SHA="$(git rev-parse HEAD)"
if [[ "$HEAD_SHA" != "$COMMIT" || "$EVENT_SHA" != "$COMMIT" ]]; then
echo "Release commit $COMMIT, checked-out HEAD $HEAD_SHA, and GITHUB_SHA $EVENT_SHA must all match" >&2
exit 1
fi
- name: Build sdist and wheel
run: uv build --no-preview --no-sources --clear
- name: Verify built distributions
run: uv run --no-sync python -m local.verify_release dist
- name: Attest distribution build provenance
id: attest
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
Expand Down Expand Up @@ -82,7 +112,7 @@ jobs:
publish:
name: Publish to PyPI
needs: build
if: github.ref == 'refs/heads/main'
if: startsWith(github.ref, 'refs/heads/release/')
runs-on: ubuntu-latest
timeout-minutes: 15
environment: pypi
Expand All @@ -102,7 +132,7 @@ jobs:
github-release:
name: Create GitHub Release
needs: [build, publish]
if: github.ref == 'refs/heads/main'
if: startsWith(github.ref, 'refs/heads/release/')
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
Expand All @@ -128,24 +158,46 @@ jobs:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
VERSION: ${{ needs.build.outputs.version }}
COMMIT: ${{ needs.build.outputs.commit }}
LATEST: ${{ needs.build.outputs.latest }}
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ ! "$VERSION" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "Invalid version from build job: $VERSION" >&2
exit 1
fi
if [[ ! "$COMMIT" =~ ^[0-9a-f]{40}$ ]]; then
echo "Invalid commit from build job: $COMMIT" >&2
exit 1
fi
if [[ ! "$LATEST" =~ ^(true|false)$ ]]; then
echo "Invalid latest flag from build job: $LATEST" >&2
exit 1
fi
BUNDLE_FILE="$(find provenance -type f | head -n 1)"
if [[ -z "$BUNDLE_FILE" ]]; then
echo "Missing provenance bundle in provenance/" >&2
exit 1
fi
cp "$BUNDLE_FILE" "provenance/cuid2-${VERSION}.sigstore.json"
jq -ce '.dsseEnvelope' "$BUNDLE_FILE" > "provenance/cuid2-${VERSION}.intoto.jsonl"
if TAG_REF="$(gh api "repos/$GH_REPO/git/ref/tags/v$VERSION" 2>&1)"; then
echo "Tag v$VERSION already exists; refusing to attach the release to it: $TAG_REF" >&2
exit 1
elif [[ "$TAG_REF" != *"HTTP 404"* ]]; then
echo "Could not verify that tag v$VERSION is absent: $TAG_REF" >&2
exit 1
fi
gh release create "v$VERSION" \
--repo "$GH_REPO" \
--target "$GITHUB_SHA" \
--target "$COMMIT" \
--title "v$VERSION" \
--notes-file release-notes/release-notes.md \
--latest \
--latest="$LATEST" \
dist/*.whl dist/*.tar.gz \
"provenance/cuid2-${VERSION}.sigstore.json" \
"provenance/cuid2-${VERSION}.intoto.jsonl"
TAG_COMMIT="$(gh api "repos/$GH_REPO/commits/v$VERSION" --jq .sha)"
if [[ "$TAG_COMMIT" != "$COMMIT" ]]; then
echo "Tag v$VERSION targets $TAG_COMMIT, expected $COMMIT" >&2
exit 1
fi
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ This repository continues the `overflowdigital` `cuid2` package (`b02c8ca`); ver

## [Unreleased]

### Changed

- `Cuid`, `Cuid.generate`, `create_id`, and `cuid_wrapper` now normalize integer-like `length` arguments via `operator.index` on validation, so objects implementing only `__index__` (without `__gt__` or `__add__`) are supported and `cuid_wrapper` binds a plain `int` in its `functools.partial` keywords.

### Removed

- Unreferenced internal helpers `create_letter` and `create_hash` from `cuid2.utils`.

### Fixed

- `cuid2 --check -` now decodes `stdin` as UTF-8 (it used the locale encoding before, which only differs on Windows before Python 3.15 and in non-UTF-8 locales) and treats lines containing invalid UTF-8 bytes as invalid identifiers (escaped via `ascii()`), exiting with code 1 instead of crashing with a `UnicodeDecodeError` traceback.
- The `cuid2` CLI no longer crashes with an unhandled traceback when `stdin` or `stdout` is closed (`<&-`, `>&-`): generation, `-h`/`--help`, and `-V`/`--version` exit with code 0 and `cuid2 --check <id> -q` preserves its validation exit status (0 or 1) when `stdout` is closed, while non-quiet `--check` with closed `stdout` and `--check -` with closed `stdin` exit with code 1.

## [3.0.0] - 2026-11-08

### Changed
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Pull requests that change behavior, packaging, or documentation that consumers r
To cut a release:

1. Open a release PR that renames `## [Unreleased]` to `## [X.Y.Z] - YYYY-MM-DD`, adds a fresh empty `## [Unreleased]` section above it, bumps `version` in `pyproject.toml` and `uv.lock`, and updates the compare-link footer in `CHANGELOG.md` (adds `[X.Y.Z]` comparing `v<prev>...vX.Y.Z` and updates `[Unreleased]` to `compare/vX.Y.Z...HEAD`).
2. After the release PR merges to `main`, dispatch `.github/workflows/build_release.yml` from `main` and approve the `pypi` environment deployment when prompted (the workflow reads the version from `pyproject.toml`, validates and extracts the matching `## [X.Y.Z]` section from `CHANGELOG.md` via `local.verify_release`, verifies and attests SLSA build provenance for the built sdist and wheel via `actions/attest`, publishes distributions with PEP 740 attestations via `pypa/gh-action-pypi-publish`, and creates the GitHub release tagged at the built commit). Verify the published attestations via `gh attestation verify <dist> --owner gordon-code` and at `https://pypi.org/integrity/cuid2/<version>/<wheel>/provenance`.
2. After the release PR squash-merges to `main`, a `core`-team member resolves the release commit and creates the release branch: run `git fetch origin main --tags && git switch main && git pull --ff-only`, then `uv run python -m local.verify_release changelog --resolve-commit` (prints the SHA of the commit that bumped `version` to X.Y.Z; fails if tag `vX.Y.Z` exists or X.Y.Z is not greater than every existing `v*` tag of the same major version), then `git push origin <sha>:refs/heads/release/X.Y.Z`. Release branches can be created only by the core team and are immutable (they cannot be updated, rewritten, or deleted), so double-check the SHA and version before pushing.
3. Dispatch `gh workflow run build_release.yml --ref release/X.Y.Z` and approve the `pypi` environment deployment when prompted (the workflow skips every job on a ref that is not `release/*`, and its `build` job fails unless the ref is `release/<version from pyproject.toml>` at the commit that bumped the version, so later commits on `main` are ignored; it reads the version from `pyproject.toml`, validates and extracts the matching `## [X.Y.Z]` section from `CHANGELOG.md` via `local.verify_release`, builds and verifies the sdist and wheel, verifies and attests SLSA build provenance via `actions/attest`, publishes distributions with PEP 740 attestations via `pypa/gh-action-pypi-publish`, and creates the GitHub release with tag `vX.Y.Z` at that commit). Verify the published attestations via `gh attestation verify <dist> --owner gordon-code` and at `https://pypi.org/integrity/cuid2/<version>/<wheel>/provenance`.

## Submitting Pull Requests

Expand Down
Loading
Loading