From 9ec83153891d3606f72ef203fa67c48e75b04275 Mon Sep 17 00:00:00 2001 From: Blair Hamilton Date: Mon, 23 Nov 2026 11:26:44 -0500 Subject: [PATCH] ci: release with release-please A release was a hand-moved [Unreleased] section and a signed v* tag pushed by hand. Following dockmaster and k4a, release-please now keeps a standing release PR with the next version and its CHANGELOG.md section, and merging that PR is the release: release-please tags it and calls release.yml with the tag, which publishes and then moves the v4 alias as before. A tag pushed by hand releases nothing, which also retires the full-versions-only tag pattern that kept the alias from starting a second release. The PR title becomes the changelog entry, so pr-title.yml fails a title that is not a Conventional Commit, and on the release PR re-checks every commit release-please would carry. Versions track upstream parity, which release-please cannot know: it proposes a bump by commit type, so a feat: would propose 4.8.0 while the release is still 4.7 parity. That proposal is right for the usual fix: release; when it is not, Release-As sets the version. CONTRIBUTING.md and AGENTS.md say so. CHANGELOG.md loses its empty [Unreleased] heading: release-please inserts each new section above the first version heading, so it would otherwise sit stranded below the newest release. --- .github/PULL_REQUEST_TEMPLATE.md | 1 + .github/workflows/pr-title.yml | 125 +++++++++++++++++++++++++++ .github/workflows/release-please.yml | 65 ++++++++++++++ .github/workflows/release.yml | 59 ++++++++++--- .release-please-manifest.json | 3 + AGENTS.md | 2 +- CHANGELOG.md | 6 +- CONTRIBUTING.md | 40 +++++++++ README.md | 24 +++-- release-please-config.json | 21 +++++ 10 files changed, 317 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/pr-title.yml create mode 100644 .github/workflows/release-please.yml create mode 100644 .release-please-manifest.json create mode 100644 release-please-config.json diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index d4efa07..e2ac3bd 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -23,5 +23,6 @@ This project's contract is "behaves like Python pre-commit". Pick one: - [ ] If behavior changed, the differential parity suite still passes - [ ] Docs updated if this changes something a user can observe - [ ] I have signed the CLA (see CLA.md) +- [ ] The title is a Conventional Commit (`feat:`, `fix:`, `feat!:`, `docs:` …) — it becomes the changelog entry Closes # diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml new file mode 100644 index 0000000..660abfc --- /dev/null +++ b/.github/workflows/pr-title.yml @@ -0,0 +1,125 @@ +name: PR title + +# The pull request title is the changelog entry and the version bump: a squash +# merge makes it the commit subject on main (the repository's squash title is +# set to PR_TITLE, so a one-commit PR cannot slip its own subject in instead), +# and release-please reads the bump from it (CONTRIBUTING.md). So the title +# must be a Conventional Commit — `feat(builds): …`, `fix: …`, `feat!: …` — +# and this check, required by the main ruleset, fails one that is not. +# +# On release-please's own pull request it also re-checks every commit the +# release would carry. release-please skips a subject it cannot parse without +# a word, so a commit that reached main some other way would silently miss the +# changelog and the bump; here it fails the release instead, naming the commit. +# +# Gate steps, never the job: a required check whose job is skipped never +# reports and stays pending forever. +on: + pull_request: + # `edited` re-runs the check when only the title changes. + types: [opened, edited, reopened, synchronize] + +permissions: + contents: read + pull-requests: read # the merged PR behind each commit, for its override block + +concurrency: + group: pr-title-${{ github.event.pull_request.number }} + cancel-in-progress: true + +env: + # One definition for both steps. The types are the Conventional Commits set; + # which of them appear in the changelog is release-please-config.json's. + CONVENTIONAL: '^(feat|fix|perf|revert|docs|ci|build|refactor|test|chore|style)(\([[:alnum:]_./-]+\))?!?: [^[:space:]]' + +jobs: + title: + name: PR title + runs-on: ubuntu-latest + steps: + - name: The title is a Conventional Commit + env: + TITLE: ${{ github.event.pull_request.title }} + AUTHOR: ${{ github.event.pull_request.user.login }} + run: | + set -euo pipefail + # Dependabot titles its PRs "Bump …" until the baseline's + # dependabot.yml gives it a commit-message prefix. + if [ "$AUTHOR" = "dependabot[bot]" ]; then + echo "::notice::dependabot pull request; title not checked" + exit 0 + fi + if ! printf '%s' "$TITLE" | grep -Eq "$CONVENTIONAL"; then + echo "::error::the title must be a Conventional Commit: 'feat(scope): …' (minor), 'fix: …' (patch), 'feat!: …' (breaking), or docs/ci/build/refactor/test/chore/style for a change nobody using go-pre-commit can see. See CONTRIBUTING.md." + exit 1 + fi + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + if: startsWith(github.head_ref, 'release-please--') + with: + fetch-depth: 0 + persist-credentials: false + + - name: Every commit in the release is a Conventional Commit + if: startsWith(github.head_ref, 'release-please--') + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + run: | + set -euo pipefail + git fetch --quiet --tags origin main + # The range is what this release carries: since the last tag, or — + # before the first release-please release — since release-please was + # set up, so the history before it is not held to a rule it predates. + tag="$(git describe --tags --abbrev=0 --match 'v*' origin/main)" + setup="$(git log --format=%H --diff-filter=A -1 origin/main -- release-please-config.json)" + if git merge-base --is-ancestor "$setup" "$tag"; then base="$tag"; else base="$setup^"; fi + + # What release-please reads for a commit, ported from its + # src/commit.ts: when the merged PR's body contains + # BEGIN_COMMIT_OVERRIDE anywhere (even quoted in prose), the text + # after the FIRST occurrence up to END_COMMIT_OVERRIDE replaces the + # commit message, for every commit, conventional or not. That text + # is split into several messages only at a blank line followed by a + # type (and at BEGIN_NESTED_COMMIT blocks). Prints one subject per + # message, or nothing when the body has no override. + override_subjects() { + python3 -c ' + import re, sys + body = sys.stdin.read() + parts = body.split("BEGIN_COMMIT_OVERRIDE") + msg = (parts[1] if len(parts) > 1 else "").split("END_COMMIT_OVERRIDE")[0].strip() + if not msg: + sys.exit(0) + nested = msg.split("BEGIN_NESTED_COMMIT") + msgs = [nested.pop(0)] + for part in nested: + new, *rest = part.split("END_NESTED_COMMIT") + msgs.append(new) + msgs[0] += "END_NESTED_COMMIT".join(rest) + types = "feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert" + split = re.split(r"\r?\n\r?\n(?=(?:" + types + r")(?:\(.*?\))?: )", msgs[0]) + for m in [m for m in split if m] + msgs[1:]: + print(m.strip().splitlines()[0] if m.strip() else "") + ' + } + + bad=0 + while IFS=$'\t' read -r sha author subject; do + [ "$author" = "dependabot[bot]" ] && continue + body="$(gh api "repos/$REPO/commits/$sha/pulls" -q '.[0].body // ""')" + subjects="$(printf '%s' "$body" | override_subjects)" + if [ -z "$subjects" ]; then + printf '%s' "$subject" | grep -Eq "$CONVENTIONAL" && continue + echo "::error::${sha:0:7} \"$subject\" is not a Conventional Commit, so release-please leaves it out of this release. Edit its merged pull request's body to add a commit-override block (CONTRIBUTING.md), then re-run this check." + bad=1 + continue + fi + if printf '%s\n' "$subjects" | grep -Evq "$CONVENTIONAL"; then + echo "::error::${sha:0:7}: release-please reads its merged pull request's commit-override block instead of the subject, and these messages in it are not Conventional Commits:" + printf '%s\n' "$subjects" | grep -Ev "$CONVENTIONAL" | sed 's/^/ /' + echo "::error::Separate messages with a blank line, and do not write the block's opening marker anywhere else in the body: release-please starts at its first occurrence (CONTRIBUTING.md)." + bad=1 + fi + done < <(git log --format='%H%x09%an%x09%s' "$base..origin/main") + exit "$bad" diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..0aebe0d --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,65 @@ +name: Release Please + +# Every push to main updates one standing release pull request, "chore(main): +# release X.Y.Z": release-please reads the Conventional Commit subjects since +# the last release (each one a squash-merged PR title), works out the bump +# (CONTRIBUTING.md) and writes the version's CHANGELOG.md section. Merging +# that pull request is the release: release-please tags it and creates the +# GitHub release, and the release job below builds and publishes it. +# +# The token is a GitHub App's, not GITHUB_TOKEN: a pull request GITHUB_TOKEN +# opens never triggers workflows, so the release PR's required checks would +# never report and the main ruleset would block it forever. The App needs +# contents, pull requests and issues (labels) write on this repository; its +# client ID is the RELEASE_APP_CLIENT_ID variable and its key the +# RELEASE_APP_PRIVATE_KEY secret. +# +# The release job is called from here rather than started by the tag: one path +# to a release, and it does not depend on whether a tag created through the +# API fires a push event for the token that created it. +on: + push: + branches: [main] + +permissions: + contents: read + +concurrency: + group: release-please + cancel-in-progress: false + +jobs: + release-please: + name: Release PR + runs-on: ubuntu-latest + outputs: + release_created: ${{ steps.release.outputs.release_created }} + tag_name: ${{ steps.release.outputs.tag_name }} + steps: + - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + id: app + with: + client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + permission-contents: write + permission-pull-requests: write + permission-issues: write + - uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0 + id: release + with: + token: ${{ steps.app.outputs.token }} + config-file: release-please-config.json + manifest-file: .release-please-manifest.json + + release: + name: Release + needs: release-please + if: needs.release-please.outputs.release_created == 'true' + permissions: + contents: write + id-token: write + attestations: write + uses: ./.github/workflows/release.yml + with: + tag: ${{ needs.release-please.outputs.tag_name }} + secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2ea70bd..ba0307b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,24 +1,30 @@ name: Release -# A signed v* tag is the release. blairham/.github's go-release.yml builds and -# publishes it: the tests, GoReleaser (.goreleaser.yaml: binaries for every -# platform, notarized darwin builds, the Homebrew formula), a cosign-signed -# checksums.txt and SLSA build provenance. The signing identity is -# go-release.yml itself; SECURITY.md shows how to verify it. The notes are the -# tag's section of CHANGELOG.md. +# A release is release-please's: merging its release pull request tags vX.Y.Z +# and calls this workflow (release-please.yml). blairham/.github's +# go-release.yml builds and publishes it: the tests, GoReleaser +# (.goreleaser.yaml: binaries for every platform, notarized darwin builds, the +# Homebrew formula), a cosign-signed checksums.txt and SLSA build provenance. +# The signing identity is go-release.yml itself; SECURITY.md shows how to +# verify it. The notes are the tag's section of CHANGELOG.md, which +# release-please wrote. +# +# Pushing a tag by hand releases nothing: there is one path to a release. That +# also keeps the moving major alias (v4), which the alias job below pushes, +# from ever starting a release of its own. on: - push: - tags: - # Full versions only. The moving major alias (v4) is a tag too, and - # matching "v*" would make every alias update kick off a second, - # duplicate release. - - "v[0-9]+.[0-9]+.[0-9]+*" + workflow_call: + inputs: + tag: + description: "Tag to release (e.g. v4.7.3). Must already exist." + required: true + type: string # Re-run a release for a tag that already exists — after a failed publish, # say — without moving or re-creating the tag; or dry-run the build. workflow_dispatch: inputs: tag: - description: "Tag to release (e.g. v4.6.17). Must already exist. Leave empty for a dry run." + description: "Tag to release (e.g. v4.7.3). Must already exist. Leave empty for a dry run." required: false type: string dry-run: @@ -32,8 +38,35 @@ permissions: contents: read jobs: + # The version is release-please's answer, not a number someone typed: the + # tag must be the version its manifest records at that tag, so a release can + # only be the bump its commits call for, or the Release-As a maintainer + # gave it (CONTRIBUTING.md). A dry run builds whatever it is given and + # skips this. + version: + name: Version is release-please's + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + if: inputs.dry-run != true + with: + ref: ${{ inputs.tag }} + persist-credentials: false + - name: The tag is the version release-please recorded + if: inputs.dry-run != true + env: + TAG: ${{ inputs.tag }} + run: | + set -euo pipefail + want="v$(jq -r '."."' .release-please-manifest.json)" + if [ "$TAG" != "$want" ]; then + echo "::error::the tag is $TAG but .release-please-manifest.json at it records $want; release by merging release-please's pull request" + exit 1 + fi + release: name: Release + needs: version permissions: contents: write # the GitHub release and its assets # Keyless cosign and the provenance attestation both sign with the diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..5e5830a --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "4.7.2" +} diff --git a/AGENTS.md b/AGENTS.md index a351750..ba022eb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -93,7 +93,7 @@ The synced config files (`.golangci.yml`, `.pre-commit-config.yaml`, `.editorcon **The repo-root `action.yml` is a public composite action.** It downloads the release binary and runs hooks — a drop-in for `pre-commit/action` with no Python setup. `aws-sso-config`, `aws-config-management`, and `ghorg` consume it in their own CI, so a breaking change to its inputs (`version`, `extra_args`, `cache`, `install-only`) breaks those repos. The `pre-commit` CI job dogfoods it against this repo. -Releases: move `CHANGELOG.md`'s `[Unreleased]` under the version, push a `v*` tag → `release.yml` calls blairham/.github's `go-release.yml`, which runs the tests, then GoReleaser (`.goreleaser.yaml`) builds, signs, and notarizes, updates the `pre-commit` formula in `blairham/homebrew-tap` (a source build plus bottles of the release binaries, `homebrew_bottles`), attests provenance, and publishes the tag's CHANGELOG section as the notes; then the moving `v4` alias tag follows. +**Releases are release-please's.** Every pull request title is a Conventional Commit (`feat:` minor, `fix:` patch, `feat!:` breaking, major; `docs:`/`ci:`/`build:`/`refactor:`/`test:`/`chore:`/`style:` for nothing a user can see) — the `PR title` check (`.github/workflows/pr-title.yml`) fails anything else, and the squash-merged title is the changelog entry and the version bump. release-please (`.github/workflows/release-please.yml`, `release-please-config.json`, `.release-please-manifest.json`) keeps one release PR open with the next version and its `CHANGELOG.md` section; **merging it is the release** — never tag by hand, never edit the manifest or write a `CHANGELOG.md` section by hand. It runs on a GitHub App's token (`RELEASE_APP_CLIENT_ID` variable, `RELEASE_APP_PRIVATE_KEY` secret), since a PR opened with `GITHUB_TOKEN` never triggers the required checks. On the release PR the `PR title` check also re-checks every commit since the last tag; one release-please would skip is fixed with a commit-override block in the merged PR's body (CONTRIBUTING.md). When the release PR merges, release-please.yml calls `release.yml` with the new tag; `release.yml` first checks the tag is the version the manifest records, then calls blairham/.github's `go-release.yml`, which runs the tests, then GoReleaser (`.goreleaser.yaml`) builds, signs, and notarizes, updates the `pre-commit` formula in `blairham/homebrew-tap` (a source build plus bottles of the release binaries, `homebrew_bottles`), attests provenance, and publishes the tag's CHANGELOG section as the notes; then the moving `v4` alias tag follows. A pushed tag releases nothing. ⚠️ **release-please's bump is a proposal, not the parity version.** It bumps by commit type (`feat:` → 4.8.0), but the version tracks upstream parity (above): when the proposal would claim a parity line the release does not reach, or skip one it does, a `Release-As: X.Y.Z` footer in a PR body merged before the release sets the version — see CONTRIBUTING.md. ## Toolchain diff --git a/CHANGELOG.md b/CHANGELOG.md index 47cc546..47dd41c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,10 @@ including 4.6.16 were reconstructed from the GitHub release notes when this file was introduced; the full notes are on the [releases page](https://github.com/blairham/go-pre-commit/releases). -## [Unreleased] +From the release after 4.7.2 on, release-please writes each section from the +Conventional Commit titles of the pull requests it carries, and proposes the +next version from them; CONTRIBUTING.md says how a release keeps to upstream +parity anyway. ## [4.7.2] - 2026-11-15 @@ -628,7 +631,6 @@ file was introduced; the full notes are on the - First release of the rewrite: Python parity for `run` and `uninstall`, the `/v4` module path, and a GoReleaser release workflow. -[Unreleased]: https://github.com/blairham/go-pre-commit/compare/v4.7.2...HEAD [4.7.2]: https://github.com/blairham/go-pre-commit/compare/v4.7.1...v4.7.2 [4.7.1]: https://github.com/blairham/go-pre-commit/compare/v4.7.0...v4.7.1 [4.7.0]: https://github.com/blairham/go-pre-commit/compare/v4.6.17...v4.7.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 36e5a0b..0aa6d11 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -99,6 +99,46 @@ config. Redirect with `t.TempDir()` and `t.Setenv` — including `PRE_COMMIT_HOM - Commits must be signed. - Every `.go` file carries the two-line SPDX header (`Apache-2.0`); the pre-commit hook fails without it. +- **The pull request title is a [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/)**, + and it is the changelog entry and release-please's proposed version bump: + the repository squash-merges with the title as the commit subject, and + release-please reads the subjects. The required **PR title** check fails + one that is not. + + | Title | Proposed bump | [`CHANGELOG.md`](CHANGELOG.md) | + |---|---|---| + | `feat!:` / `fix!:` (any type with `!`) | major | ⚠ Breaking Changes | + | `feat:` | minor | Added | + | `fix:` (a compatible security fix too) | patch | Fixed | + | `perf:` / `revert:` | patch | Performance / Reverted | + | `docs:` `ci:` `build:` `refactor:` `test:` `chore:` `style:` | none | hidden | + + The text after the colon is the entry, so write it for someone upgrading. + A `BREAKING CHANGE: …` footer in the PR body also marks it breaking. +- **Releases are release-please's.** Every merge updates one standing pull + request, `chore(main): release X.Y.Z`, with the next version and its + `CHANGELOG.md` section. Merging it is the release: it tags `vX.Y.Z`, and + `release-please.yml` calls `release.yml` to publish it and then move the + `v4` alias tag. Never tag by hand. `Release-As: X.Y.Z` in a PR body forces + a version. A title that went wrong after the merge is fixed on the merged + pull request: add the messages it should have had between + `BEGIN_COMMIT_OVERRIDE` and `END_COMMIT_OVERRIDE` in its body, **separated + by blank lines** (one message per line reads as a single message with the + rest as its body). release-please starts at the first + `BEGIN_COMMIT_OVERRIDE` anywhere in the body, so never write that word + elsewhere in a PR body, even in backticks, and the block replaces the + subject even of a conventional commit. The PR title check on the release + pull request reads each commit as release-please will and fails on any + message that is not a Conventional Commit. +- **Versions track upstream parity, and release-please does not know that.** + `v4.7.x` means parity with Python pre-commit 4.7, so a release's version is + decided by what it brings to parity, not by commit types alone. + release-please's proposal is right for the usual release, `fix:` changes + inside the current parity line (4.7.2 → 4.7.3). When it is not — a `feat:` + that is still 4.7 parity would propose 4.8.0, and moving to 4.8 parity is a + deliberate step rather than a side effect of one `feat:` — put + `Release-As: X.Y.Z` in the body of a pull request merged before the + release, and release-please's pull request takes that version instead. ## Adding a language backend diff --git a/README.md b/README.md index b236a26..5f72c2e 100644 --- a/README.md +++ b/README.md @@ -243,19 +243,17 @@ There is no `lint` target: golangci-lint runs as a pre-commit hook (`pre-commit ## Releasing -Releases are automated with [GoReleaser](https://goreleaser.com) via the shared -release workflow in [blairham/.github](https://github.com/blairham/.github). Move -`CHANGELOG.md`'s `[Unreleased]` section under `## [X.Y.Z] - ` (the -release notes are that section, and a release without one fails), then tag: - -```bash -git tag -s v4.6.17 -git push origin v4.6.17 -``` - -The release workflow also moves the `v4` alias tag to the new release, which is -what `uses: blairham/go-pre-commit@v4` resolves to. Its tag trigger deliberately -matches full versions only, so moving the alias does not start a second release. +Releases are cut by [release-please](https://github.com/googleapis/release-please): +every merge to `main` updates one standing release pull request with the next +version and its `CHANGELOG.md` section, and merging that pull request is the +release. It tags `vX.Y.Z` and runs the shared release workflow in +[blairham/.github](https://github.com/blairham/.github), which builds with +[GoReleaser](https://goreleaser.com), publishes the release with that section as +its notes, and then moves the `v4` alias tag, which is what +`uses: blairham/go-pre-commit@v4` resolves to. Never tag by hand: a pushed tag +releases nothing. Pull request titles are Conventional Commits, and they are +the changelog; see [CONTRIBUTING.md](CONTRIBUTING.md), including how a release +keeps its version on the upstream parity line. CI builds, signs, and notarizes cross-platform binaries, publishes a GitHub release, and updates the Homebrew formula in [blairham/homebrew-tap](https://github.com/blairham/homebrew-tap) automatically. Versions track upstream parity: `v4.7.x` means feature parity with Python pre-commit 4.7. diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..dba6935 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "release-type": "go", + "include-component-in-tag": false, + "changelog-sections": [ + { "type": "feat", "section": "Added" }, + { "type": "fix", "section": "Fixed" }, + { "type": "perf", "section": "Performance" }, + { "type": "revert", "section": "Reverted" }, + { "type": "docs", "section": "Documentation", "hidden": true }, + { "type": "ci", "section": "CI", "hidden": true }, + { "type": "build", "section": "Build", "hidden": true }, + { "type": "refactor", "section": "Refactoring", "hidden": true }, + { "type": "test", "section": "Tests", "hidden": true }, + { "type": "chore", "section": "Chores", "hidden": true }, + { "type": "style", "section": "Style", "hidden": true } + ], + "packages": { + ".": {} + } +}