From 306ad18162da4b91797c0eaab2591072744df697 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Wed, 11 Nov 2026 11:19:06 +0000 Subject: [PATCH 1/3] ci: assign merged pull requests to their release line's milestone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On merge, read TMVersionDefault from version/version.go at the merge commit and assign the pull request to the open vX.Y (or vX.Y.Z) milestone it maps to: dev at 2.0.0-dev.N maps to v2.0, master at 1.8.N to v1.8. Planning milestones for later lines (v2.1, v3.0) are not picked because the version, not the highest open milestone, decides. With no open match the milestone is left unchanged and the run logs a warning. The workflow uses pull_request_target without checking out code; the version file is read through the API at the merge commit. 🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent Co-Authored-By: Claude Opus 5.5 --- .github/workflows/milestone.yml | 63 +++++++++++++++++++++++++++++++++ RELEASES.md | 6 ++++ 2 files changed, 69 insertions(+) create mode 100644 .github/workflows/milestone.yml diff --git a/.github/workflows/milestone.yml b/.github/workflows/milestone.yml new file mode 100644 index 000000000..43fa064ba --- /dev/null +++ b/.github/workflows/milestone.yml @@ -0,0 +1,63 @@ +name: Milestone on merge +# Assigns a merged pull request to the milestone of the release line it was +# merged into. The line is read from version/version.go at the merge commit, +# so `dev` (e.g. 2.0.0-dev.1) maps to v2.0 while a stable branch keeps mapping +# to its own line, and no milestone list needs maintaining here. +on: + pull_request_target: + types: [closed] + +permissions: + contents: read + issues: write + pull-requests: write + +jobs: + milestone: + if: github.event.pull_request.merged == true + runs-on: ubuntu-slim + timeout-minutes: 5 + steps: + # No checkout: the version file is read through the API at the merge + # commit, which is already part of the base branch. + - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 + with: + script: | + const pr = context.payload.pull_request; + const { owner, repo } = context.repo; + const path = 'version/version.go'; + + const { data } = await github.rest.repos.getContent({ + owner, repo, path, ref: pr.merge_commit_sha, + }); + const source = Buffer.from(data.content, 'base64').toString('utf8'); + const match = source.match(/TMVersionDefault\s*=\s*"(v?(\d+)\.(\d+)\.(\d+)[^"]*)"/); + if (!match) { + core.warning(`TMVersionDefault not found in ${path} at ${pr.merge_commit_sha}; milestone of #${pr.number} left unchanged.`); + return; + } + const [, version, major, minor, patch] = match; + + // Release lines use vX.Y milestones; vX.Y.Z covers a patch-specific one. + const titles = [`v${major}.${minor}`, `v${major}.${minor}.${patch}`]; + const open = await github.paginate(github.rest.issues.listMilestones, { + owner, repo, state: 'open', per_page: 100, + }); + const milestone = titles + .map((title) => open.find((m) => m.title === title)) + .find(Boolean); + if (!milestone) { + core.warning(`No open milestone ${titles.join(' or ')} for ${version} on ${pr.base.ref}; milestone of #${pr.number} left unchanged.`); + return; + } + if (pr.milestone?.number === milestone.number) { + core.info(`#${pr.number} is already in ${milestone.title}.`); + return; + } + if (pr.milestone) { + core.notice(`#${pr.number} moves from ${pr.milestone.title} to ${milestone.title}, the line it was merged into.`); + } + await github.rest.issues.update({ + owner, repo, issue_number: pr.number, milestone: milestone.number, + }); + core.info(`#${pr.number} (${pr.base.ref}, ${version}) assigned to ${milestone.title}.`); diff --git a/RELEASES.md b/RELEASES.md index bad88e29c..c25b7a9f7 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -38,6 +38,12 @@ an explicit Platform support decision rather than automatic maintenance promises Release tags remain `vX.Y.Z`; prereleases use `vX.Y.Z-dev.N`. The skill evaluates SemVer from compatibility, not branch names or `feat`/`fix` labels. +A merged pull request is assigned to the open `vX.Y` milestone that matches +`TMVersionDefault` at its merge commit (`.github/workflows/milestone.yml`), so a +merge into `dev` at `2.0.0-dev.N` lands in `v2.0` and one into `master` at +`1.8.N` in `v1.8`. Keep a line's milestone open while it receives changes; with +no open match the pull request's milestone is left unchanged. + Full-release promotion and stable-to-dev synchronization should preserve ancestry. Master currently has protection rules that must be reconciled with that merge strategy by maintainers before a release. The skill must report any From 0687e8b9536d81a4b5b02cb0726746b9af5eb159 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Wed, 11 Nov 2026 11:21:34 +0000 Subject: [PATCH 2/3] ci: pick the next release's milestone from the latest stable release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Select the milestone from the latest stable GitHub release instead of TMVersionDefault: the open milestone with the lowest version whose major.minor is above that release (v1.8.2 released -> v2.0; v2.0.0 released -> v2.1). Patch milestones of the stable line are skipped. Run only for pull requests merged into the default branch. 🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent Co-Authored-By: Claude Opus 5.5 --- .github/workflows/milestone.yml | 58 +++++++++++++++++++-------------- RELEASES.md | 11 ++++--- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/.github/workflows/milestone.yml b/.github/workflows/milestone.yml index 43fa064ba..85179014d 100644 --- a/.github/workflows/milestone.yml +++ b/.github/workflows/milestone.yml @@ -1,8 +1,8 @@ name: Milestone on merge -# Assigns a merged pull request to the milestone of the release line it was -# merged into. The line is read from version/version.go at the merge commit, -# so `dev` (e.g. 2.0.0-dev.1) maps to v2.0 while a stable branch keeps mapping -# to its own line, and no milestone list needs maintaining here. +# Assigns a pull request merged into the default branch to the milestone of the +# next release: the open vX.Y milestone with the lowest version above the latest +# stable release. With v1.8.2 released and v1.8, v2.0, v2.1 and v3.0 open, that +# is v2.0; once v2.0.0 is released it becomes v2.1. No list is maintained here. on: pull_request_target: types: [closed] @@ -14,50 +14,58 @@ permissions: jobs: milestone: - if: github.event.pull_request.merged == true + if: >- + github.event.pull_request.merged == true && + github.event.pull_request.base.ref == github.event.repository.default_branch runs-on: ubuntu-slim timeout-minutes: 5 steps: - # No checkout: the version file is read through the API at the merge - # commit, which is already part of the base branch. + # No checkout: only the API is used. - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 with: script: | const pr = context.payload.pull_request; const { owner, repo } = context.repo; - const path = 'version/version.go'; + const parse = (text) => { + const m = /^v?(\d+)\.(\d+)(?:\.(\d+))?$/.exec(text.trim()); + return m && { major: +m[1], minor: +m[2], patch: +(m[3] ?? 0) }; + }; + const compare = (a, b) => + a.major - b.major || a.minor - b.minor || a.patch - b.patch; - const { data } = await github.rest.repos.getContent({ - owner, repo, path, ref: pr.merge_commit_sha, - }); - const source = Buffer.from(data.content, 'base64').toString('utf8'); - const match = source.match(/TMVersionDefault\s*=\s*"(v?(\d+)\.(\d+)\.(\d+)[^"]*)"/); - if (!match) { - core.warning(`TMVersionDefault not found in ${path} at ${pr.merge_commit_sha}; milestone of #${pr.number} left unchanged.`); + // Latest non-prerelease, non-draft release. + const { data: release } = await github.rest.repos.getLatestRelease({ owner, repo }); + const stable = parse(release.tag_name); + if (!stable) { + core.warning(`Latest release tag ${release.tag_name} is not vX.Y.Z; milestone of #${pr.number} left unchanged.`); return; } - const [, version, major, minor, patch] = match; - // Release lines use vX.Y milestones; vX.Y.Z covers a patch-specific one. - const titles = [`v${major}.${minor}`, `v${major}.${minor}.${patch}`]; + // Next line: lowest open milestone whose major.minor is above the stable + // release, so the stable line's own milestones (v1.8, v1.8.3) are skipped. const open = await github.paginate(github.rest.issues.listMilestones, { owner, repo, state: 'open', per_page: 100, }); - const milestone = titles - .map((title) => open.find((m) => m.title === title)) - .find(Boolean); - if (!milestone) { - core.warning(`No open milestone ${titles.join(' or ')} for ${version} on ${pr.base.ref}; milestone of #${pr.number} left unchanged.`); + const candidates = open + .map((m) => ({ milestone: m, version: parse(m.title) })) + .filter(({ version }) => version && + compare({ ...version, patch: 0 }, { ...stable, patch: 0 }) > 0) + .sort((a, b) => compare(a.version, b.version) || + a.milestone.title.length - b.milestone.title.length); + if (candidates.length === 0) { + core.warning(`No open milestone above ${release.tag_name}; milestone of #${pr.number} left unchanged.`); return; } + const { milestone } = candidates[0]; + if (pr.milestone?.number === milestone.number) { core.info(`#${pr.number} is already in ${milestone.title}.`); return; } if (pr.milestone) { - core.notice(`#${pr.number} moves from ${pr.milestone.title} to ${milestone.title}, the line it was merged into.`); + core.notice(`#${pr.number} moves from ${pr.milestone.title} to ${milestone.title}, the next release after ${release.tag_name}.`); } await github.rest.issues.update({ owner, repo, issue_number: pr.number, milestone: milestone.number, }); - core.info(`#${pr.number} (${pr.base.ref}, ${version}) assigned to ${milestone.title}.`); + core.info(`#${pr.number} assigned to ${milestone.title} (latest stable release ${release.tag_name}).`); diff --git a/RELEASES.md b/RELEASES.md index c25b7a9f7..31d75eb05 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -38,11 +38,12 @@ an explicit Platform support decision rather than automatic maintenance promises Release tags remain `vX.Y.Z`; prereleases use `vX.Y.Z-dev.N`. The skill evaluates SemVer from compatibility, not branch names or `feat`/`fix` labels. -A merged pull request is assigned to the open `vX.Y` milestone that matches -`TMVersionDefault` at its merge commit (`.github/workflows/milestone.yml`), so a -merge into `dev` at `2.0.0-dev.N` lands in `v2.0` and one into `master` at -`1.8.N` in `v1.8`. Keep a line's milestone open while it receives changes; with -no open match the pull request's milestone is left unchanged. +A pull request merged into `dev` is assigned to the next release's milestone +(`.github/workflows/milestone.yml`): the open `vX.Y` milestone with the lowest +version above the latest stable release, so with `v1.8.2` released it lands in +`v2.0`, and in `v2.1` once `v2.0.0` is released. Keep the next release's +milestone open; with none above the latest stable release the pull request's +milestone is left unchanged. Full-release promotion and stable-to-dev synchronization should preserve ancestry. Master currently has protection rules that must be reconciled with From a52c607991b6423f4b2a04c826baca960595aa0c Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Mon, 16 Nov 2026 06:32:44 +0000 Subject: [PATCH 3/3] fix(ci): validate release and milestone versions strictly Accept canonical vX.Y.Z release tags and vX.Y milestone titles only. Remove the redundant issues write permission. Co-Authored-By: Claude gpt-6 --- .github/workflows/milestone.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/milestone.yml b/.github/workflows/milestone.yml index 85179014d..b93512010 100644 --- a/.github/workflows/milestone.yml +++ b/.github/workflows/milestone.yml @@ -9,7 +9,6 @@ on: permissions: contents: read - issues: write pull-requests: write jobs: @@ -26,16 +25,19 @@ jobs: script: | const pr = context.payload.pull_request; const { owner, repo } = context.repo; - const parse = (text) => { - const m = /^v?(\d+)\.(\d+)(?:\.(\d+))?$/.exec(text.trim()); - return m && { major: +m[1], minor: +m[2], patch: +(m[3] ?? 0) }; + const releaseTag = /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/; + const milestoneTitle = /^v(0|[1-9]\d*)\.(0|[1-9]\d*)$/; + const parse = (text, pattern) => { + const m = pattern.exec(text); + return m && m[0] === text && + { major: +m[1], minor: +m[2], patch: +(m[3] ?? 0) }; }; const compare = (a, b) => a.major - b.major || a.minor - b.minor || a.patch - b.patch; // Latest non-prerelease, non-draft release. const { data: release } = await github.rest.repos.getLatestRelease({ owner, repo }); - const stable = parse(release.tag_name); + const stable = parse(release.tag_name, releaseTag); if (!stable) { core.warning(`Latest release tag ${release.tag_name} is not vX.Y.Z; milestone of #${pr.number} left unchanged.`); return; @@ -47,11 +49,10 @@ jobs: owner, repo, state: 'open', per_page: 100, }); const candidates = open - .map((m) => ({ milestone: m, version: parse(m.title) })) + .map((m) => ({ milestone: m, version: parse(m.title, milestoneTitle) })) .filter(({ version }) => version && compare({ ...version, patch: 0 }, { ...stable, patch: 0 }) > 0) - .sort((a, b) => compare(a.version, b.version) || - a.milestone.title.length - b.milestone.title.length); + .sort((a, b) => compare(a.version, b.version)); if (candidates.length === 0) { core.warning(`No open milestone above ${release.tag_name}; milestone of #${pr.number} left unchanged.`); return;