-
Notifications
You must be signed in to change notification settings - Fork 81
66 lines (56 loc) · 2.07 KB
/
release-milestone.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: 'Release Milestone Check'
on:
pull_request_target:
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
jobs:
check-release-milestone:
name: Check Release Milestone
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: './'
- id: version
run: |
echo "::set-output name=version::$(cat ./VERSION)"
- name: Block merge if release milestone is missing
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const nextMinorRegex = /^(v[0-9]+\.[0-9]+)\.0-dev/gmi;
let match = nextMinorRegex.exec('${{ steps.version.outputs.version }}');
if (match == null) {
core.info('VERSION does not indicate that the next version is a new minor release - skipping check');
return;
}
const nextMinorVersion = match[1];
const milestones = await github.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'due_on',
direction: 'desc'
});
let milestoneForNextMinorReleaseFound = false;
for (const milestone of milestones.data) {
if (milestone.title != nextMinorVersion) {
continue;
}
// milestone found, check if PR is associated
milestoneForNextMinorReleaseFound = true;
if (context.payload.pull_request.milestone == null) {
core.setFailed('Milestone for next minor release ' + nextMinorVersion + ' found, however, PR is not milestoned for it. Merge is not allowed.');
return
}
}
if (milestoneForNextMinorReleaseFound) {
core.info('Milestone for next minor release ' + nextMinorVersion + ' found and PR is milestoned for it. Merge is allowed.');
} else {
core.info('Milestone for next minor release ' + nextMinorVersion + ' not found. Merge is allowed.');
}