Skip to content
Merged
Show file tree
Hide file tree
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
90 changes: 90 additions & 0 deletions .github/scripts/is-release-notes-only.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// Shared by both milestone jobs. Only a complete, nonempty default-branch
// release-notes change may bypass branch and next-version rules.
module.exports = async ({ github, context, core }) => {
const pr = context.payload.pull_request;
if (pr?.milestone?.state !== 'open') {
throw new Error('An assigned open milestone is required, including for release notes.');
}

const defaultBranch = context.payload.repository?.default_branch;
if (!defaultBranch || !pr.base?.ref) {
throw new Error('Missing default or target branch for release-notes classification.');
}
if (pr.base.ref !== defaultBranch) {
return false;
}

// GitHub's list-files endpoint returns at most 3,000 files. Never infer
// eligibility from a truncated response or an unavailable expected count.
const count = pr.changed_files;
if (!Number.isSafeInteger(count) || count < 0 || count > 3000) {
throw new Error('Cannot verify the complete changed-file count (must be 0..3000).');
}
if (count === 0) {
return false;
}
if (!pr.head?.sha || !pr.base.sha) {
throw new Error('Missing PR commit identity for release-notes classification.');
}

const args = { ...context.repo, pull_number: pr.number };
const snapshot = value => JSON.stringify([
value?.head?.sha, value?.base?.ref, value?.changed_files,
value?.milestone?.id, value?.milestone?.title, value?.milestone?.state,
Comment thread
Copilot marked this conversation as resolved.
Resolved
]);
const verifySnapshot = async expectedBaseSha => {
const { data } = await github.rest.pulls.get(args);
if (!data?.base?.sha) {
throw new Error('Missing live base commit identity for release-notes classification.');
}
if (snapshot(data) !== snapshot(pr)
|| (expectedBaseSha !== undefined && data.base.sha !== expectedBaseSha)) {
throw new Error('PR changed since this event or during file retrieval; trigger a fresh milestone check.');
}
return data.base.sha;
};

// Reconciliation replays an older event after main may have advanced.
// Match PR identity to the event, but compare base SHA only between live
// snapshots so unrelated merges do not prevent a stable retrieval.
const liveBaseSha = await verifySnapshot();
const filenames = new Set();
const statuses = new Set(['added', 'modified', 'removed', 'renamed', 'copied', 'changed', 'unchanged']);
const allowedPath = path => typeof path === 'string'
&& !path.includes('\\')
&& path.split('/').every(part => part !== '' && part !== '.' && part !== '..')
&& (path === 'CHANGELOG.md' || path.startsWith('release-notes/'));
let notesOnly = true;
for (let page = 1; page <= Math.ceil(count / 100); page++) {
const { data } = await github.rest.pulls.listFiles({ ...args, per_page: 100, page });
if (!Array.isArray(data) || data.length !== Math.min(100, count - (page - 1) * 100)) {
throw new Error(`Incomplete changed-file data on page ${page}.`);
}
for (const file of data) {
if (!file || typeof file.filename !== 'string' || !file.filename || !statuses.has(file.status)) {
throw new Error('Invalid changed-file entry.');
}
if (filenames.has(file.filename)) {
throw new Error('Duplicate changed-file entry; the complete file set cannot be verified.');
}
filenames.add(file.filename);
if ((file.status === 'renamed' || file.status === 'copied') && !file.previous_filename) {
throw new Error('Missing previous filename for a renamed or copied file.');
}
// Check both sides, including deletions and code moved into notes.
if (!allowedPath(file.filename)
|| (file.previous_filename !== undefined && !allowedPath(file.previous_filename))) {
notesOnly = false;
}
}
}
await verifySnapshot(liveBaseSha);
if (notesOnly) {
core.notice('Release-notes-only PR on the default branch: skipping milestone branch and next-version rules; the open-milestone requirement still applies.');
}
return notesOnly;
};
11 changes: 9 additions & 2 deletions .github/scripts/recheck-milestones-for-release-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# whatever result it last recorded. This script closes that gap by re-running
# every semantic-version-milestoned PR targeting the default branch. That covers
# both the newly serviced series and any later series whose eligibility changes.
# Release-notes-only PRs are intentionally included: the replayed workflow
# applies the shared exception without duplicating file classification here.
#
# Re-running is enough because check-milestone-branch.sh queries the live list
# of release branches. The replayed event payload still carries the correct
Expand All @@ -30,8 +32,10 @@
# LIMITATION
# ----------
# A re-run replays the original run's commit, which means it executes the
# workflow definition and script as they existed then. Only the release branch
# lookup is evaluated live.
# workflow definition and script as they existed then. API lookups (including
# release branches and release-note file classification) are evaluated live.
# The file classifier rejects stale PR identity but allows the default branch
# to advance before a re-run; its base SHA must remain stable during retrieval.
#
# So a pull request whose most recent milestone check predates the arrival of
# the target-branch rule will replay the older check, pass it, and keep its
Expand All @@ -40,6 +44,9 @@
# distinguishing a stale replay costs an extra API call per pull request and
# the window closes on its own. After the first release branch is cut following
# a change to the check itself, review the affected pull requests by hand.
# To activate a new exception on an existing PR, first land the workflow change
# on its base, then update the PR branch with that base and trigger a fresh
# pull_request run. Re-running an old failed run does not load the new scripts.
#
# REQUIRED ENVIRONMENT VARIABLES
# ------------------------------
Expand Down
29 changes: 29 additions & 0 deletions .github/scripts/tests/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# GitHub Actions Script Tests

## Release-notes milestone exception tests

`is-release-notes-only.test.cjs` uses the built-in Node.js test runner (Node.js
20 or newer), with no npm dependencies:

```bash
node --test .github/scripts/tests/is-release-notes-only.test.cjs
```

Default-branch PRs with an assigned **open** milestone and a complete, nonempty
file set exclusively under `release-notes/` or at exact `CHANGELOG.md` bypass
only the milestone target-branch and next-version rules. Mixed changes and
non-default targets retain the existing rules. Both names used by required
status checks remain unchanged. API failures, incomplete pages, duplicate
entries, unknown file statuses, and file counts beyond the API's 3,000-file
limit fail the check rather than grant an exception. Renames/copies must have
both paths in the allowlist; deleting code is not a release-notes-only change.

Tests cover these rules, pagination boundaries, missing/closed milestones,
stale events and concurrent PR changes, and wiring in both workflow jobs.
Reconciliation continues to rerun the same workflow, including notes-only PRs.
Unrelated default-branch updates before a rerun are allowed: the head, target,
milestone, and file count must still match the event, while base-SHA stability
is checked between the live snapshots around file retrieval, not against the
historical event. Base changes during retrieval still fail closed.
After landing changes to the check, update existing PR branches with the new
base and trigger a fresh `pull_request` run; rerunning an old run reuses its old
workflow/scripts and cannot activate the exception.

## Agentic triage output tests

`validate-triage-output.test.cjs` uses the built-in Node.js test runner (Node.js
Expand Down
Loading
Loading