-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathverifyFreezePeriod.yml
More file actions
53 lines (48 loc) · 2.39 KB
/
verifyFreezePeriod.yml
File metadata and controls
53 lines (48 loc) · 2.39 KB
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
# This workflow will check if the project is currently in a Code-Freeze-Period
name: Verify Code Freeze Period
on:
workflow_call
permissions:
issues: read
jobs:
verify-freeze-period:
runs-on: ubuntu-latest
steps:
- name: Checking for code-freeze period
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
// See
// - https://octokit.github.io/rest.js/v21/#issues-list-milestones
// - https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28#list-milestones
// About pagination, see https://github.com/octokit/octokit.js#pagination
const responseIterator = github.paginate.iterator(github.rest.issues.listMilestones, {
...context.repo,
state: 'open', sort: 'due_on', direction: 'desc',
per_page: 6, // the six milestones of the current release are usually sufficient
})
const now = new Date()
for await (const response of responseIterator) { // iterate through each response
for (const milestone of response.data) {
console.log('Checking milestone ' + milestone.title)
const dueDate = new Date(milestone.due_on)
if (milestone.title.includes('RC') && isInFreezePeriodOf(dueDate, now)) {
core.setFailed('Active freeze period for ' + milestone.description)
return;
} else if (dueDate < now) {
// As milestones are sorted by descending due-dates and this one's is in the past, following ones won't match either.
return;
}
}
}
function isInFreezePeriodOf(referenceDate, nowDate) {
// A freeze period starts at the beginning of the third day before the milestone/RC
// Two days for stabilization and one for sign-off before the promotion happens at the date.
const freezePeriodStartOffset = 3
const endDate = new Date(referenceDate)
endDate.setUTCHours(24, 0, 0) // start of next day
const startDate = new Date(referenceDate)
startDate.setDate(startDate.getDate() - freezePeriodStartOffset); // handles month and year under-flow
startDate.setUTCHours(0, 0, 0) // start of the day
return startDate <= nowDate && nowDate < endDate
}