From 94e52138822a77b8ec884e167558d191bb3f7895 Mon Sep 17 00:00:00 2001 From: Thomas Sprock Date: Tue, 24 Nov 2026 07:43:27 +0100 Subject: [PATCH] fix: open no release candidate for sync merge commits candidate-pr counted every commit in origin/main..origin/next, including the merge commits sync-main-to-next adds after each push to main. Every fix, Dependabot update or release on main therefore produced an empty candidate with an RC tag and a preview build. Count only non-merge commits (release_tools.py unreleased-count, the same range rc-version and candidate-body use). With nothing to release, the existing path pushes no RC tag and closes an open candidate PR. Closes #17 --- .github/workflows/candidate-pr.yml | 5 +++-- ARCHITECTURE.md | 2 +- scripts/release_tools.py | 13 +++++++++++++ tests/test_release_tools.py | 20 +++++++++++++++++++- tests/test_repo_consistency.py | 9 +++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/.github/workflows/candidate-pr.yml b/.github/workflows/candidate-pr.yml index 66bba1a..7620b0e 100644 --- a/.github/workflows/candidate-pr.yml +++ b/.github/workflows/candidate-pr.yml @@ -1,4 +1,5 @@ -# Keeps exactly one acceptance PR next -> main open while next holds unreleased commits. +# Keeps exactly one acceptance PR next -> main open while next holds unreleased commits. The merge commits +# of sync-main-to-next do not count: without other commits there is no RC tag and no candidate PR. # Per push to next: RC tag, preview (deployment / TestPyPI / build artifact), screenshots, # PR body (changes, preview link, test script from the feature PRs, screenshots), milestone. # Auto-merge (merge commit) is enabled; candidate-approval stays red until the owner approves the head. @@ -52,7 +53,7 @@ jobs: GH_TOKEN: ${{ steps.app.outputs.token }} run: | git fetch --quiet --tags origin main next - count=$(git rev-list --count origin/main..origin/next) + count=$(python3 "$GOV/scripts/release_tools.py" unreleased-count) echo "count=$count" >> "$GITHUB_OUTPUT" pr=$(gh pr list --repo "$GITHUB_REPOSITORY" --base main --head next --state open --json number,isCrossRepository --jq '[.[] | select(.isCrossRepository | not)][0].number // empty') echo "pr=$pr" >> "$GITHUB_OUTPUT" diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index bc041cd..03a07df 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -26,7 +26,7 @@ Branch and release model per project repository: `main` is released, `next` coll - Issue → triage (small model) → owner applies `po:ready` → po-ready-gate verifies the actor in the issue timeline → nightly roadmap pre-filter picks one issue → implementer PR. - Push to `main` → release-please (release PR auto-merges; minor/major only after an owner-accepted candidate) → docs to Pages, deploy, smoke test, automatic rollback to the previous tag; plus sync PR `main → next` (merge commit). -- Push to `next` → RC tag, preview (deployment, TestPyPI or build artifact), screenshots, candidate PR with changes, preview link, test script from the feature PRs → owner approves the current head → merge commit → minor release. +- Push to `next` with commits `main` lacks (sync merges do not count; without any, an open candidate PR is closed) → RC tag, preview (deployment, TestPyPI or build artifact), screenshots, candidate PR with changes, preview link, test script from the feature PRs → owner approves the current head → merge commit → minor release. - Schedule → pre-filters (`scripts/housekeeping.py`) → Claude only when a tool found something; audit, cleanup and fuzzing need no model. - Fork PR → scheduled pre-qualification (`po:review`) → owner approval (roadmap decision) → Claude ports it with co-author credit and closes the fork PR. diff --git a/scripts/release_tools.py b/scripts/release_tools.py index 742825a..b31ba78 100644 --- a/scripts/release_tools.py +++ b/scripts/release_tools.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 """Release helpers for the reusable workflows. + unreleased-count number of commits on next that main lacks, sync merges excluded rc-version next release-candidate version for the current next branch (vX.Y.Z-rc.N) version-smoke run the profile's version command and require the expected version in its output previous-tag stable tag released before the given tag (rollback target) @@ -123,11 +124,21 @@ def accepted_candidate(merged_candidates: list[dict], reviews_by_pr: dict[int, l return None +def unreleased_count(repo_dir: str = ".", base: str = "origin/main", head: str = "origin/next") -> int: + """Non-merge commits on head that base lacks. The merge commits of sync-main-to-next carry nothing to release.""" + return int(govlib.git("rev-list", "--count", "--no-merges", f"{base}..{head}", cwd=repo_dir) or 0) + + def git_tags(repo_dir: str) -> list[str]: govlib.run(["git", "fetch", "--tags", "--quiet", "origin"], cwd=repo_dir) return [t for t in govlib.git("tag", "--list", cwd=repo_dir).splitlines() if t] +def cmd_unreleased_count(args) -> int: + print(unreleased_count(args.repo_dir)) + return 0 + + def cmd_rc_version(args) -> int: subjects = govlib.git("log", "--no-merges", "--format=%s", "origin/main..origin/next", cwd=args.repo_dir).splitlines() version = next_rc(git_tags(args.repo_dir), subjects) @@ -221,6 +232,7 @@ def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("--repo-dir", default=".") sub = parser.add_subparsers(dest="cmd", required=True) + sub.add_parser("unreleased-count") sub.add_parser("rc-version") vs = sub.add_parser("version-smoke") vs.add_argument("--expected") @@ -240,6 +252,7 @@ def main(argv: list[str] | None = None) -> int: rg.add_argument("--pr", required=True, type=int) args = parser.parse_args(argv) return { + "unreleased-count": cmd_unreleased_count, "rc-version": cmd_rc_version, "version-smoke": cmd_version_smoke, "previous-tag": cmd_previous_tag, diff --git a/tests/test_release_tools.py b/tests/test_release_tools.py index f723481..7a9c430 100644 --- a/tests/test_release_tools.py +++ b/tests/test_release_tools.py @@ -1,7 +1,7 @@ import json import unittest -from helpers import ROOT +from helpers import ROOT, git, make_repo import install import release_tools as rt import set_version @@ -90,6 +90,24 @@ def test_set_version(self): self.assertIn('version = "1.1.0"', text) self.assertIn('version = "9"', text) + def test_unreleased_count_ignores_sync_merges(self): + tmp, root = make_repo({"a.txt": "a"}) + self.addCleanup(tmp.cleanup) + git(root, "branch", "next") + (root / "a.txt").write_text("fix", encoding="utf-8") + git(root, "commit", "-qam", "fix: on main") + git(root, "switch", "-q", "next") + git(root, "merge", "-q", "--no-ff", "-m", "chore: sync main into next", "main") + self.assertEqual(rt.unreleased_count(str(root), "main", "next"), 0) + (root / "b.txt").write_text("feat", encoding="utf-8") + git(root, "add", "b.txt") + git(root, "commit", "-qm", "feat: on next") + git(root, "switch", "-q", "main") + git(root, "commit", "-q", "--allow-empty", "-m", "fix: second") + git(root, "switch", "-q", "next") + git(root, "merge", "-q", "--no-ff", "-m", "chore: sync main into next", "main") + self.assertEqual(rt.unreleased_count(str(root), "main", "next"), 1) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_repo_consistency.py b/tests/test_repo_consistency.py index 6c71565..7137083 100644 --- a/tests/test_repo_consistency.py +++ b/tests/test_repo_consistency.py @@ -160,6 +160,15 @@ def test_caller_names_cover_all_templates(self): self.assertEqual(len(install.caller_names("private")), 6) self.assertEqual(len(install.caller_names("public")), 7) + def test_candidate_counts_without_sync_merges(self): + # Sync merges main -> next must not produce an RC tag or a candidate PR. + steps = load(WF / "candidate-pr.yml")["jobs"]["candidate"]["steps"] + state = next(s for s in steps if s.get("id") == "state") + self.assertIn('release_tools.py" unreleased-count', state["run"]) + self.assertIn("gh pr close", state["run"]) + tag = next(s for s in steps if s.get("name") == "Tag release candidate") + self.assertEqual(tag["if"], "steps.state.outputs.count != '0'") + def test_third_party_actions_are_sha_pinned(self): # Scorecard Pinned-Dependencies; the comment keeps the version readable and lets Dependabot update it. for path in sorted(WF.glob("*.yml")) + sorted((ROOT / "callers").glob("*.yml")):