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
85 changes: 59 additions & 26 deletions .github/workflows/validate-milestone.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,91 @@
name: validate-milestone

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: read
issues: read

on:
pull_request:
types: [opened, synchronize, milestoned, demilestoned, edited]
types: [opened, reopened, edited, synchronize, milestoned, demilestoned]

jobs:
validate-milestone:
if: ${{ github.repository == 'docker/cli' && github.event.pull_request.state == 'open' }}
runs-on: ubuntu-26.04
timeout-minutes: 5
steps:
- name: Validate milestone matches VERSION
- name: Validate milestone matches next version
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
MILESTONE: ${{ github.event.pull_request.milestone.title }}
# Pinned "[Branch status]" issue with a "json docker-versions" block
# mapping each branch to its next and last version.
BRANCH_STATUS_ISSUE: 7526
with:
script: |
const files = await github.paginate(github.rest.pulls.listFiles, {
const issueNumber = Number(process.env.BRANCH_STATUS_ISSUE);
const source = `issue #${issueNumber}`;
const baseBranch = context.payload.pull_request.base.ref;
core.info(`Base branch: ${baseBranch}`);

const {data: issue} = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
issue_number: issueNumber,
});
core.info(`Modified files: ${files.map(f => f.filename).join(', ')}`);

const touchesVersion = files.some(f => f.filename === 'VERSION');
core.info(`Touches VERSION: ${touchesVersion}`);

// Use the PR's version when it bumps the file, base branch otherwise.
// It's fine to trust the author in this case, it's not meant to be
// a security gate, just a helpful check for maintainers.
const ref = touchesVersion
? context.payload.pull_request.head.sha
: context.payload.pull_request.base.ref;
const lines = (issue.body ?? '').split('\n').map(line => line.trimEnd());
const start = lines.indexOf('```json docker-versions') + 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[low] Opening-fence match requires exact line; leading whitespace causes a false "not found" failure

lines.indexOf('```json docker-versions') performs an exact string comparison. The .trimEnd() applied on the previous line strips only trailing whitespace, not leading spaces. If the opening code-fence in the branch-status issue body has any leading whitespace (e.g., indented inside a list or blockquote), indexOf returns -1, start becomes 0, and the guard on line 42 fires with:

Could not find a 'json docker-versions block' in issue #7526

This is not a silent failure — the error is surfaced — but it can be confusing to debug because the message implies the block is missing, not misindented. Consider using a leading-whitespace-tolerant match:

Suggested change
const start = lines.indexOf('```json docker-versions') + 1;
const lines = (issue.body ?? '').split('\n').map(line => line.trimEnd());
const start = lines.findIndex(l => l.trim() === '```json docker-versions') + 1;
Confidence Score
🟢 strong 100/100

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I kept it identical to the workflow in moby/moby. We can probably improve, although it's expected for the ticket to have a somewhat strict format.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fair point — keeping the workflows synchronized makes sense, especially since both issues currently use the strict format without leading whitespace. The suggestion would only add value if the format becomes more flexible in the future (e.g., nesting the block in a list), but that's not the case now.

Feel free to close this or keep it as a reference if the format ever needs to evolve across both repos.

const end = lines.indexOf('```', start);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[low] Closing-fence search matches any standalone triple-backtick line within the JSON block

lines.indexOf('```', start) finds the first line (after trimEnd()) that is exactly three backticks, starting from the opening fence. If the JSON content between the fences ever contains a line that is only \``— for example if someone edits the issue body and adds a stray markdown fence — the JSON slice will be truncated at that line, causingJSON.parse` to throw with a confusing "Invalid json docker-versions block" error.

In practice valid JSON cannot naturally contain such a line (all strings must be quoted), so this is a theoretical fragility rather than an immediately exploitable bug. It is worth noting as a future robustness concern, especially since the issue body is a human-editable document.

Confidence Score
🟡 moderate 70/100

if (start === 0 || end === -1) {
core.setFailed(`Could not find a 'json docker-versions' block in ${source}`);
return;
}

core.info(`Base ref: ${ref}`);
// For example: {"master": {"next": "29.10.0", "last": "29.9.1"}}
let versions;
try {
versions = JSON.parse(lines.slice(start, end).join('\n'));
} catch (err) {
core.setFailed(`Invalid 'json docker-versions' block in ${source}: ${err.message}`);
return;
}
core.info(`Versions: ${JSON.stringify(versions)}`);

const resp = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: 'VERSION',
ref,
});
const expected = Buffer.from(resp.data.content, resp.data.encoding).toString('utf8').trim();
const expected = versions?.[baseBranch]?.next;
if (!expected) {
core.setFailed(`Could not find the next version for branch '${baseBranch}' in ${source}`);
return;
}
const milestone = process.env.MILESTONE;

if (!milestone) {
core.setFailed(`PR must have a milestone set (expected: ${expected})`);
return;
}
if (milestone !== expected) {
core.setFailed(`Milestone '${milestone}' does not match VERSION '${expected}'`);
const guidance =
'This check prevents the PR from being merged accidentally before it is appropriate ' +
'for its milestone. If the milestone is intentional, no action is needed.';
await core.summary
.addHeading('This PR is intentionally blocked from merging for now')
.addTable([
[
{data: 'Milestone', header: true},
{data: 'Expected next version', header: true},
],
[milestone, expected],
])
.addRaw(`The expected version for the '${baseBranch}' branch comes from ${source}.`)
.addEOL()
.addRaw(guidance)
.write();
core.setFailed(
`This PR cannot be merged yet because milestone '${milestone}' does not match ` +
`the next version '${expected}'. ${guidance}`
);
return;
}
core.info(`Milestone: ${milestone} ✓`);
Loading