gha: Port validate milestones from Moby

Keep it in sync and also fix the base ref to take the VERSION file from.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2026-05-20 16:08:41 +02:00
parent 77cb156764
commit 9177c7fc6b
+40 -17
View File
@@ -2,6 +2,7 @@ name: validate-milestone
permissions: permissions:
contents: read contents: read
pull-requests: read
on: on:
pull_request: pull_request:
@@ -12,24 +13,46 @@ jobs:
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
timeout-minutes: 5 timeout-minutes: 5
steps: steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
sparse-checkout: VERSION
- name: Validate milestone matches VERSION - name: Validate milestone matches VERSION
run: | uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
expected=$(cat VERSION) env:
milestone="${{ github.event.pull_request.milestone.title }}" MILESTONE: ${{ github.event.pull_request.milestone.title }}
with:
script: |
const files = await github.paginate(github.rest.pulls.listFiles, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});
core.info(`Modified files: ${files.map(f => f.filename).join(', ')}`);
if [[ -z "$milestone" ]]; then const touchesVersion = files.some(f => f.filename === 'VERSION');
echo "::error::PR must have a milestone set (expected: $expected)" core.info(`Touches VERSION: ${touchesVersion}`);
exit 1
fi
if [[ "$milestone" != "$expected" ]]; then // Use the PR's version when it bumps the file, base branch otherwise.
echo "::error::Milestone '$milestone' does not match VERSION '$expected'" // It's fine to trust the author in this case, it's not meant to be
exit 1 // a security gate, just a helpful check for maintainers.
fi const ref = touchesVersion
? context.payload.pull_request.head.sha
: context.payload.pull_request.base.ref;
echo "Milestone: $milestone ✓" core.info(`Base ref: ${ref}`);
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 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}'`);
return;
}
core.info(`Milestone: ${milestone} ✓`);