From 45f4ed26601f55b02248f9532cd3d9a66ec8c428 Mon Sep 17 00:00:00 2001 From: Matthijs Iriks Date: Fri, 4 Dec 2026 09:49:11 +0100 Subject: [PATCH] Make a patch release of a merged renovate pull request --- .gitea/scripts/check_flow.py | 4 +- .gitea/scripts/release.py | 82 ++++++++++++++++++++++++++++------ .gitea/scripts/test_scripts.py | 14 ++++++ CHANGELOG.md | 3 +- README.md | 5 ++- TOKENS.md | 1 + 6 files changed, 90 insertions(+), 19 deletions(-) diff --git a/.gitea/scripts/check_flow.py b/.gitea/scripts/check_flow.py index 2ec6ba2..1c8e760 100755 --- a/.gitea/scripts/check_flow.py +++ b/.gitea/scripts/check_flow.py @@ -10,8 +10,8 @@ Pull requests go to a release branch or to production, never to develop. and the pull request does not come from production, develop or another release branch. - to `production`: only from `release/vX.Y.Z`, with a version above the latest tag, a section for it in CHANGELOG.md, and no "version" in composer.json (Packagist reads the tag). - The one other way in is `renovate/*`: the nightly dependency update of the homelab (it makes no release; - the change reaches develop with the next sync). + The one other way in is `renovate/*`: the nightly dependency update of the homelab (release.py makes a + patch release of it, unless a release branch is open). Environment: BASE_REF, HEAD_REF. Run in a checkout with the tags (fetch-depth 0). Standard library + git only. diff --git a/.gitea/scripts/release.py b/.gitea/scripts/release.py index 3b05fcf..d4224ef 100755 --- a/.gitea/scripts/release.py +++ b/.gitea/scripts/release.py @@ -6,8 +6,14 @@ finds that version (from the pull request Gitea knows for the commit, or from th and makes the release `vX.Y.Z` on that commit, with the changelog section as its text. Gitea makes the tag; Packagist picks the tag up in the next step. +The other way into production is the nightly dependency update of the homelab, a pull request from +`renovate/*`. That makes a patch release too: the version above the latest tag with the patch raised by +one (v0.5.0 -> v0.5.1), its text the title and description of the pull request. Renovate makes one pull +request per night, so that is at most one patch release a night. When a release branch is open (a version +above the latest tag) it makes none: the update goes out with that release. + Runs again on the same commit without harm: a tag that is already there on that commit is fine. -A push that is not a release merge (a hotfix pushed by an admin, say) makes no release and says so. +A push that is neither (a hotfix pushed by an admin, say) makes no release and says so. Environment: GT_URL, GT_OWNER, GT_REPO, GT_TOKEN (may create releases), COMMIT_HASH. Standard library + git only. @@ -48,9 +54,13 @@ def api(method, path, body=None, allow=()): return json.loads(text) if text else None -def release_branch_of(commit): +def pull_of(commit): + """The pull request that made this commit, or None.""" + return api("GET", f"commits/{commit}/pull", allow=(404,)) + + +def release_branch_of(commit, pull=None): """The release branch whose pull request made this commit, or None.""" - pull = api("GET", f"commits/{commit}/pull", allow=(404,)) head = ((pull or {}).get("head") or {}).get("ref", "") if semver.release_version(head): return head @@ -61,15 +71,67 @@ def release_branch_of(commit): return found.group(1) if found else None +def next_patch(newest): + """v0.5.0 -> (0, 5, 1); None without a tag to count from.""" + return None if newest is None else (newest[0], newest[1], newest[2] + 1) + + +def release_is_open(branches, newest): + """True when one of the branches is a release/vX.Y.Z above the latest tag.""" + return any((v := semver.release_version(b)) and (newest is None or v > newest) for b in branches) + + +def dependency_release(commit, pull): + """Makes the patch release for a merged renovate/* pull request; says why when it makes none.""" + tags = subprocess.run(["git", "tag", "--list", "v*"], capture_output=True, text=True).stdout.split() + already = subprocess.run(["git", "tag", "--points-at", commit], capture_output=True, text=True).stdout.split() + if any(semver.tag_version(tag) for tag in already): + print(f"{commit[:8]} is already tagged ({' '.join(already)}): nothing to do.") + return + + newest = semver.latest(tags) + version = next_patch(newest) + if version is None: + print("No tag to count from: no release made.") + return + + branches = [b["name"] for b in api("GET", "branches?limit=100") or []] + if release_is_open(branches, newest): + print("A release branch is open: this update goes out with it, no patch release made.") + return + + tag = f"v{semver.text(version)}" + title = (pull.get("title") or "Dependency update").strip() + body = (pull.get("body") or "").strip() + notes = f"- {title}" + (f"\n\n{body}" if body else "") + publish(tag, commit, notes) + + +def publish(tag, commit, notes): + api("POST", "releases", { + "tag_name": tag, + "target_commitish": commit, + "name": tag, + "body": notes, + "draft": False, + "prerelease": False, + }) + print(f"Released {tag} on {commit[:8]}.") + + def main(): if not (URL and OWNER and REPO and TOKEN): sys.exit("GT_URL, GT_OWNER, GT_REPO and GT_TOKEN are required.") if not re.fullmatch(r"[0-9a-f]{40}", COMMIT): sys.exit("COMMIT_HASH must be the full commit hash.") - branch = release_branch_of(COMMIT) + pull = pull_of(COMMIT) + branch = release_branch_of(COMMIT, pull) if branch is None: - print(f"{COMMIT[:8]} is not the merge of a release/vX.Y.Z pull request: no release made.") + if ((pull or {}).get("head") or {}).get("ref", "").startswith("renovate/"): + dependency_release(COMMIT, pull) + else: + print(f"{COMMIT[:8]} is not the merge of a release/vX.Y.Z or renovate/* pull request: no release made.") return version = semver.release_version(branch) @@ -85,15 +147,7 @@ def main(): if notes is None: sys.exit(f"CHANGELOG.md has no section for {tag}: the release pull request should have been stopped by PR CI.") - api("POST", "releases", { - "tag_name": tag, - "target_commitish": COMMIT, - "name": tag, - "body": notes, - "draft": False, - "prerelease": False, - }) - print(f"Released {tag} on {COMMIT[:8]}.") + publish(tag, COMMIT, notes) if __name__ == "__main__": diff --git a/.gitea/scripts/test_scripts.py b/.gitea/scripts/test_scripts.py index d4ec3d7..34f6355 100644 --- a/.gitea/scripts/test_scripts.py +++ b/.gitea/scripts/test_scripts.py @@ -11,6 +11,7 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import check_flow # noqa: E402 import packagist # noqa: E402 import prune_branches # noqa: E402 +import release # noqa: E402 import semver # noqa: E402 TAGS = ["v0.1.0", "v0.2.0", "v0.10.0", "not-a-version"] @@ -139,6 +140,19 @@ class HermesTokens(unittest.TestCase): self.assertTrue(self.hermes.lines(per_model, "Work", "2026-12-04", "", None)[0].endswith("| 4.000 | |")) +class DependencyRelease(unittest.TestCase): + def test_the_next_patch(self): + self.assertEqual(release.next_patch((0, 5, 0)), (0, 5, 1)) + self.assertEqual(release.next_patch((1, 2, 9)), (1, 2, 10)) + self.assertIsNone(release.next_patch(None)) + + def test_an_open_release_takes_the_update_with_it(self): + branches = ["production", "develop", "release/v0.4.0", "release/v0.5.0", "renovate/deps-1"] + self.assertFalse(release.release_is_open(branches, (0, 5, 0))) + self.assertTrue(release.release_is_open(branches, (0, 4, 0))) + self.assertTrue(release.release_is_open(branches + ["release/v0.5.1"], (0, 5, 0))) + + class PackagistNotice(unittest.TestCase): def run_notice(self, answers): """Runs notify() with fake answers per endpoint (a status number, or an HTTP error code as a string).""" diff --git a/CHANGELOG.md b/CHANGELOG.md index 783612d..aa5dacf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,8 @@ the section is the text of the release in Gitea. with its own roles say what an account may do; groups stay the default. - CI: nothing runs weekly any more, and Trivy no longer runs in the jobs (the runner disk filled up with its database). `composer audit` stays in every pull request and every release; Trivy scans production from the homelab, every night and after every release. The nightly dependency round of the - homelab replaces the weekly *Dependency updates* workflow (and `update_dependencies.py`); its `renovate/*` pull requests may go to `production`. + homelab replaces the weekly *Dependency updates* workflow (and `update_dependencies.py`); its `renovate/*` pull requests may go to `production` and + become a patch release of their own (one a night at most, none while a release branch is open). - `manager:doctor` has a `names` check: it warns when the site uses a route name or an address of the manager and says to set `route_name` or `path`. ## v0.4.0 - 2026-12-04 diff --git a/README.md b/README.md index 048644b..2cc8c40 100644 --- a/README.md +++ b/README.md @@ -273,8 +273,9 @@ Nothing here runs on a weekly schedule; the checks hang on the moments that matt - **Every release:** `composer audit` again on the merge to `production`. - **After every release to production:** Trivy scans `production` from the homelab (LXC 120, no database to download in a job). - **Every night:** Trivy scans every repository of the organisation (03:00), and the dependency round (04:00) opens a pull request - `renovate/deps-DATE` straight to `production` for updates that have been public for 48 hours. PR CI tests it; it makes no release - and reaches `develop` with the next sync. A critical advisory on the installed version skips the 48 hours. + `renovate/deps-DATE` straight to `production` for updates that have been public for 48 hours. PR CI tests it, and when it is + merged the Release workflow makes a patch release of it (v0.5.0 → v0.5.1, text from the pull request), tells Packagist and syncs `develop`: + one a night at most. While a release branch is open there is no patch release; the update goes out with that release. A critical advisory on the installed version skips the 48 hours. Secrets of the repository for this: `DEPLOY_TOKEN` (the organisation has it), and `PACKAGIST_USERNAME` and `PACKAGIST_TOKEN` (until they are set that step only says so). When Packagist does not know the package yet, that step diff --git a/TOKENS.md b/TOKENS.md index b369250..f27c678 100644 --- a/TOKENS.md +++ b/TOKENS.md @@ -46,3 +46,4 @@ Per stuk werk een rij; zie `dev/token-usage.py`. | 2026-12-04 | Controle op namen die de site al gebruikt, en de documenten van 0.5.0 rechtgezet | - | claude-sonnet-5-5 | 9 | 7.281 | 18 | 12.115 | 2.881.457 | 0,03 | | 2026-12-04 | Trivy uit de PR-jobs (schijf van de runners vol), opruimen en wekelijkse prune | - | claude-sonnet-5-5 | 20 | 9.723 | 44 | 94.863 | 1.460.150 | 0,15 | | 2026-12-04 | Niets meer wekelijks: nachtelijke scan en updates, Trivy na een release, docs | - | claude-sonnet-5-5 | 27 | 19.377 | 58 | 41.226 | 2.879.048 | 0,63 | +| 2026-12-04 | Patch-release voor de nachtelijke renovate-update | - | claude-sonnet-5-5 | 24 | 17.609 | 54 | 35.165 | 3.038.359 | 0,16 |