-
Notifications
You must be signed in to change notification settings - Fork 292
64 lines (63 loc) · 2.58 KB
/
increment-milestone-on-tag.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
name: Increment milestones on tag
on:
create
permissions:
issues: write # Required to update milestones
jobs:
increment_milestone:
if: github.event.ref_type == 'tag' && contains(github.event.ref,'-RC') == false
runs-on: ubuntu-latest
steps:
- name: Close current milestone
id: close-milestone
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # 7.0.1
with:
script: |
// Get the milestone title ("X.Y.Z") from tag name ("vX.Y.Z")
const match = '${{github.event.ref}}'.match(/v(\d+\.\d+\.\d+)/i)
if (!match) {
core.setFailed('Failed to parse tag name into milestone title: ${{github.event.ref}}')
return
}
const milestoneTitle = match[1]
// Look for the milestone from its title
const response = await github.rest.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
})
if (!response.data || response.data.length == 0) {
core.setFailed(`Failed to list milestones: ${response.status}`)
return
}
const milestone = response.data.find(milestone => milestone.title == milestoneTitle)
if (!milestone) {
core.setFailed(`Failed to find milestone: ${milestoneTitle}`)
return
}
// Close the milestone
await github.rest.issues.updateMilestone({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
milestone_number: milestone.number
}).catch(error => {
core.setFailed(`Failed to close milestone: ${error}`)
})
// Compute the next milestone version
const versionNumbers = milestoneTitle.split('.').map(Number)
if (versionNumbers[2] != 0) {
core.info('Closing a patch version milestone. Not opening a new one.')
return
}
versionNumbers[1]++
const nextMilestoneTitle = versionNumbers.join('.')
core.info(`Creating next version milestone: ${nextMilestoneTitle}`)
// Create the next milestone
await github.rest.issues.createMilestone({
owner: context.repo.owner,
repo: context.repo.repo,
title: nextMilestoneTitle
}).catch(error => {
core.setFailed(`Failed to create milestone ${nextMilestoneTitle}: ${error}`)
})