Skip to content

Commit 1a3048f

Browse files
authored
Merge pull request #6997 from vvoland/gha-fix
gha: Port validate milestones from Moby
2 parents 77cb156 + 9177c7f commit 1a3048f

1 file changed

Lines changed: 39 additions & 16 deletions

File tree

.github/workflows/validate-milestone.yml

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: validate-milestone
22

33
permissions:
44
contents: read
5+
pull-requests: read
56

67
on:
78
pull_request:
@@ -12,24 +13,46 @@ jobs:
1213
runs-on: ubuntu-24.04
1314
timeout-minutes: 5
1415
steps:
15-
- name: Checkout
16-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
16+
- name: Validate milestone matches VERSION
17+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
18+
env:
19+
MILESTONE: ${{ github.event.pull_request.milestone.title }}
1720
with:
18-
sparse-checkout: VERSION
21+
script: |
22+
const files = await github.paginate(github.rest.pulls.listFiles, {
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
pull_number: context.payload.pull_request.number,
26+
});
27+
core.info(`Modified files: ${files.map(f => f.filename).join(', ')}`);
1928
20-
- name: Validate milestone matches VERSION
21-
run: |
22-
expected=$(cat VERSION)
23-
milestone="${{ github.event.pull_request.milestone.title }}"
29+
const touchesVersion = files.some(f => f.filename === 'VERSION');
30+
core.info(`Touches VERSION: ${touchesVersion}`);
31+
32+
// Use the PR's version when it bumps the file, base branch otherwise.
33+
// It's fine to trust the author in this case, it's not meant to be
34+
// a security gate, just a helpful check for maintainers.
35+
const ref = touchesVersion
36+
? context.payload.pull_request.head.sha
37+
: context.payload.pull_request.base.ref;
2438
25-
if [[ -z "$milestone" ]]; then
26-
echo "::error::PR must have a milestone set (expected: $expected)"
27-
exit 1
28-
fi
39+
core.info(`Base ref: ${ref}`);
2940
30-
if [[ "$milestone" != "$expected" ]]; then
31-
echo "::error::Milestone '$milestone' does not match VERSION '$expected'"
32-
exit 1
33-
fi
41+
const resp = await github.rest.repos.getContent({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
path: 'VERSION',
45+
ref,
46+
});
47+
const expected = Buffer.from(resp.data.content, resp.data.encoding).toString('utf8').trim();
48+
const milestone = process.env.MILESTONE;
3449
35-
echo "Milestone: $milestone ✓"
50+
if (!milestone) {
51+
core.setFailed(`PR must have a milestone set (expected: ${expected})`);
52+
return;
53+
}
54+
if (milestone !== expected) {
55+
core.setFailed(`Milestone '${milestone}' does not match VERSION '${expected}'`);
56+
return;
57+
}
58+
core.info(`Milestone: ${milestone} ✓`);

0 commit comments

Comments
 (0)