Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 94 additions & 28 deletions .github/workflows/label-and-milestone-issues.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This workflow automatically labels issues with the preview/RC version when their fixing PR
# is merged into main or a release branch, and sets their milestone to the current version.
# All version information is read from eng/Versions.props at the merge commit.
# The version is inferred from tags and branches in the repo, with the major/minor on main taken from eng/Versions.props.

name: Label and milestone closed issues

Expand Down Expand Up @@ -28,7 +28,6 @@ jobs:
const owner = context.repo.owner;
const repo = context.repo.repo;
const prNumber = context.payload.pull_request.number;
const mergeCommitSha = context.payload.pull_request.merge_commit_sha;

// Find issues closed by this PR using GraphQL (include current milestone)
const query = `
Expand Down Expand Up @@ -56,30 +55,98 @@ jobs:
return;
}

// Read version info from eng/Versions.props at the actual merge commit
const { data: versionFileData } = await github.rest.repos.getContent({
owner,
repo,
path: 'eng/Versions.props',
ref: mergeCommitSha
});
const versionFileContent = Buffer.from(versionFileData.content, 'base64').toString('utf-8');

const versionPrefixMatch = versionFileContent.match(/<VersionPrefix>(\d+\.\d+\.\d+)<\/VersionPrefix>/);
if (!versionPrefixMatch) {
throw new Error('Could not parse VersionPrefix from eng/Versions.props');
}
const versionPrefix = versionPrefixMatch[1];
// Detect version and label from tags/branches based on the target branch
const targetBranch = context.payload.pull_request.base.ref;
let targetMilestoneName;
let label;

Comment thread
roji marked this conversation as resolved.
const preReleaseLabelMatch = versionFileContent.match(/<PreReleaseVersionLabel>(preview|rc)<\/PreReleaseVersionLabel>/);
const preReleaseIterationMatch = versionFileContent.match(/<PreReleaseVersionIteration>(\d+)<\/PreReleaseVersionIteration>/);
const releaseBranchMatch = targetBranch.match(/^release\/(\d+)\.(\d+)$/);
if (releaseBranchMatch) {
// Servicing branch (e.g. release/10.0): find the next patch version from tags
const major = releaseBranchMatch[1];
const minor = releaseBranchMatch[2];

let label;
if (preReleaseLabelMatch && preReleaseIterationMatch) {
label = `${preReleaseLabelMatch[1]}-${preReleaseIterationMatch[1]}`;
const tagRefs = await github.paginate(
github.rest.git.listMatchingRefs,
{
owner,
repo,
ref: `tags/v${major}.${minor}.`,
per_page: 100
}
);

let highestPatch = -1;
for (const ref of tagRefs) {
const m = ref.ref.match(/^refs\/tags\/v\d+\.\d+\.(\d+)$/);
if (m) {
const patch = parseInt(m[1]);
if (patch < 100 && patch > highestPatch) {
highestPatch = patch;
}
}
}

Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no GA tags are found for the servicing branch (i.e., highestPatch stays -1), the computed milestone becomes X.Y.0, which is likely incorrect and may silently create the wrong milestone. It would be safer to fail fast (or handle the bootstrap case explicitly) when no matching vX.Y.Z tags are present, rather than defaulting to .0.

Suggested change
if (highestPatch === -1) {
throw new Error(`No GA v${major}.${minor}.Z tags found for servicing branch ${targetBranch}`);
}

Copilot uses AI. Check for mistakes.
Comment thread
AndriySvyryd marked this conversation as resolved.
targetMilestoneName = `${major}.${minor}.${highestPatch + 1}`;
// No preview/rc label for servicing branches
} else if (targetBranch === 'main') {
// Main branch: read major.minor from Versions.props, then infer
// the next preview/rc from existing release branches
const { data: versionFileData } = await github.rest.repos.getContent({
owner,
repo,
path: 'eng/Versions.props',
ref: context.payload.pull_request.merge_commit_sha
});
const versionFileContent = Buffer.from(versionFileData.content, 'base64').toString('utf-8');
const versionPrefixMatch = versionFileContent.match(/<VersionPrefix>(\d+)\.(\d+)\.\d+<\/VersionPrefix>/);
if (!versionPrefixMatch) {
throw new Error('Could not parse VersionPrefix from eng/Versions.props');
}
const major = versionPrefixMatch[1];
const minor = versionPrefixMatch[2];

targetMilestoneName = `${major}.${minor}.0`;

// List release branches for this major.minor to find what's already been branched
const branchRefs = await github.paginate(
github.rest.git.listMatchingRefs,
{
owner,
repo,
ref: `heads/release/${major}.${minor}-`,
per_page: 100
}
);

let highestPreview = 0;
let highestRc = 0;
for (const ref of branchRefs) {
const previewMatch = ref.ref.match(/^refs\/heads\/release\/\d+\.\d+-preview(\d+)$/);
if (previewMatch) {
highestPreview = Math.max(highestPreview, parseInt(previewMatch[1]));
continue;
}
const rcMatch = ref.ref.match(/^refs\/heads\/release\/\d+\.\d+-rc(\d+)$/);
if (rcMatch) {
highestRc = Math.max(highestRc, parseInt(rcMatch[1]));
}
}

if (highestRc >= 2) {
// After rc2, we're heading to GA — no label
} else if (highestRc === 1) {
label = 'rc-2';
} else if (highestPreview >= 7) {
label = 'rc-1';
} else {
label = `preview-${highestPreview + 1}`;
}
} else {
throw new Error(`Unexpected target branch: ${targetBranch}`);
Comment thread
AndriySvyryd marked this conversation as resolved.
}
Comment thread
roji marked this conversation as resolved.

console.log(`Version: ${versionPrefix}, label: ${label ?? 'none'}`);
console.log(`Target branch: ${targetBranch}, milestone: ${targetMilestoneName}, label: ${label ?? 'none'}`);

// Label all closing issues
// (don't filter by state to avoid race conditions where GitHub
Expand All @@ -101,11 +168,10 @@ jobs:
}
}

// Look up the target milestone (e.g. "11.0.0", "10.0.5") via GraphQL,
// including closed milestones to avoid recreating one that already exists.
// The GraphQL query parameter does fuzzy/substring matching (no exact match
// option), so we fetch multiple results and filter client-side.
const targetMilestoneName = versionPrefix;
// Look up the target milestone via GraphQL, including closed milestones
// to avoid recreating one that already exists. The GraphQL query parameter
// does fuzzy/substring matching (no exact match option), so we fetch
// multiple results and filter client-side.
const milestoneResult = await github.graphql(`
query($owner: String!, $repo: String!, $title: String!) {
repository(owner: $owner, name: $repo) {
Expand Down Expand Up @@ -136,7 +202,7 @@ jobs:

// Set the milestone on closing issues, applying a "min" strategy:
// only update if the issue has no version milestone or the target is earlier
const targetVersion = parseVersion(versionPrefix);
const targetVersion = parseVersion(targetMilestoneName);
for (const issue of closingIssues) {
const currentTitle = issue.milestone?.title;
const currentVersion = currentTitle ? parseVersion(currentTitle) : null;
Expand Down
Loading