diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 69b6fa021e..71a6492c9a 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -11,6 +11,18 @@ - [ ] `make lint` passes (stage changes first, then run) - [ ] Tests added/updated for new or modified logic +## Release Note + + +```release-note +NONE +``` + ## Checklist - [ ] PR title follows [Conventional Commits](COMMITS.md) (correct type, `!` for breaking changes) - [ ] Commits are signed off (DCO) — human and human-directed agent sessions only diff --git a/.github/workflows/release-note-check.yml b/.github/workflows/release-note-check.yml new file mode 100644 index 0000000000..5593c76019 --- /dev/null +++ b/.github/workflows/release-note-check.yml @@ -0,0 +1,126 @@ +name: Release Note Check + +on: + pull_request: + # `labeled` and `unlabeled` are included so the recovery path for + # fork PRs works and label removal cannot strand a stale pass: adding + # release-note-action-required re-runs this check (which then accepts + # the already-present label without a write), and removing it re-runs + # validation, which re-adds the label (same-repo) or fails the check. + types: [opened, synchronize, reopened, edited, labeled, unlabeled] + branches: [main] + merge_group: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + release-note-check: + # The check already ran on the PR head; merge-group commits carry no + # pull_request event payload to re-check, so pass (skip) there. This + # keeps the check safe to mark required without stalling the queue. + if: github.event_name == 'pull_request' + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: read + outputs: + # Consumed by the sync-action-required-label job below; empty when + # the note is not action-required (or the bootstrap skip ran). + action-required: ${{ steps.check.outputs.action-required }} + steps: + # Check out the PR's base ref, not the PR head: the validator must + # come from a trusted revision so a PR cannot neuter its own check + # by editing scripts/check-release-note.sh. The PR body, title and + # commit subjects come from the API below, not from the checkout. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.pull_request.base.sha }} + fetch-depth: 1 + + # Fetch the PR body, title and commit subjects from the API rather + # than the event payload so every trigger type (including `edited`) + # sees the current state. Fork PRs work too: the PR object lives in + # this repository. + - name: Check release-note block + id: check + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + set -euo pipefail + # Bootstrap: the validator ships in this repository. When the + # PR's base predates the script (e.g. this PR itself), skip + # rather than fail; the check becomes enforcing once the script + # has landed on main. + if [[ ! -f scripts/check-release-note.sh ]]; then + echo "::warning::scripts/check-release-note.sh not present at the PR base; skipping release-note check." + exit 0 + fi + PR_JSON=$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}") + PR_BODY=$(jq -r '.body // ""' <<<"${PR_JSON}") + PR_TITLE=$(jq -r '.title // ""' <<<"${PR_JSON}") + # Per-item jq transform with --paginate is safe; no cross-page + # aggregation happens here (see docs/contributing/shell-scripting.md). + COMMIT_SUBJECTS=$(gh api --paginate "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/commits" \ + --jq '.[] | .commit.message | split("\n")[0]') + PR_BODY="${PR_BODY}" PR_TITLE="${PR_TITLE}" COMMIT_SUBJECTS="${COMMIT_SUBJECTS}" \ + bash scripts/check-release-note.sh + # The script appends action-required=1 to GITHUB_OUTPUT when the + # accepted note starts with "action required". + + # The release-notes gatherer lists a note under "Urgent Upgrade + # Notes" only when the PR carries this label (it also strips the + # "action required:" prefix from the note text), so keep the label in + # sync with the check result. This is the only job with + # pull-requests: write; the validation job above stays read-only. + sync-action-required-label: + if: github.event_name == 'pull_request' + needs: release-note-check + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: read + pull-requests: write + steps: + - name: Sync action-required label + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # gh cannot infer the repository without a checkout (it ignores + # GITHUB_REPOSITORY), so tell it explicitly. + GH_REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} + ACTION_REQUIRED: ${{ needs.release-note-check.outputs.action-required }} + run: | + set -euo pipefail + # Fork PRs run with a read-only token and cannot create or add + # labels. For an action-required note that must not be silent: + # without the label the gatherer publishes the note as an + # ordinary bullet and strips the "action required:" prefix, + # losing the Urgent Upgrade Notes entry. Fail instead, so a + # maintainer must add the label before merge; the `labeled` + # trigger then re-runs this check, which accepts the label + # without a write. + if [[ "${ACTION_REQUIRED:-}" == "1" ]]; then + # Already labeled (e.g. a maintainer added the label on a fork + # PR): accept it without a write — the fork's read-only token + # cannot mutate labels even when the label is present. + if gh pr view "${PR_NUMBER}" --json labels \ + --jq '.labels[].name' | grep -qx release-note-action-required; then + exit 0 + fi + gh label create release-note-action-required --color b60205 \ + --description "Release-note block starts with 'action required'" --force \ + || echo "::warning::could not create label (it may already exist)" + if ! gh pr edit "${PR_NUMBER}" --add-label release-note-action-required; then + echo "::error::This PR needs the release-note-action-required label (its release-note block starts with 'action required'), but the label could not be added — the token cannot write (a fork PR) or the API call failed. A maintainer must add it before merge." + exit 1 + fi + else + # Fails if the label is absent; that is the common case. + gh pr edit "${PR_NUMBER}" --remove-label release-note-action-required || true + fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7844fa5a3a..f8c29bf310 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,17 @@ on: push: tags: - "v[0-9]+.[0-9]+.[0-9]+*" + # Dry-run of the release-notes gather step only: measures the + # GITHUB_TOKEN rate-limit cost and runtime over a real tag range + # before a final release relies on it. Nothing is built or published. + workflow_dispatch: + inputs: + start-tag: + description: "Previous tag (gather PRs merged after this tag)" + required: true + end-tag: + description: "Tag to gather notes up to" + required: true permissions: contents: write @@ -11,8 +22,12 @@ permissions: jobs: release: - needs: [validate-agents, resolve-agents, recheck-tag] + if: github.event_name == 'push' + needs: [validate-agents, resolve-agents, recheck-tag, gather-release-notes] runs-on: ubuntu-24.04 + permissions: + contents: write + id-token: write # Historically ~2 minutes. Bounded so a hung publish cannot hold the # tag-agents sync (and the default 6h limit) open. timeout-minutes: 20 @@ -51,6 +66,16 @@ jobs: fi echo "current=${TAG} previous=${PREV:-}" + # Release notes come from `release-note` blocks in PR bodies (see + # COMMITS.md, "Release notes"), gathered by the + # gather-release-notes job below and passed here as an artifact, so + # the untrusted-PR-body parsing never runs inside this signing job. + - name: Download release notes + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: release-notes + path: ${{ runner.temp }} + # GoReleaser signs the release here. Installed CLIs only accept a # signature made by this workflow file, for the tag, on a # GitHub-hosted runner (internal/selfupdate/verify.go). Renaming this @@ -60,7 +85,10 @@ jobs: uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7.2.3 with: version: "~> v2" - args: release --clean + # --release-notes replaces the changelog with the markdown + # gathered from PR bodies above. The path is outside the + # checkout so the git tree stays clean. + args: release --clean --release-notes ${{ runner.temp }}/release-notes.md env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} @@ -85,6 +113,7 @@ jobs: fi validate-agents: + if: github.event_name == 'push' needs: resolve-agents # Permission contract of the called workflow. GitHub validates this at # parse time, before any job runs or `if:` is evaluated — a called @@ -114,6 +143,7 @@ jobs: EVAL_GH_TOKEN: ${{ secrets.EVAL_GH_TOKEN }} resolve-agents: + if: github.event_name == 'push' # Resolve agents main once at release start. Since agents#1010 the gate # itself reports the SHA it validated (validate-agents' agents_sha # output), and tag-agents prefers that; this job's resolution is the @@ -180,6 +210,7 @@ jobs: run: bash scripts/check-agents-gate-pin.sh recheck-tag: + if: github.event_name == 'push' # Second half of the tag-move guard. validate-agents clones fullsend by # tag name — the called workflow only accepts `main` or a `v*` ref and # uses `git clone --branch`, so it cannot be pinned to a SHA from this @@ -209,6 +240,7 @@ jobs: run: bash scripts/verify-release-tag.sh tag-agents: + if: github.event_name == 'push' # Sync the version tag to fullsend-ai/agents. Runs for all tags # including pre-releases — agents' own release.yml handles # pre-release semantics. Only runs after agents functional tests @@ -269,12 +301,14 @@ jobs: # published the binary and Slack reported only the missing agents tag. # Now the whole release stops here, so it needs its own signal; # otherwise a blocked release is silent on Slack. - needs: [validate-agents, resolve-agents, recheck-tag] + needs: [validate-agents, resolve-agents, recheck-tag, gather-release-notes] if: >- - always() + github.event_name == 'push' + && always() && (needs.validate-agents.result == 'failure' || needs.resolve-agents.result == 'failure' - || needs.recheck-tag.result == 'failure') + || needs.recheck-tag.result == 'failure' + || needs.gather-release-notes.result == 'failure') runs-on: ubuntu-24.04 timeout-minutes: 5 permissions: @@ -299,7 +333,8 @@ jobs: # passed, and their failure is reported by notify-release-blocked. needs: [release, tag-agents] if: >- - always() + github.event_name == 'push' + && always() && needs.release.result == 'success' && needs.tag-agents.result == 'failure' runs-on: ubuntu-24.04 @@ -318,3 +353,111 @@ jobs: PAYLOAD=$(jq -n --arg tag "${GITHUB_REF_NAME}" --arg url "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \ '{text: ":warning: Agents tag sync failed for `\($tag)`. The fullsend release shipped but the agents tag was not created. <\($url)|View run>"}') curl -fsS -X POST -H "Content-Type: application/json" -d "$PAYLOAD" "$SLACK_WEBHOOK" + + # Gathers the release notes from PR bodies in a read-only job, so the + # pinned release-notes binary (which parses contributor-controlled PR + # bodies) never runs inside the signing job. The rendered markdown is + # passed to the release job as an artifact. + gather-release-notes: + if: github.event_name == 'push' + runs-on: ubuntu-24.04 + # Generous on purpose: on a rate-limit error the release-notes tool + # waits for the reset window (up to an hour), matching the dry-run + # job's budget. + timeout-minutes: 60 + permissions: + contents: read + pull-requests: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + + - name: Generate release notes from PR bodies + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG: ${{ github.ref_name }} + run: | + set -euo pipefail + # Previous tag: for a final release, the last final release, so + # the notes span the whole release. For an rc, the tag + # immediately before this one (usually the previous rc), so an + # rc only lists what changed since that tag — matching + # GoReleaser's default previous-tag resolution for rc tags. + TAGS=$(git tag --merged "${TAG}^{commit}" --sort=-v:refname --list 'v[0-9]*.[0-9]*.[0-9]*') + case "${TAG}" in + *-*) PREV=$(printf '%s\n' "$TAGS" | grep -vxF -e "$TAG" | head -n1 || true) ;; + *) PREV=$(printf '%s\n' "$TAGS" | grep -v -e '-' | grep -vxF -e "$TAG" | head -n1 || true) ;; + esac + if [[ -z "${PREV}" ]]; then + # Static message: interpolating TAG here would need workflow-command + # escaping (%0A/%0D) to stay injection-safe. + echo "::error::Could not find a previous release tag before the current tag" + exit 1 + fi + # The gather logic (pinned release-notes install, JSON gather, + # rendering) lives in the shared script so the workflow_dispatch + # dry-run job measures the exact same path. Output goes outside + # the checkout: GoReleaser refuses a dirty git tree. + bash scripts/gather-release-notes.sh "${PREV}" "${TAG}" "${RUNNER_TEMP}" + + - name: Upload release notes + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: release-notes + path: ${{ runner.temp }}/release-notes.md + if-no-files-found: error + + gather-dry-run: + # Measures the release-notes gather step with the workflow's own + # GITHUB_TOKEN (the smoke test in #9704 used a personal token, whose + # budget differs). Records the core rate limit before and after plus + # the runtime, so the release job's timeout-minutes can be set from + # data instead of guesswork. Nothing is built or published. + if: github.event_name == 'workflow_dispatch' + runs-on: ubuntu-24.04 + # Generous on purpose: on a rate-limit error the release-notes tool + # waits for the reset window (up to an hour). The point of the dry + # run is to observe that behaviour, not to cut it off at the release + # job's 20 minutes. + timeout-minutes: 60 + permissions: + contents: read + pull-requests: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + + - name: Record rate limit before + env: + # GITHUB_TOKEN (not GH_TOKEN): the release-notes tool only reads + # GITHUB_TOKEN; gh accepts it too. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh api rate_limit --jq '.resources.core | "core before \(.remaining)/\(.limit) (reset \(.reset))"' + + - name: Gather release notes (dry run) + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + START_TAG: ${{ inputs.start-tag }} + END_TAG: ${{ inputs.end-tag }} + run: | + set -euo pipefail + SECONDS=0 + bash scripts/gather-release-notes.sh "${START_TAG}" "${END_TAG}" "${RUNNER_TEMP}" + echo "gather runtime: ${SECONDS}s" + echo "gathered notes:" + # The notes derive from contributor-controlled PR bodies. Wrap + # the output in a stop-commands token so nothing in it can be + # interpreted as a workflow command (::error::, ::add-mask::, + # ::stop-commands::). The token is runner-generated and not + # present in the output. + STOP_TOKEN="stop-commands-$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n')" + echo "::stop-commands::${STOP_TOKEN}" + cat "${RUNNER_TEMP}/release-notes.md" + echo "::${STOP_TOKEN}::" + + - name: Record rate limit after + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh api rate_limit --jq '.resources.core | "core after \(.remaining)/\(.limit) (reset \(.reset))"' diff --git a/.gitlint b/.gitlint index fab3a5e1ca..e8216dfd8b 100644 --- a/.gitlint +++ b/.gitlint @@ -7,7 +7,6 @@ extra-path=gitlint_rules/ line-length=100 # Conventional commit types allowed in this repo. -# Matches the types documented in COMMITS.md and parsed by -# GoReleaser for release notes. +# Matches the types documented in COMMITS.md. [contrib-title-conventional-commits] types=feat,fix,refactor,docs,test,chore,ci,perf,build,style diff --git a/.goreleaser.yml b/.goreleaser.yml index 29b3d9a2bf..b89d2f3e4f 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -2,7 +2,7 @@ version: 2 git: # Ignore major-version floating tags (v0, v1, ...) so they don't - # confuse GoReleaser's previous-tag detection for changelogs. + # confuse GoReleaser's tag detection. ignore_tags: - v0 - v1 @@ -31,35 +31,11 @@ archives: checksum: name_template: checksums.txt -changelog: - use: github - sort: asc - filters: - exclude: - - '^Merge ' - - '^ci(\(.*\))?:' - - '^docs(\(.*\))?:' - - '^test(\(.*\))?:' - - '^chore(\(.*\))?:' - - '^build(\(.*\))?:' - - '^style(\(.*\))?:' - # Groups match in list order and the first match wins, so Breaking - # Changes must stay first to pull `!` commits out of the type groups. - groups: - - title: Breaking Changes - regexp: '^[a-z]+(\([^)]*\))?!:' - order: 0 - - title: Features - regexp: '^.*?feat(\([^)]+\))??!?:.+$' - order: 1 - - title: Bug Fixes - regexp: '^.*?fix(\([^)]+\))??!?:.+$' - order: 2 - - title: Refactoring - regexp: '^.*?refactor(\([^)]+\))??!?:.+$' - order: 3 - - title: Others - order: 999 +# Release notes are not built from commit subjects. The release +# workflow gathers `release-note` blocks from merged PR bodies with the +# Kubernetes release-notes tool and passes the markdown to GoReleaser +# via `--release-notes` (see .github/workflows/release.yml and +# COMMITS.md, "Release notes"). # `fullsend self-update` verifies this signature. Read the comment on the # GoReleaser step in .github/workflows/release.yml before changing it. @@ -79,7 +55,7 @@ release: name: fullsend name_template: "{{ .Tag }}{{ if and .TagSubject (ne .TagSubject .Tag) }}: {{ .TagSubject }}{{ end }}" prerelease: auto - # The changelog above lists fullsend commits only. The agents release + # The release notes above list fullsend changes only. The agents release # for the same tag (created by release.yml's tag-agents job) carries the # agents changelog, so link it from every release. footer: | diff --git a/AGENTS.md b/AGENTS.md index c5e7f53275..cf3de2801c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -41,8 +41,13 @@ full documentation site. binary to avoid stale state. See [Go Code § Running the fullsend CLI](docs/contributing/go-code.md#running-the-fullsend-cli). - Follow [COMMITS.md](COMMITS.md) when writing or reviewing commit messages - and PR titles. Commit prefixes feed release notes; breaking changes require - the `!` marker in both commit subjects and PR titles; a missing `!` is an + and PR titles. Every PR must carry a `release-note` block in its body (the + Release Note Check workflow validates it); release notes come from those + blocks, not commit prefixes. + Breaking changes require the `!` marker in both commit subjects and PR + titles, and an `action required` release-note block (CI labels such PRs + `release-note-action-required` so the note lands under Urgent Upgrade + Notes); a missing `!` is an important-severity review finding; forbidden combinations (e.g. `fix(ci)`/`fix(e2e)`) are enforced as errors. - Human and human-driven agent commits require DCO sign-off (`git commit -s`); diff --git a/COMMITS.md b/COMMITS.md index c3455ab1c4..2804b04ad3 100644 --- a/COMMITS.md +++ b/COMMITS.md @@ -1,6 +1,8 @@ # Commit Messages -This project uses [Conventional Commits](https://www.conventionalcommits.org/). Every commit on `main` feeds the auto-generated release notes (via GoReleaser), so getting the prefix right matters. You **must** consult this file when writing or reviewing commit messages. +This project uses [Conventional Commits](https://www.conventionalcommits.org/). Gitlint enforces the prefixes on every commit and PR title, so getting them right matters. You **must** consult this file when writing or reviewing commit messages. + +Release notes no longer come from commit subjects. They come from a `release-note` block in the PR body — see [Release notes](#release-notes) below. ## Format @@ -14,22 +16,48 @@ This project uses [Conventional Commits](https://www.conventionalcommits.org/). ## Types -| Type | Purpose | Appears in release notes? | +| Type | Purpose | Needs a release-note entry? | |---|---|---| -| `feat` | New user-facing functionality | Yes — under **Features** | -| `fix` | Bug fix visible to users | Yes — under **Bug Fixes** | -| `refactor` | Code restructuring (no behavior change) | Yes — under **Refactoring** | -| `docs` | Documentation only | No | -| `test` | Adding or updating tests | No | -| `chore` | Maintenance (CI, deps, tooling) | No | -| `ci` | CI/CD pipeline changes | No | -| `perf` | Performance improvement | Yes — under **Others** | -| `build` | Build system or dependency changes | No | -| `style` | Formatting only, no logic change | No | +| `feat` | New user-facing functionality | Yes | +| `fix` | Bug fix visible to users | Yes | +| `refactor` | Code restructuring (no behavior change) | Usually `NONE` | +| `docs` | Documentation only | Usually `NONE` | +| `test` | Adding or updating tests | `NONE` | +| `chore` | Maintenance (CI, deps, tooling) | `NONE` | +| `ci` | CI/CD pipeline changes | `NONE` | +| `perf` | Performance improvement | Yes | +| `build` | Build system or dependency changes | `NONE` | +| `style` | Formatting only, no logic change | `NONE` | + +## Release notes + +Every PR must contain a fenced `release-note` block in its body. The PR +template carries the block with a `NONE` default. CI rejects a PR whose +block is missing or empty. + +Write the block for users, not for reviewers. One or more lines of prose. +Write `NONE` when the change has no effect users can see. Start the block +with `action required` when the change breaks something. + +At release time, the release pipeline reads the blocks from the merged +PRs in the tag range (with the Kubernetes `release-notes` tool), skips +`NONE` entries, and publishes the gathered markdown. Commit subjects no +longer feed the release notes. + +Example block: + +```release-note +action required: the `role` field in harness files is now required. +Add `role: ` to any harness file that lacks it. +``` ## `feat` is for end users -The `feat` prefix populates the **Features** section of our release notes. End users read that list to decide whether to upgrade. Reserve `feat` for changes an end user would recognize as new capability: +Commit types classify git history and are gitlint-enforced; the PR-body +release-note block controls what end users read in the release notes. +The `feat` prefix still marks user-facing functionality, so the history +stays meaningful. Reserve `feat` for changes an end user would recognize +as new capability: - A new CLI command or flag they can invoke - A new behavior they interact with (e.g., the agent now comments on their PR with a new kind of analysis) @@ -45,7 +73,10 @@ The `feat` prefix populates the **Features** section of our release notes. End u Apply the same discipline to `fix` — bumping a dependency version is `chore`, not `fix`, unless it corrects a user-visible bug. Removing a trailing blank line is `style`, not `fix`. -**When in doubt, prefer `refactor` or `chore` over `feat` or `fix`.** A change miscategorized as `refactor` is harmless — it shows up in a lower section of the release notes. A change miscategorized as `feat` erodes the signal of the Features list. +**When in doubt, prefer `refactor` or `chore` over `feat` or `fix`.** A +miscategorized type mislabels the git history, not the release notes — +the PR-body release-note block decides what users read — but an honest +history is still worth keeping. ## Scope @@ -53,7 +84,7 @@ The parenthesized scope is optional but encouraged. Use it to identify the subsy ### Forbidden type + scope combinations -Some type/scope pairs are **enforced as errors** by gitlint (rule `UC1`). These combinations mislead users by putting infrastructure changes in user-facing release-note sections. +Some type/scope pairs are **enforced as errors** by gitlint (rule `UC1`). These combinations mislead users by putting infrastructure changes in user-facing release-note territory. | Forbidden | Why | Use instead | |---|---|---| @@ -64,16 +95,23 @@ Some type/scope pairs are **enforced as errors** by gitlint (rule `UC1`). These ## Breaking changes -Breaking changes **must** be marked in both commit messages and PR titles. -GoReleaser builds release notes from the subject line of every commit in the -release range (`use: github` in `.goreleaser.yml`). PRs land through the merge -queue as merge commits, whose `Merge pull request …` subjects are excluded, so -the PR title does not appear in the release notes: each breaking commit's own -subject must carry the `!`. A breaking commit whose subject lacks `!` is filed -under Features, Bug Fixes, or Refactoring instead of **Breaking Changes**, so -users reading the release notes get no warning. This has caused -real incidents — users upgraded with no warning that their agents would stop -working (#8366). +Breaking changes **must** be marked in three places: the `!` suffix in +every commit subject and the PR title, and an `action required` +`release-note` block in the PR body. + +The release-note block is what users see. When the block starts with +`action required`, the release-note check labels the PR +`release-note-action-required`, and the release pipeline lists the note +under **Urgent Upgrade Notes** in the published release notes (the +gatherer strips the `action required:` prefix from the note text itself). +Fork PRs run with a read-only token, so CI cannot label them; the check +fails instead until a maintainer adds the label. +The `!` marker stays required for reviewers and tooling. CI rejects a +`NONE` release-note block — and any block that does not start with +`action required` — when the PR title or any commit subject carries the +`!` marker, so a breaking PR cannot ship without a warning. This closes +the gap that caused real incidents — users upgraded +with no warning that their agents would stop working (#8366). **How to mark a breaking change:** @@ -81,9 +119,9 @@ working (#8366). 2. Include a `BREAKING CHANGE:` trailer in the commit body explaining what breaks and how to migrate Both the `!` suffix and the trailer are required. The `!` suffix signals the -breaking change to human reviewers and puts the commit under **Breaking -Changes** in the release notes; GoReleaser only reads subjects, so a trailer -alone does not. The trailer tells users what to do about it. +breaking change to human reviewers and to the release-note CI check. The +trailer tells readers of the commit what to do about it. The `action required` +release-note block tells users. **How to tell if your change is breaking:** @@ -130,6 +168,8 @@ When reviewing PRs, check that commit messages and PR titles use the correct typ - **Missing `!` on breaking changes** — if the diff removes a field, renames a flag, adds a required input, tightens validation, or otherwise breaks existing usage, the PR title and commit messages **must** carry the `!` - suffix. Flag a missing `!` as an important-severity finding. Every commit - subject matters because GoReleaser lists each one in the user-facing release - notes. The PR title is not one of them, because PRs land as merge commits. + suffix. Flag a missing `!` as an important-severity finding. +- **Missing or wrong `release-note` block** — every PR needs a valid block. + A breaking PR (title or commit subject carries `!`) must start its block + with `action required`; a `NONE` block there is an important-severity + finding. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cd233d7f77..f7838c473a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,12 +43,22 @@ contribution. - On macOS or a Linux distribution other than Ubuntu, `make ci-local` runs the same checks in a container that matches the CI runner, so local results predict CI (see [`hack/ci-local`](hack/ci-local/README.md)). +- Every PR must carry a `release-note` block in its body — the PR template + provides one with a `NONE` default. The Release Note Check workflow + rejects a PR whose block is missing or empty. See + [COMMITS.md](COMMITS.md#release-notes) for how to write it. - **If your PR introduces a breaking change**, the PR title and every breaking commit's subject must carry the `!` suffix (e.g., `feat(harness)!: require - role field`). GoReleaser builds release notes from commit subjects, not the - PR title — a missing `!` on a breaking commit means users get no warning - before upgrading. See [COMMITS.md](COMMITS.md#breaking-changes) for how to - identify breaking changes and what to include in the commit body. + role field`), and the PR's `release-note` block must start with + `action required`. The block is what users see — CI labels the PR + `release-note-action-required` so the note is listed under **Urgent + Upgrade Notes** in the release, and CI rejects a `NONE` block (or any + block without the prefix) on a PR that carries the `!` marker, so a + breaking change cannot ship without a warning. Fork PRs cannot be + labeled by CI (read-only token); a maintainer must add the label + before merge. See + [COMMITS.md](COMMITS.md#breaking-changes) for how to identify breaking + changes and what to include in the commit body. - Wrap prose in Markdown files at about 80 columns, so diffs show only the lines you changed. Tables, code blocks, headings, and long URLs are exceptions. See diff --git a/Makefile b/Makefile index e4e9e0f2e1..d79ee24e16 100644 --- a/Makefile +++ b/Makefile @@ -187,6 +187,9 @@ define run-timed endef script-test: + $(call run-timed,bash scripts/check-release-note-test.sh) + $(call run-timed,bash scripts/render-release-notes-test.sh) + $(call run-timed,bash scripts/gather-release-notes-test.sh) $(call run-timed,bash scripts/check-live-test-relevance-test.sh) $(call run-timed,bash scripts/check-e2e-authorization-test.sh) $(call run-timed,bash scripts/vouch-sweep-test.sh) diff --git a/docs/contributing/vouch-system.md b/docs/contributing/vouch-system.md index 2c8fc16a6e..41a23c6260 100644 --- a/docs/contributing/vouch-system.md +++ b/docs/contributing/vouch-system.md @@ -10,4 +10,4 @@ - The vouch gate is separate from the e2e authorization gate. Vouch determines whether a PR stays open; e2e authorization determines whether tests run. - PRs from unvouched external contributors are automatically closed with a comment linking to the vouch process. The PR is closed before the comment is posted, and the comment (marker ``) is posted once per PR, even when overlapping runs or a reopen close it again. - An API error never closes a PR: a failed `VOUCHED.td` read aborts the sweep, and a failed permission lookup skips that PR until the next run. -- PRs should follow the PR template structure: Summary, Related Issue, Changes, Testing, Checklist. +- PRs should follow the PR template structure: Summary, Related Issue, Changes, Testing, Release Note, Checklist. diff --git a/gitlint_rules/forbidden_type_scope.py b/gitlint_rules/forbidden_type_scope.py index 833d3c309e..7def4a2bf7 100644 --- a/gitlint_rules/forbidden_type_scope.py +++ b/gitlint_rules/forbidden_type_scope.py @@ -1,9 +1,10 @@ """Gitlint rule that forbids misleading type+scope combinations. -Types like ``feat`` and ``fix`` appear in user-facing release notes. -Scopes like ``ci`` and ``e2e`` describe infrastructure, not user-visible -changes. Using them together pollutes the release notes with entries -that mean nothing to end users. +Types like ``feat`` and ``fix`` describe user-facing changes, which now +belong in the PR body's ``release-note`` block rather than the commit +subject. Scopes like ``ci`` and ``e2e`` describe infrastructure, not +user-visible changes. Using them together produces commit subjects that +misleadingly suggest user-facing infrastructure changes. """ import re diff --git a/gitlint_rules_test.py b/gitlint_rules_test.py index 83705cb2b1..58aa8c95af 100644 --- a/gitlint_rules_test.py +++ b/gitlint_rules_test.py @@ -5,7 +5,6 @@ from pathlib import Path import pytest -import yaml from gitlint.rules import RuleViolation from gitlint_rules.forbidden_type_scope import ForbiddenTypeScope @@ -92,7 +91,7 @@ def test_ignores_non_conventional(title): assert not violations -# --- .gitlint, COMMITS.md and .goreleaser.yml must agree on commit types --- +# --- .gitlint and COMMITS.md must agree on commit types --- ROOT = Path(__file__).parent @@ -104,7 +103,7 @@ def gitlint_types(): def commits_md_rows(): - """Map type -> 'Appears in release notes?' cell from the COMMITS.md types table.""" + """Map type -> 'Needs a release-note entry?' cell from the COMMITS.md types table.""" rows = re.findall( r"^\| `(\w+)` \| [^|]+ \| ([^|]+) \|$", (ROOT / "COMMITS.md").read_text(), re.M ) @@ -113,11 +112,3 @@ def commits_md_rows(): def test_gitlint_types_match_commits_md(): assert gitlint_types() == set(commits_md_rows()) - - -@pytest.mark.parametrize( - "ctype", sorted(t for t, notes in commits_md_rows().items() if notes == "No") -) -def test_hidden_types_excluded_from_release_notes(ctype): - goreleaser = yaml.safe_load((ROOT / ".goreleaser.yml").read_text()) - assert f"^{ctype}(\\(.*\\))?:" in goreleaser["changelog"]["filters"]["exclude"] diff --git a/renovate.json b/renovate.json index 06d991e0ea..736a0e509f 100644 --- a/renovate.json +++ b/renovate.json @@ -142,6 +142,16 @@ "executionMode": "branch" } }, + { + "description": "After a kubernetes/release bump, refresh RELEASE_NOTES_SHA256 in gather-release-notes.sh, checked against the digest GitHub records for the asset. Human-reviewed: the binary parses contributor-controlled PR bodies inside the release path.", + "matchPackageNames": ["kubernetes/release"], + "automerge": false, + "postUpgradeTasks": { + "commands": ["bash scripts/renovate/update-release-notes-checksum.sh"], + "fileFilters": ["scripts/gather-release-notes.sh"], + "executionMode": "branch" + } + }, { "description": "After an fd bump, refresh FD_SHA256_{AMD64,ARM64} in the sandbox Containerfile. fd ships no checksum file, so the download is checked against the digest GitHub records for each release asset (#9121)", "matchPackageNames": ["sharkdp/fd"], @@ -517,6 +527,17 @@ "depNameTemplate": "sigstore/gitsign", "datasourceTemplate": "github-releases", "extractVersionTemplate": "^v(?\\d+\\.\\d+\\.\\d+)$" + }, + { + "customType": "regex", + "description": "Track the pinned Kubernetes release-notes tool in gather-release-notes.sh. RELEASE_NOTES_SHA256 is refreshed in the same PR by postUpgradeTasks (scripts/renovate/update-release-notes-checksum.sh), checked against the digest GitHub records for the asset.", + "managerFilePatterns": ["/^scripts/gather-release-notes\\.sh$/"], + "matchStrings": [ + "releases/download/v(?[^/]+)/release-notes-amd64-linux" + ], + "depNameTemplate": "kubernetes/release", + "datasourceTemplate": "github-releases", + "extractVersionTemplate": "^v(?.*)$" } ] } diff --git a/scripts/check-release-note-test.sh b/scripts/check-release-note-test.sh new file mode 100755 index 0000000000..0e9b473347 --- /dev/null +++ b/scripts/check-release-note-test.sh @@ -0,0 +1,376 @@ +#!/usr/bin/env bash +# check-release-note-test.sh — Tests for check-release-note.sh +# +# Run from the repo root: +# bash scripts/check-release-note-test.sh + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SCRIPT="${SCRIPT_DIR}/check-release-note.sh" +FAILURES=0 + +run_case() { + local desc="$1" expected="$2" + shift 2 + local actual + if "$@" bash "${SCRIPT}" >/dev/null 2>&1; then + actual="pass" + else + actual="fail" + fi + if [[ "${actual}" == "${expected}" ]]; then + echo "ok — ${desc}" + else + echo "FAIL — ${desc} (expected ${expected}, got ${actual})" + FAILURES=$((FAILURES + 1)) + fi +} + +# Like run_case, but also asserts on the script's GITHUB_OUTPUT: whether +# the action-required=1 output is present. That output drives the +# release-note-action-required label, which is the only way a note +# lands under Urgent Upgrade Notes. +run_marker_case() { + local desc="$1" expected_exit="$2" expected_marker="$3" + shift 3 + local actual_exit actual_marker="absent" + local out + out=$(mktemp) + if GITHUB_OUTPUT="${out}" "$@" bash "${SCRIPT}" >/dev/null 2>&1; then + actual_exit="pass" + else + actual_exit="fail" + fi + if grep -qx 'action-required=1' "${out}"; then + actual_marker="present" + fi + rm -f "${out}" + if [[ "${actual_exit}" == "${expected_exit}" && "${actual_marker}" == "${expected_marker}" ]]; then + echo "ok — ${desc}" + else + echo "FAIL — ${desc} (expected ${expected_exit}/${expected_marker}, got ${actual_exit}/${actual_marker})" + FAILURES=$((FAILURES + 1)) + fi +} + +BODY_WITH_NONE="## Summary + +Does a thing. + +\`\`\`release-note +NONE +\`\`\` +" + +BODY_WITH_NOTE="## Summary + +Does a thing. + +\`\`\`release-note +The fullsend CLI now frobs the widget. +\`\`\` +" + +BODY_WITH_ACTION_REQUIRED="## Summary + +Breaks a thing. + +\`\`\`release-note +action required: the widget flag is now required. +\`\`\` +" + +BODY_EMPTY_BLOCK="## Summary + +Does a thing. + +\`\`\`release-note +\`\`\` +" + +BODY_NO_BLOCK="## Summary + +Does a thing. +" + +BODY_INDENTED_NONE="## Summary + +\`\`\`release-note + NONE +\`\`\` +" + +BODY_NONE_MIXED_CASE="## Summary + +\`\`\`release-note +None +\`\`\` +" + +BODY_NA="## Summary + +\`\`\`release-note +n/a +\`\`\` +" + +BODY_QUOTED_NONE="## Summary + +\`\`\`release-note +\"NONE\" +\`\`\` +" + +BODY_QUOTED_NA="## Summary + +\`\`\`release-note +\"n/a\" +\`\`\` +" + +BODY_QUOTED_NA_LOWER="## Summary + +\`\`\`release-note +'na' +\`\`\` +" + +BODY_QUOTED_NONE_UPPER="## Summary + +\`\`\`release-note +'NONE' +\`\`\` +" + +BODY_NONE_THEN_ACTION_REQUIRED="## Summary + +\`\`\`release-note +NONE +action required: the widget flag is now required. +\`\`\` +" + +BODY_NOTE_WITH_NA_LINE_PLUS_NONE="## Summary + +\`\`\`release-note +Fixed foo. +na +\`\`\` + +\`\`\`release-note +NONE +\`\`\` +" + +# A fence line with real trailing spaces (web editors add them), built at +# runtime so the file itself carries no trailing whitespace for +# pre-commit to strip. +BODY_FENCE_TRAILING_SPACES=$(sed 's/^```release-note$/```release-note /' <<<"${BODY_WITH_NOTE}") + +BODY_FENCE_VARIANT="## Summary + +\`\`\`release-note-foo +Fixed foo. +\`\`\` +" + +BODY_INDENTED_CLOSING_FENCE="## Summary + +\`\`\`release-note +Fixed foo. + \`\`\` + +## Later section +" + +BODY_ACTION_REQUIRED_MIXED_CASE="## Summary + +\`\`\`release-note +Action Required: the widget flag is now required. +\`\`\` +" + +BODY_MULTI_LINE="## Summary + +\`\`\`release-note +The CLI now supports frobbing. + +Users must pass --frob. +\`\`\` +" + +BODY_NONE_PLUS_LINES="## Summary + +\`\`\`release-note +NONE + +Except this extra line. +\`\`\` +" + +# Real CRLF bytes: the script must strip carriage returns before parsing. +BODY_CRLF_NONE=$'## Summary\r\n\r\n```release-note\r\nNONE\r\n```\r\n' + +BODY_SECOND_NONE_BLOCK="## Summary + +\`\`\`release-note +action required: the widget flag is now required. +\`\`\` + +\`\`\`release-note +NONE +\`\`\` +" + +BODY_RELEASE_NOTE_NONE_TAG="## Summary + +\`\`\`release-note +action required: the widget flag is now required. +\`\`\` + +/release-note-none +" + +BODY_NOTE_PLUS_LEFTOVER_NONE="## Summary + +\`\`\`release-note +The fullsend CLI now frobs the widget. +\`\`\` + +\`\`\`release-note +NONE +\`\`\` +" + +BODY_ACTION_REQUIRED_NON_BREAKING="## Summary + +\`\`\`release-note +action required: the widget flag is now required. +\`\`\` +" + +BREAKING_TITLE="feat(harness)!: require role field" + +# Valid blocks pass. +run_case "NONE block passes" pass env PR_BODY="$BODY_WITH_NONE" +run_case "prose block passes" pass env PR_BODY="$BODY_WITH_NOTE" +run_case "action required block passes" pass env PR_BODY="$BODY_WITH_ACTION_REQUIRED" +run_case "indented NONE passes" pass env PR_BODY="$BODY_INDENTED_NONE" +run_case "multi-line block passes" pass env PR_BODY="$BODY_MULTI_LINE" + +# NONE variants the gatherer treats as "no note" — all pass for +# non-breaking PRs (the note is simply not published). +run_case "None (mixed case) passes" pass env PR_BODY="$BODY_NONE_MIXED_CASE" +run_case "n/a block passes" pass env PR_BODY="$BODY_NA" +run_case "NONE plus extra lines passes (published as a note)" pass \ + env PR_BODY="$BODY_NONE_PLUS_LINES" + +# Quoted sentinels are rejected: the gatherer publishes quoted text +# literally instead of treating it as "no note". +run_case "quoted NONE fails (write NONE without quotes)" fail env PR_BODY="$BODY_QUOTED_NONE" +run_case "quoted n/a fails" fail env PR_BODY="$BODY_QUOTED_NA" +run_case "quoted na fails" fail env PR_BODY="$BODY_QUOTED_NA_LOWER" +run_case "quoted 'NONE' (mixed case) fails" fail env PR_BODY="$BODY_QUOTED_NONE_UPPER" + +# Malformed fences are rejected: the gatherer would silently skip them, +# so the note would never be published. +run_case "fence with trailing spaces fails" fail env PR_BODY="$BODY_FENCE_TRAILING_SPACES" +run_case "release-note-foo fence fails" fail env PR_BODY="$BODY_FENCE_VARIANT" + +BODY_MISSING_CLOSING_FENCE="## Summary + +\`\`\`release-note +Fixed foo. + +## Later section +" + +# An indented closing fence is not a closer for the gatherer, so such a +# block must fail CI instead of being silently skipped at release. +run_case "indented closing fence fails" fail \ + env PR_BODY="$BODY_INDENTED_CLOSING_FENCE" +run_case "missing closing fence fails" fail \ + env PR_BODY="$BODY_MISSING_CLOSING_FENCE" + +# Missing or empty blocks fail. +run_case "no block fails" fail env PR_BODY="$BODY_NO_BLOCK" +run_case "empty block fails" fail env PR_BODY="$BODY_EMPTY_BLOCK" +run_case "empty body fails" fail env PR_BODY="" + +# NONE with a breaking marker fails. +run_case "NONE with breaking PR title fails" fail \ + env PR_BODY="$BODY_WITH_NONE" PR_TITLE="feat(harness)!: require role field" +run_case "NONE with breaking commit subject fails" fail \ + env PR_BODY="$BODY_WITH_NONE" PR_TITLE="feat(harness): add thing" \ + COMMIT_SUBJECTS=$'feat(harness): add thing\nfix(mint)!: drop old flag' +run_case "NONE with scoped breaking title fails" fail \ + env PR_BODY="$BODY_WITH_NONE" PR_TITLE="fix!: remove flag" + +# NONE variants and exclusion markers with a breaking marker fail: the +# gatherer would drop the PR, silently losing the upgrade warning. +run_case "None (mixed case) with breaking title fails" fail \ + env PR_BODY="$BODY_NONE_MIXED_CASE" PR_TITLE="$BREAKING_TITLE" +run_case "n/a with breaking title fails" fail \ + env PR_BODY="$BODY_NA" PR_TITLE="$BREAKING_TITLE" +run_case "quoted NONE with breaking title fails" fail \ + env PR_BODY="$BODY_QUOTED_NONE" PR_TITLE="$BREAKING_TITLE" +run_case "second NONE block with breaking title fails" fail \ + env PR_BODY="$BODY_SECOND_NONE_BLOCK" PR_TITLE="$BREAKING_TITLE" +run_case "/release-note-none tag with breaking title fails" fail \ + env PR_BODY="$BODY_RELEASE_NOTE_NONE_TAG" PR_TITLE="$BREAKING_TITLE" +run_case "CRLF NONE with breaking title fails" fail \ + env PR_BODY="$BODY_CRLF_NONE" PR_TITLE="$BREAKING_TITLE" + +# is_none_block must match the whole block, not any single line: a +# NONE line followed by more content is a real note, not a sentinel. +run_case "NONE then action-required line with breaking title fails (not a NONE block)" fail \ + env PR_BODY="$BODY_NONE_THEN_ACTION_REQUIRED" PR_TITLE="$BREAKING_TITLE" +run_case "note with an na line plus leftover NONE block fails" fail \ + env PR_BODY="$BODY_NOTE_WITH_NA_LINE_PLUS_NONE" PR_TITLE="feat(harness): add thing" + +# A real note plus a leftover NONE block fails even without a breaking +# marker: the gatherer would drop the whole PR and the note would never +# be published. +run_case "note plus leftover NONE block fails (non-breaking)" fail \ + env PR_BODY="$BODY_NOTE_PLUS_LEFTOVER_NONE" PR_TITLE="feat(harness): add thing" + +# NONE without a breaking marker passes even when title/commits are set. +run_case "NONE with non-breaking title and commits passes" pass \ + env PR_BODY="$BODY_WITH_NONE" PR_TITLE="feat(harness): add thing" \ + COMMIT_SUBJECTS=$'feat(harness): add thing\nfix(mint): correct flag' + +# A breaking PR must start its block with "action required" — the +# gatherer strips that prefix and lists the note under "Urgent Upgrade +# Notes" only for labeled, action-required PRs. +run_case "breaking title with prose note fails (no action required)" fail \ + env PR_BODY="$BODY_WITH_NOTE" PR_TITLE="$BREAKING_TITLE" +run_case "breaking title with action required note passes" pass \ + env PR_BODY="$BODY_WITH_ACTION_REQUIRED" PR_TITLE="$BREAKING_TITLE" +run_case "breaking commit subject with action required note passes" pass \ + env PR_BODY="$BODY_WITH_ACTION_REQUIRED" PR_TITLE="feat(harness): add thing" \ + COMMIT_SUBJECTS=$'feat(harness): add thing\nfix(mint)!: drop old flag' +run_case "action required in mixed case with breaking title passes" pass \ + env PR_BODY="$BODY_ACTION_REQUIRED_MIXED_CASE" PR_TITLE="$BREAKING_TITLE" + +# The action-required GITHUB_OUTPUT drives the Urgent label. It must be +# present for a valid breaking PR and for any accepted note that starts +# with "action required", and absent otherwise. +run_marker_case "breaking PR emits action-required marker" pass present \ + env PR_BODY="$BODY_WITH_ACTION_REQUIRED" PR_TITLE="$BREAKING_TITLE" +run_marker_case "non-breaking prose note emits no marker" pass absent \ + env PR_BODY="$BODY_WITH_NOTE" PR_TITLE="feat(harness): add thing" +run_marker_case "NONE block emits no marker" pass absent \ + env PR_BODY="$BODY_WITH_NONE" PR_TITLE="feat(harness): add thing" +run_marker_case "action-required note without '!' still emits marker" pass present \ + env PR_BODY="$BODY_ACTION_REQUIRED_NON_BREAKING" PR_TITLE="feat(harness): add thing" + +# A `!` in prose (not a Conventional Commits marker) must not trip the check. +run_case "NONE with exclamation in title prose passes" pass \ + env PR_BODY="$BODY_WITH_NONE" PR_TITLE="feat(harness): wow!" + +if [[ "${FAILURES}" -gt 0 ]]; then + echo "${FAILURES} test(s) failed" + exit 1 +fi +echo "all tests passed" diff --git a/scripts/check-release-note.sh b/scripts/check-release-note.sh new file mode 100755 index 0000000000..acc114c648 --- /dev/null +++ b/scripts/check-release-note.sh @@ -0,0 +1,161 @@ +#!/usr/bin/env bash +# check-release-note.sh — Validate the `release-note` block in a PR body. +# +# Release notes are gathered from fenced ```release-note blocks in PR +# bodies (see COMMITS.md, "Release notes"). This script enforces the +# contract on every PR, whether a human or an agent wrote it: +# +# 1. The body must contain a fenced ```release-note block. +# 2. The block must not be empty. +# 3. If the PR title or any commit subject carries the Conventional +# Commits `!` breaking-change marker, the block must start with +# "action required". A NONE block (or any of the variants the +# release-notes gatherer treats as "no note") is rejected instead. +# +# On success the script prints "release-note block OK" and, when the +# accepted note starts with "action required", appends +# action-required=1 to $GITHUB_OUTPUT (when set). The release-note-check +# workflow uses that to label the PR +# `release-note-action-required`, which is what makes the gatherer list +# the note under "Urgent Upgrade Notes". +# +# Exits 0 if the block is valid, 1 otherwise. +# +# Inputs (env vars): +# PR_BODY — full PR body text +# PR_TITLE — PR title (optional; skips the title check if unset) +# COMMIT_SUBJECTS — newline-separated commit subjects (optional; skips +# the commit check if unset) +# +# Requires: bash, awk, grep. No network access. + +set -euo pipefail + +PR_BODY="${PR_BODY:-}" +PR_TITLE="${PR_TITLE:-}" +COMMIT_SUBJECTS="${COMMIT_SUBJECTS:-}" + +# Strip carriage returns so CRLF bodies (common after web-UI edits) +# normalize the same way as LF bodies. +PR_BODY="${PR_BODY//$'\r'/}" + +# Extract the first fenced ```release-note block: lines between the +# opening ```release-note fence and the next closing fence. Both fences +# must be exactly as the release-notes gatherer recognizes them: the +# opener exactly ```release-note (or ```release-notes) at column 0, and +# the closer exactly ``` at column 0 directly after a newline. Variants +# the gatherer would skip or mis-parse (trailing spaces, an indented +# closer, a missing closer) are rejected below instead of passing CI and +# then being silently dropped at release time. +NOTE=$(awk ' + /^```release-notes?$/ { inblock = 1; next } + inblock && /^```$/ { closed = 1; exit } + inblock { print } + END { if (inblock && !closed) exit 3 } +' <<<"${PR_BODY}") || { + echo "::error::PR body has a release-note block that is never closed by an unindented fence line. The gatherer would skip or mis-extract it; close the block with a fence line (three backticks) at column 0." >&2 + exit 1 +} + +# Trim each line and drop leading/trailing blank lines, so indented or +# padded blocks still validate. +NOTE_TRIMMED=$( + awk ' + { sub(/^[ \t]+/, ""); sub(/[ \t]+$/, ""); print } + ' <<<"${NOTE}" | + awk 'NF { started = 1 } started { print }' | + awk '{ lines[NR] = $0; last = NR } END { for (i = 1; i <= last; i++) print lines[i] }' +) + +# A fence line that starts like a release-note fence but is not exactly +# ```release-note (or ```release-notes) is accepted by no tool: the +# gatherer skips it, so the note would never be published. Reject it +# with a clear error instead of passing silently. +if grep -Eq '^```release-note' <<<"${PR_BODY}" \ + && ! grep -Eq '^```release-notes?$' <<<"${PR_BODY}"; then + echo "::error::PR body has a malformed release-note fence (e.g. trailing spaces or \`\`\`release-note-foo). The fence line must be exactly \`\`\`release-note." >&2 + exit 1 +fi + +if [[ -z "${NOTE_TRIMMED}" ]]; then + echo "::error::PR body has no release-note block, or the block is empty. Add a fenced \`\`\`release-note block; write NONE if users see no change." >&2 + exit 1 +fi + +# A Conventional Commits breaking-change marker: type, optional scope, +# then `!` before the colon, e.g. "feat(harness)!:" or "fix!:". +BREAKING_RE='^[[:alpha:]]+(\([^)]*\))?!:' + +# The "no note" sentinels the gatherer excludes, mirroring its regex. +SENTINEL_PAT='none|n/a|na' + +has_breaking_marker() { + local text="$1" + [[ -z "${text}" ]] && return 1 + grep -Eq "${BREAKING_RE}" <<<"${text}" +} + +# The whole trimmed block must be the unquoted sentinel (case-insensitive) +# for the gatherer to treat it as "no note". This mirrors the gatherer's +# exclusion regex for `none`, `n/a` and `na`. Quoted sentinels ("NONE") +# are NOT excluded by the gatherer — it would publish the literal text — +# so they are rejected below instead. +is_none_block() { + [[ "${NOTE_TRIMMED,,}" =~ ^(${SENTINEL_PAT})$ ]] +} + +# A quoted sentinel would be published literally by the gatherer. +is_quoted_none_block() { + local re="^['\"](${SENTINEL_PAT})['\"]$" + [[ "${NOTE_TRIMMED,,}" =~ ${re} ]] +} + +# The gatherer drops a PR entirely when its body matches either exclusion +# filter, regardless of which block comes first. Mirror both so a breaking +# PR cannot hide its warning behind a second NONE block or the +# /release-note-none tag. Newlines are folded to spaces first because the +# fenced-block regex spans lines and grep is line-based. +matches_exclusion_filter() { + local oneline + oneline=$(tr '\n' ' ' <<<"${PR_BODY}") + local fenced_re + fenced_re='```release-notes?[[:space:]]*('"${SENTINEL_PAT}"')[[:space:]]*```' + grep -Eiq "${fenced_re}" <<<"${oneline}" || + grep -q '/release-note-none' <<<"${PR_BODY}" +} + +FIRST_LINE=$(head -n1 <<<"${NOTE_TRIMMED}") + +if is_quoted_none_block; then + echo "::error::release-note block is a quoted sentinel (\"NONE\", 'n/a', ...). The release-notes gatherer publishes quoted text literally; write NONE without quotes." >&2 + exit 1 +fi + +if has_breaking_marker "${PR_TITLE}" || has_breaking_marker "${COMMIT_SUBJECTS}"; then + if is_none_block || matches_exclusion_filter; then + echo "::error::release-note block says NONE (or the body carries a release-note-none marker), but the PR title or a commit subject carries the '!' breaking-change marker. Start the block with 'action required' and describe what breaks." >&2 + exit 1 + fi + if ! grep -Eiq '^action required' <<<"${FIRST_LINE}"; then + echo "::error::PR title or a commit subject carries the '!' breaking-change marker, but the release-note block does not start with 'action required'. Start the block with 'action required' and describe what breaks." >&2 + exit 1 + fi +else + # The gatherer drops a PR entirely when its body matches an exclusion + # filter, regardless of which block comes first. A real note plus a + # leftover NONE block would pass here but never be published, so fail + # instead. + if ! is_none_block && matches_exclusion_filter; then + echo "::error::PR body contains both a release note and a NONE/release-note-none marker; keep exactly one block." >&2 + exit 1 + fi +fi + +echo "release-note block OK" +# Label the PR whenever the accepted note starts with "action required", +# matching COMMITS.md: the block content drives the Urgent label. +if grep -Eiq '^action required' <<<"${FIRST_LINE}"; then + if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + echo "action-required=1" >> "${GITHUB_OUTPUT}" + fi +fi diff --git a/scripts/gather-release-notes-test.sh b/scripts/gather-release-notes-test.sh new file mode 100644 index 0000000000..676bf026c9 --- /dev/null +++ b/scripts/gather-release-notes-test.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# gather-release-notes-test.sh — Tests for the pure functions of +# gather-release-notes.sh (merged-PR extraction). +# +# The full script needs the release-notes binary and an authenticated +# gh, so only the offline parts are exercised here: extract_merged_prs +# (merge commits and squash subjects). The START_SHA selection is a +# plain `git rev-parse PREV` (v0.23.0 stops its first-parent walk at the +# merge base of START_SHA and END_SHA, exclusive), so it needs no test. +# +# Run from the repo root: +# bash scripts/gather-release-notes-test.sh + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=scripts/gather-release-notes.sh +source "${SCRIPT_DIR}/gather-release-notes.sh" + +TMP=$(mktemp -d) +trap 'rm -rf "${TMP}"' EXIT + +FAILURES=0 + +ok() { + echo "ok — $1" +} + +fail() { + echo "FAIL — $1" + echo "--- expected ---" + printf '%s\n' "$2" + echo "--- actual ---" + printf '%s\n' "$3" + FAILURES=$((FAILURES + 1)) +} + +assert_equals() { + local desc=$1 expected=$2 actual=$3 + if [[ "${actual}" == "${expected}" ]]; then + ok "${desc}" + else + fail "${desc}" "${expected}" "${actual}" + fi +} + +# Build a repo shaped like a real release range: +# +# A --- B(merge #1) --- C(squash #2) --- D(merge #3) <- TAG +# \ +# E (old-dated PR-branch commit for #1) +build_repo() { + git -C "${TMP}" init -q -b main + git -C "${TMP}" -c user.email=t@t -c user.name=t commit -q --allow-empty -m "A" + # PREV points at A. + git -C "${TMP}" tag v0.1.0 + + # PR #1: a branch with an old-dated commit, merged with a merge commit. + git -C "${TMP}" checkout -q -b pr1 + git -C "${TMP}" -c user.email=t@t -c user.name=t commit -q --allow-empty -m "E" + git -C "${TMP}" checkout -q main + git -C "${TMP}" -c user.email=t@t -c user.name=t merge -q --no-ff -m "Merge pull request #1 from x/pr1" pr1 + + # PR #2: squash merge (subject ends with "(#2)"). + git -C "${TMP}" -c user.email=t@t -c user.name=t commit -q --allow-empty -m "feat: thing (#2)" + + # PR #3: another merge commit. + git -C "${TMP}" checkout -q -b pr3 + git -C "${TMP}" -c user.email=t@t -c user.name=t commit -q --allow-empty -m "F" + git -C "${TMP}" checkout -q main + git -C "${TMP}" -c user.email=t@t -c user.name=t merge -q --no-ff -m "Merge pull request #3 from x/pr3" pr3 + + git -C "${TMP}" tag v0.2.0 +} + +build_repo + +# The functions run git in the current directory; run them inside the +# temp repo. +cd "${TMP}" + +# --- extract_merged_prs --------------------------------------------------- + +assert_equals "extract_merged_prs finds merge commits and squash subjects" \ + "1 +2 +3" "$(extract_merged_prs v0.1.0 v0.2.0)" + +# A range with no merges yields nothing. +git -C "${TMP}" -c user.email=t@t -c user.name=t commit -q --allow-empty -m "chore: no PR" +git -C "${TMP}" tag v0.3.0 +assert_equals "extract_merged_prs returns nothing for a PR-less range" \ + "" "$(extract_merged_prs v0.2.0 v0.3.0)" + +if [[ "${FAILURES}" -gt 0 ]]; then + echo "${FAILURES} failure(s)" >&2 + exit 1 +fi +echo "all tests passed" diff --git a/scripts/gather-release-notes.sh b/scripts/gather-release-notes.sh new file mode 100644 index 0000000000..be8cdc6d37 --- /dev/null +++ b/scripts/gather-release-notes.sh @@ -0,0 +1,157 @@ +#!/usr/bin/env bash +# gather-release-notes.sh — Gather release notes from release-note blocks +# in PR bodies for a tag range. +# +# Shared by the release workflow (.github/workflows/release.yml) and its +# workflow_dispatch dry-run job, which measures the GITHUB_TOKEN +# rate-limit cost and runtime before a final release relies on it. +# +# Usage: gather-release-notes.sh PREV_TAG TAG OUTDIR +# +# Writes OUTDIR/release-notes.md (with the "## Changelog" header the +# release-highlights step expects) and OUTDIR/release-notes-body.md. +# Requires gh (authenticated) for PR title, label and edit-timestamp +# lookups. +# +# The merged-PR extraction lives in a function below so +# gather-release-notes-test.sh can exercise it offline (the full run +# needs the release-notes binary and an authenticated gh). + +set -euo pipefail + +# Install the pinned Kubernetes release-notes tool if absent (in main, +# after the args are parsed). Update the URL and digest together: Renovate +# bumps the version (custom manager in renovate.json) and +# scripts/renovate/update-release-notes-checksum.sh refreshes the digest in +# the same PR. v0.17.1 was replaced by v0.23.0 (current at the time) +# because the old pin was ~2.4 years stale and nothing could bump it. +install_release_notes() { + local outdir=$1 + local RELEASE_NOTES_SHA256=086ef82292e97a1dcc3b4e096ea40627a78b0ef3a2564f2faf324acc11f75724 + curl -fsSLo "${outdir}/release-notes" \ + https://github.com/kubernetes/release/releases/download/v0.23.0/release-notes-amd64-linux + echo "${RELEASE_NOTES_SHA256} ${outdir}/release-notes" | sha256sum -c - + chmod +x "${outdir}/release-notes" + sudo mv "${outdir}/release-notes" /usr/local/bin/release-notes +} + +# extract_merged_prs PREV TAG — print the PR numbers merged in the range, +# one per line, sorted and unique. Merge commits say "Merge pull request +# #N"; squash-merge subjects end with "(#N)". +extract_merged_prs() { + local prev=$1 tag=$2 + git log --first-parent --format='%s' "${prev}..${tag}" \ + | sed -nE 's/^Merge pull request #([0-9]+).*/\1/p; s/.*\(#([0-9]+)\)$/\1/p' \ + | sort -u +} + +# fetch_pr_meta PR — print a JSON object with the PR's title, +# lastEditedAt, mergedAt and label names (one GraphQL call). +# lastEditedAt is null when the body was never edited. +fetch_pr_meta() { + local pr=$1 + gh api graphql \ + -f query='query($number: Int!) { + repository(owner: "fullsend-ai", name: "fullsend") { + pullRequest(number: $number) { + title + lastEditedAt + mergedAt + labels(first: 100) { + nodes { name } + } + } + } + }' \ + -F number="${pr}" \ + --jq '.data.repository.pullRequest' +} + +main() { + if [[ $# -ne 3 ]]; then + echo "usage: $0 PREV_TAG TAG OUTDIR" >&2 + exit 2 + fi + + local PREV=$1 TAG=$2 OUTDIR=$3 + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + + if ! command -v release-notes >/dev/null 2>&1; then + install_release_notes "${OUTDIR}" + fi + + echo "Gathering notes from ${PREV} to ${TAG}" + # v0.23.0 walks first parents from END_SHA and stops at the merge base + # of END_SHA and START_SHA (exclusive), so START_SHA must be PREV + # itself: every commit after PREV up to TAG is then included, and the + # first PR merged after the previous tag keeps its note. + local START_SHA END_SHA + # ^{commit} peels annotated tags to their commit SHA; the tool's + # CommitObject call fails on a tag object. + START_SHA=$(git rev-parse "${PREV}^{commit}") + END_SHA=$(git rev-list -n1 "${TAG}") + # The tool reads its range from these env vars and walks a local clone + # (v0.23.0 has no --required-author flag and no date window; it opens + # the repo at --repo-path, which defaults to a tempdir clone that does + # not exist here). + export START_SHA END_SHA + # Gather as JSON, then render with our own script. The tool credits a + # commit to any PR cited as "(#N)" in its message, so PRs from earlier + # releases can appear; the renderer keeps only PRs actually merged in + # the range (first-parent commits between PREV and TAG) and groups notes + # by PR title type, mirroring the old GoReleaser changelog layout. + release-notes generate \ + --repo-path "$(git rev-parse --show-toplevel)" \ + --dependencies=false \ + --format json \ + --output "${OUTDIR}/release-notes.json" \ + --org fullsend-ai --repo fullsend + # PRs merged in this release. + extract_merged_prs "${PREV}" "${TAG}" > "${OUTDIR}/merged-prs.txt" + # Titles and edit timestamps for every merged PR (one GraphQL call + # each). Titles feed the renderer's section grouping and its + # missing-note fallback; the timestamps feed the post-merge edit check + # below. + : > "${OUTDIR}/pr-titles.tsv" + local -a edited_after_merge=() + local pr meta title + while read -r pr; do + meta=$(fetch_pr_meta "${pr}") + title=$(jq -r '.title // ""' <<<"${meta}") + printf '%s\t%s\n' "${pr}" "${title}" >> "${OUTDIR}/pr-titles.tsv" + # The release-note check validates the body only before merge. After + # merge the author (including a fork contributor) can still edit the + # body, replacing a reviewed note with arbitrary markdown. Refuse to + # publish a note whose body was edited after the merge. Reverting the + # edit does not clear lastEditedAt, so the recovery path is explicit: + # a maintainer reviews the edited body and adds the + # release-note-edit-approved label to the PR. + if jq -e ' + .lastEditedAt != null and .mergedAt != null + and .lastEditedAt > .mergedAt + ' >/dev/null <<<"${meta}" \ + && ! jq -e '[.labels.nodes[].name] + | index("release-note-edit-approved")' >/dev/null <<<"${meta}"; then + edited_after_merge+=("${pr}") + fi + done < "${OUTDIR}/merged-prs.txt" + if [[ ${#edited_after_merge[@]} -gt 0 ]]; then + # PR numbers are numeric, so interpolating them needs no + # workflow-command escaping. + echo "::error::PRs whose body was edited after merge (the published note would differ from the reviewed one): ${edited_after_merge[*]}. A maintainer must review each edit and add the release-note-edit-approved label to the PR before releasing." + exit 1 + fi + bash "${SCRIPT_DIR}/render-release-notes.sh" \ + "${OUTDIR}/release-notes.json" \ + "${OUTDIR}/merged-prs.txt" \ + "${OUTDIR}/pr-titles.tsv" \ + > "${OUTDIR}/release-notes-body.md" + # Prepend the header prepend-release-highlights.sh expects, so the + # release-highlights step keeps working with the gathered-notes body. + printf '## Changelog\n\n' | cat - "${OUTDIR}/release-notes-body.md" \ + > "${OUTDIR}/release-notes.md" +} + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + main "$@" +fi diff --git a/scripts/render-release-notes-test.sh b/scripts/render-release-notes-test.sh new file mode 100755 index 0000000000..04369c92cc --- /dev/null +++ b/scripts/render-release-notes-test.sh @@ -0,0 +1,265 @@ +#!/usr/bin/env bash +# render-release-notes-test.sh — Tests for render-release-notes.sh +# +# Run from the repo root: +# bash scripts/render-release-notes-test.sh + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SCRIPT="${SCRIPT_DIR}/render-release-notes.sh" +TMP=$(mktemp -d) +trap 'rm -rf "${TMP}"' EXIT + +FAILURES=0 + +fail() { + echo "FAIL — $1" + echo "--- expected ---" + printf '%s\n' "$2" + echo "--- actual ---" + printf '%s\n' "$3" + FAILURES=$((FAILURES + 1)) +} + +check() { + local desc=$1 expected=$2 actual + actual=$("${SCRIPT}" "${TMP}/notes.json" "${TMP}/merged.txt" "${TMP}/titles.tsv") + if [[ "${actual}" == "${expected}" ]]; then + echo "ok — ${desc}" + else + echo "FAIL — ${desc}" + echo "--- expected ---" + printf '%s\n' "${expected}" + echo "--- actual ---" + printf '%s\n' "${actual}" + FAILURES=$((FAILURES + 1)) + fi +} + +write_fixtures() { + # $1: titles TSV content; stdin: notes JSON. The merged-PR list is + # written separately after each call. + cat >"${TMP}/notes.json" + printf '%b' "$1" >"${TMP}/titles.tsv" +} + +# --- Grouping by PR title type ------------------------------------------- + +write_fixtures '101\tfeat(cli): new thing +102\tfix: a bug +103\trefactor: internals +104\tdocs: some docs +105\tfeat(api)!: breaking change +' <<'EOF' +{ + "101": {"pr_number": 101, "text": "Adds a new CLI flag.", + "markdown": "Adds a new CLI flag. ([#101](https://example.com/pull/101), [@alice](https://example.com/alice))", + "pr_url": "https://example.com/pull/101", "author": "alice", + "author_url": "https://example.com/alice"}, + "102": {"pr_number": 102, "text": "Fixes a crash.", + "markdown": "Fixes a crash. ([#102](https://example.com/pull/102), [@bob](https://example.com/bob))", + "pr_url": "https://example.com/pull/102", "author": "bob", + "author_url": "https://example.com/bob"}, + "103": {"pr_number": 103, "text": "Renames a package.", + "markdown": "Renames a package. ([#103](https://example.com/pull/103), [@carol](https://example.com/carol))", + "pr_url": "https://example.com/pull/103", "author": "carol", + "author_url": "https://example.com/carol"}, + "104": {"pr_number": 104, "text": "Documents a flag.", + "markdown": "Documents a flag. ([#104](https://example.com/pull/104), [@dave](https://example.com/dave))", + "pr_url": "https://example.com/pull/104", "author": "dave", + "author_url": "https://example.com/dave"}, + "105": {"pr_number": 105, "text": "Removes a flag.", + "markdown": "Removes a flag. ([#105](https://example.com/pull/105), [@erin](https://example.com/erin))", + "pr_url": "https://example.com/pull/105", "author": "erin", + "author_url": "https://example.com/erin"} +} +EOF +cat >"${TMP}/merged.txt" <<'EOF' +101 +102 +103 +104 +105 +EOF + +check "notes grouped by title type" '### Breaking Changes + +- Removes a flag. ([#105](https://example.com/pull/105), [@erin](https://example.com/erin)) + +### Features + +- Adds a new CLI flag. ([#101](https://example.com/pull/101), [@alice](https://example.com/alice)) + +### Bug Fixes + +- Fixes a crash. ([#102](https://example.com/pull/102), [@bob](https://example.com/bob)) + +### Refactoring + +- Renames a package. ([#103](https://example.com/pull/103), [@carol](https://example.com/carol)) + +### Other Changes + +- Documents a flag. ([#104](https://example.com/pull/104), [@dave](https://example.com/dave))' + +# --- PRs outside the merged set are dropped ------------------------------ + +write_fixtures '101\tfeat(cli): new thing +' <<'EOF' +{ + "101": {"pr_number": 101, "text": "Adds a new CLI flag.", + "pr_url": "https://example.com/pull/101", "author": "alice", + "author_url": "https://example.com/alice"}, + "999": {"pr_number": 999, "text": "Old release note.", + "pr_url": "https://example.com/pull/999", "author": "mallory", + "author_url": "https://example.com/mallory"} +} +EOF +cat >"${TMP}/merged.txt" <<'EOF' +101 +EOF + +check "PR cited in a commit body but not merged in range is dropped" '### Features + +- Adds a new CLI flag. ([#101](https://example.com/pull/101), [@alice](https://example.com/alice))' + +# --- Action-required notes and do-not-publish ---------------------------- + +write_fixtures '201\tfix: urgent thing +202\tfeat: quiet thing +' <<'EOF' +{ + "201": {"pr_number": 201, "text": "The role field is now required.", + "pr_url": "https://example.com/pull/201", "author": "alice", + "author_url": "https://example.com/alice", "action_required": true}, + "202": {"pr_number": 202, "text": "Should not appear.", + "pr_url": "https://example.com/pull/202", "author": "bob", + "author_url": "https://example.com/bob", "do_not_publish": true} +} +EOF +cat >"${TMP}/merged.txt" <<'EOF' +201 +202 +EOF + +check "action-required note lands under Urgent Upgrade Notes; do-not-publish dropped" '## Urgent Upgrade Notes + +- The role field is now required. ([#201](https://example.com/pull/201), [@alice](https://example.com/alice))' + +# --- Multi-line notes stay inside the bullet ----------------------------- + +write_fixtures '301\tfeat: multi-line +' <<'EOF' +{ + "301": {"pr_number": 301, "text": "First line.\nSecond line.", + "markdown": "First line.\n Second line. ([#301](https://example.com/pull/301), [@alice](https://example.com/alice))", + "pr_url": "https://example.com/pull/301", "author": "alice", + "author_url": "https://example.com/alice"} +} +EOF +cat >"${TMP}/merged.txt" <<'EOF' +301 +EOF + +check "multi-line note continuation lines are indented" '### Features + +- First line. + Second line. ([#301](https://example.com/pull/301), [@alice](https://example.com/alice))' + +# --- Titles TSV produced the way release.yml produces it --------------- + +# release.yml builds the TSV with `gh pr view --json number,title +# --jq '"\(.number)\t\(.title)"'`. gh's --jq is jq, so simulate it with +# jq on the same JSON shape and feed the result to the renderer, so the +# producer and consumer cannot drift apart again. +printf '{"number": 501, "title": "feat: tsv producer"}\n' \ + | jq -r '"\(.number)\t\(.title)"' > "${TMP}/titles.tsv" +cat >"${TMP}/notes.json" <<'EOF' +{ + "501": {"pr_number": 501, "text": "Note from the TSV producer test.", + "pr_url": "https://example.com/pull/501", "author": "alice", + "author_url": "https://example.com/alice"} +} +EOF +printf '501\n' >"${TMP}/merged.txt" + +check "titles TSV built with the workflow's jq expression drives section choice" '### Features + +- Note from the TSV producer test. ([#501](https://example.com/pull/501), [@alice](https://example.com/alice))' + +# --- Empty input ---------------------------------------------------------- + +write_fixtures '401\tfeat: nothing +' <<'EOF' +{} +EOF +: >"${TMP}/merged.txt" + +check "empty notes render an empty body" '' + +# --- PRs without a release note ------------------------------------------- + +# A merged PR absent from the notes JSON (no release-note block) must be +# listed under "PRs Without Release Notes" instead of vanishing, and a +# warning must go to stderr. +printf '601\tfix: has note\n602\tchore: no block\n' > "${TMP}/titles.tsv" +cat >"${TMP}/notes.json" <<'EOF' +{ + "601": {"pr_number": 601, "text": "Has a note.", + "pr_url": "https://example.com/pull/601", "author": "alice", + "author_url": "https://example.com/alice"} +} +EOF +printf '601\n602\n' > "${TMP}/merged.txt" + +actual=$("${SCRIPT}" "${TMP}/notes.json" "${TMP}/merged.txt" "${TMP}/titles.tsv" 2>"${TMP}/stderr") +expected='### Bug Fixes + +- Has a note. ([#601](https://example.com/pull/601), [@alice](https://example.com/alice)) + +### PRs Without Release Notes + +- #602 chore: no block' +if [[ "${actual}" == "${expected}" ]]; then + echo "ok — merged PR without a note is listed, not dropped" +else + fail "merged PR without a note is listed, not dropped" "${expected}" "${actual}" +fi +if grep -q "PRs merged in the range have no release note" "${TMP}/stderr"; then + echo "ok — missing-note warning goes to stderr" +else + echo "FAIL — missing-note warning goes to stderr" + cat "${TMP}/stderr" + FAILURES=$((FAILURES + 1)) +fi + +# A non-empty range that gathered zero notes must warn. +printf '701\tfeat: nothing\n' > "${TMP}/titles.tsv" +printf '{}' > "${TMP}/notes.json" +printf '701\n' > "${TMP}/merged.txt" + +"${SCRIPT}" "${TMP}/notes.json" "${TMP}/merged.txt" "${TMP}/titles.tsv" \ + >"${TMP}/stdout" 2>"${TMP}/stderr" +if grep -q "Zero release notes gathered" "${TMP}/stderr"; then + echo "ok — zero notes from a non-empty range warns" +else + echo "FAIL — zero notes from a non-empty range warns" + cat "${TMP}/stderr" + FAILURES=$((FAILURES + 1)) +fi + +# --- Missing files -------------------------------------------------------- + +if "${SCRIPT}" "${TMP}/missing.json" "${TMP}/merged.txt" "${TMP}/titles.tsv" 2>/dev/null; then + echo "FAIL — missing notes file should be an error" + FAILURES=$((FAILURES + 1)) +else + echo "ok — missing notes file is an error" +fi + +if [[ ${FAILURES} -gt 0 ]]; then + echo "${FAILURES} test(s) failed" + exit 1 +fi +echo "all tests passed" diff --git a/scripts/render-release-notes.sh b/scripts/render-release-notes.sh new file mode 100755 index 0000000000..ca085b0ddd --- /dev/null +++ b/scripts/render-release-notes.sh @@ -0,0 +1,159 @@ +#!/usr/bin/env bash +# render-release-notes.sh — Render release notes from the Kubernetes +# release-notes tool's JSON output. +# +# The gatherer can credit a commit to any PR cited as "(#N)" in its +# message, so its JSON may contain PRs from earlier releases. This script +# keeps only PRs that were actually merged in the tag range (the caller +# passes their numbers) and groups the notes by PR title type, mirroring +# the layout the old GoReleaser changelog used. +# +# Usage: +# render-release-notes.sh NOTES_JSON MERGED_PRS TITLES_TSV +# +# NOTES_JSON --output file of `release-notes generate --format json` +# (an object keyed by PR number). +# MERGED_PRS file with one PR number per line: the PRs merged in the +# tag range (first-parent commits between the tags). +# TITLES_TSV file with `NUMBERTITLE` lines (PR titles; used to +# pick the section for each note). +# +# Prints the markdown body (without the `## Changelog` header, which the +# release workflow prepends) to stdout. + +set -euo pipefail + +if [[ $# -ne 3 ]]; then + echo "usage: $0 NOTES_JSON MERGED_PRS TITLES_TSV" >&2 + exit 2 +fi + +NOTES_JSON=$1 +MERGED_PRS=$2 +TITLES_TSV=$3 + +for f in "${NOTES_JSON}" "${MERGED_PRS}" "${TITLES_TSV}"; do + if [[ ! -f "${f}" ]]; then + echo "error: file not found: ${f}" >&2 + exit 2 + fi +done + +# jq arguments: the allowed PR numbers and the PR titles. +ALLOWED=$(jq -Rn '[inputs | tonumber]' "${MERGED_PRS}") +TITLES=$(jq -Rn ' + reduce inputs as $line ({}; + ($line | split("\t")) as $parts + | .[$parts[0]] = ($parts[1] // "") + )' "${TITLES_TSV}") + +# Merged PRs that the tool returned no note for (no release-note block +# in the body). They are listed in the output under "PRs Without Release +# Notes" so they do not vanish from the release silently. +MISSING=$(jq -Rn --argjson allowed "${ALLOWED}" --slurpfile notes "${NOTES_JSON}" ' + $allowed - ($notes[0] | keys | map(tonumber))') + +# One JSON object per line for each published note: number, title, +# text, PR URL, author, author URL, action-required flag. Notes for PRs +# outside the merged set, notes marked do-not-publish, and empty notes +# are dropped here. +ROWS=$(jq -c --argjson allowed "${ALLOWED}" --argjson titles "${TITLES}" ' + [ to_entries[] + | select(.value.pr_number as $n | $allowed | index($n)) + | select(.value.do_not_publish != true) + | .value + | select((.text | length) > 0) + | {number: .pr_number, title: ($titles[.pr_number | tostring] // ""), + text: .text, url: .pr_url, + author: .author, author_url: .author_url, + action_required: (.action_required == true)} + ] | sort_by(.number) | .[]' "${NOTES_JSON}") + +# Warn (to stderr, so it lands in the log, not the notes) when PRs +# merged in the range produced no note, or when a non-empty range +# gathered zero notes at all. Release Note Check is not a required +# status check, so this is the only signal that a change is about to +# drop out of the release. +if [[ -n "${MISSING}" ]] && [[ "${MISSING}" != "[]" ]]; then + echo "::warning::$(jq length <<<"${MISSING}") PRs merged in the range have no release note and will only be listed under 'PRs Without Release Notes'." >&2 +fi +if [[ -z "${ROWS}" ]] && [[ -n "${ALLOWED}" ]] && [[ "${ALLOWED}" != "[]" ]]; then + echo "::warning::Zero release notes gathered from a range containing $(jq length <<<"${ALLOWED}") merged PRs." >&2 +fi + +# Section for a note, in priority order. Action-required notes always go +# under Urgent Upgrade Notes; otherwise the PR title type decides, with +# `!` (breaking) pulled out of the type groups first — same order the old +# GoReleaser changelog used. +# Regexes in variables: bash cannot parse nested parentheses in an +# inline `[[ =~ ]]` pattern. +RE_BREAKING='^[a-z]+(\([^)]*\))?!:' +RE_FEAT='^feat(\([^)]*\))?!?:' +RE_FIX='^fix(\([^)]*\))?!?:' +RE_REFACTOR='^refactor(\([^)]*\))?!?:' + +section_for() { + local action_required=$1 title=$2 + if [[ "${action_required}" == "true" ]]; then + echo "urgent" + elif [[ "${title}" =~ ${RE_BREAKING} ]]; then + echo "breaking" + elif [[ "${title}" =~ ${RE_FEAT} ]]; then + echo "features" + elif [[ "${title}" =~ ${RE_FIX} ]]; then + echo "fixes" + elif [[ "${title}" =~ ${RE_REFACTOR} ]]; then + echo "refactoring" + else + echo "other" + fi +} + +declare -a SECTIONS=(urgent breaking features fixes refactoring other) +declare -A HEADINGS=( + [urgent]="## Urgent Upgrade Notes" + [breaking]="### Breaking Changes" + [features]="### Features" + [fixes]="### Bug Fixes" + [refactoring]="### Refactoring" + [other]="### Other Changes" +) +declare -A BULLETS + +while IFS= read -r line; do + [[ -z "${line}" ]] && continue + number=$(jq -r .number <<<"${line}") + title=$(jq -r .title <<<"${line}") + text=$(jq -r .text <<<"${line}") + url=$(jq -r .url <<<"${line}") + author=$(jq -r .author <<<"${line}") + author_url=$(jq -r .author_url <<<"${line}") + action_required=$(jq -r '.action_required' <<<"${line}") + section=$(section_for "${action_required}" "${title}") + # Indent continuation lines of multi-line notes so they stay inside the + # bullet. + formatted=$(printf '%s\n' "${text}" | sed '2,$s/^/ /') + BULLETS[${section}]+="- ${formatted} ([#${number}](${url}), [@${author}](${author_url}))"$'\n' +done <<<"${ROWS}" + +for section in "${SECTIONS[@]}"; do + if [[ -n "${BULLETS[${section}]:-}" ]]; then + echo "${HEADINGS[${section}]}" + echo + printf '%s' "${BULLETS[${section}]}" + echo + fi +done + +# Merged PRs the tool returned no note for (no release-note block in the +# body — e.g. everything merged before the block became mandatory). +# Listing them keeps the PR visible in the release instead of dropping +# it silently; the warning above tells the releaser to look. +if [[ -n "${MISSING}" ]] && [[ "${MISSING}" != "[]" ]]; then + echo "### PRs Without Release Notes" + echo + jq -r --argjson titles "${TITLES}" ' + .[] + | "- #\(.) \($titles[tostring] // "")"' <<<"${MISSING}" + echo +fi diff --git a/scripts/renovate/update-release-notes-checksum.sh b/scripts/renovate/update-release-notes-checksum.sh new file mode 100644 index 0000000000..1abfdb2e20 --- /dev/null +++ b/scripts/renovate/update-release-notes-checksum.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# Called by Renovate postUpgradeTasks after a kubernetes/release bump in +# scripts/gather-release-notes.sh. Downloads the linux release-notes +# asset for the bumped version, checks it against the sha256 digest +# GitHub recorded for the asset, and only then updates +# RELEASE_NOTES_SHA256 in the script. +set -euo pipefail +source "$(dirname "${BASH_SOURCE[0]}")/lib-checksums.sh" + +FILE="scripts/gather-release-notes.sh" +ASSET="release-notes-amd64-linux" + +url=$(grep -oE "https://github\.com/kubernetes/release/releases/download/v[0-9.]+/${ASSET}" "${FILE}") \ + || die "no ${ASSET} download URL in ${FILE}" +VERSION="${url##*/v}" +VERSION="${VERSION%%/*}" + +artifact=$(fetch_cached "${url}") || die "failed to download ${url}" +computed=$(sha256sum "${artifact}" | cut -d' ' -f1) +[[ "${computed}" =~ ${SHA_RE} ]] || die "computed checksum is not a sha256 hex digest: '${computed}'" + +published=$(github_asset_digest kubernetes/release "v${VERSION}" "${ASSET}") \ + || die "could not get the published digest for ${url}" +[[ "${published}" =~ ${SHA_RE} ]] || die "published digest for ${url} is not a sha256 hex digest: '${published}'" +[[ "${published}" == "${computed}" ]] || die "checksum mismatch for ${url}: published ${published}, downloaded ${computed}" + +count=$(grep -c '^ local RELEASE_NOTES_SHA256=' "${FILE}" || true) +if [[ "${count}" != "1" ]]; then + die "expected exactly one 'local RELEASE_NOTES_SHA256=' line in ${FILE}, found ${count}" +fi +sed -i "s/^ local RELEASE_NOTES_SHA256=.*/ local RELEASE_NOTES_SHA256=${computed}/" "${FILE}" +grep -q "local RELEASE_NOTES_SHA256=${computed}" "${FILE}" || die "failed to update RELEASE_NOTES_SHA256 in ${FILE}" + +echo "updated RELEASE_NOTES_SHA256 to ${computed} (kubernetes/release v${VERSION})" diff --git a/skills/cutting-releases/SKILL.md b/skills/cutting-releases/SKILL.md index d2906ec61b..d88e8eac60 100644 --- a/skills/cutting-releases/SKILL.md +++ b/skills/cutting-releases/SKILL.md @@ -10,8 +10,9 @@ allowed-tools: Read, Grep, Glob, AskUserQuestion, Agent, Bash(git tag:*), Bash(g # Cutting Releases Releases are driven by annotated git tags. When a tag matching `v*` is pushed, -`.github/workflows/release.yml` runs GoReleaser to build binaries, generate a -changelog, and create the GitHub release. +`.github/workflows/release.yml` gathers release notes from `release-note` +blocks in PR bodies, runs GoReleaser to build binaries, and publishes the +GitHub release with the gathered notes. ## Process @@ -80,7 +81,9 @@ git log --oneline ..HEAD ``` Summarize changes into categories (features, fixes, refactors). Exclude -`docs:`, `test:`, `chore:`, `ci:`, `build:`, `style:` commits — GoReleaser filters these anyway. +`docs:`, `test:`, `chore:`, `ci:`, `build:`, `style:` commits — their +release-note blocks typically say NONE, so they do not reach the release +notes. ### 6. Create the RC tag @@ -286,12 +289,28 @@ installs the binary as `fullsend-` so multiple versions can coexist. - **Never delete a tag that published binaries or a GitHub Release.** If a shipped release is bad, cut a new patch or RC. Only a blocked final may be deleted (see "When a release run fails"). -- **The changelog** is auto-generated from commit subjects (which must follow - conventional commit format). GoReleaser uses `changelog.use: github` in - `.goreleaser.yml`, which lists every commit in the release range, so - individual commit subjects — not PR titles — are the source of release-note - entries. PRs land as merge commits, which are excluded, so PR titles never - appear. Subjects with `!` are grouped first under **Breaking Changes**. +- **The changelog** is gathered from `release-note` blocks in merged PR + bodies (see COMMITS.md, "Release notes"). A read-only + `gather-release-notes` job runs the Kubernetes `release-notes` tool + over the tag range and passes the result to the signing job (and then + GoReleaser via `--release-notes`) as an artifact, so PR bodies — not + commit subjects — are the source of release-note entries. NONE blocks + are skipped. The gather fails if a merged PR's body was edited after + merge (the published note would differ from the reviewed one); a + maintainer must review such edits and add the + `release-note-edit-approved` label to the PR before releasing. Merged PRs with + no block are listed under **PRs Without Release Notes** instead of + vanishing. The published body starts with a `## Changelog` header + (prepended by the workflow so `prepend-release-highlights.sh` keeps + working), followed by **Urgent Upgrade Notes** (PRs labeled + `release-note-action-required`, applied automatically when a PR's + block starts with `action required`) and **Changes by Kind**. +- **Gather dry-run:** the Release workflow has a `workflow_dispatch` + trigger that runs only the release-notes gather step over a tag range + with the workflow's own `GITHUB_TOKEN`, recording the core rate limit + before and after plus the runtime. Run it over a recent final range + before relying on the gather step for a final release (its API budget + differs from a personal token's). - **The `v0` tag** is a moving tag consumed by downstream orgs for reusable workflows. It is automatically moved by the release workflow after GoReleaser completes (skipped for pre-release tags). diff --git a/skills/cutting-releases/post-flight.md b/skills/cutting-releases/post-flight.md index 110a64bd62..7c06be025c 100644 --- a/skills/cutting-releases/post-flight.md +++ b/skills/cutting-releases/post-flight.md @@ -29,8 +29,8 @@ gh release view ``` Check that the title, changelog, and binary assets look correct. Breaking -commits (`!` in the subject) should be listed first under **Breaking -Changes**. +changes (PRs whose release-note block starts with `action required`) +should be listed under **Urgent Upgrade Notes**. Verify the release is not marked as a draft. ## B2. Verify agents validation and tag