Skip to content

Commit f0b7454

Browse files
committed
[Build] Check for freeze-period based on GH milestone due-dates
This avoids accessing the RelEng build calendar through a not documented (and potential unstable) API and allows more precise and flexible control.
1 parent d1a0f15 commit f0b7454

1 file changed

Lines changed: 40 additions & 15 deletions

File tree

.github/workflows/verifyFreezePeriod.yml

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,48 @@ on:
66
workflow_call
77

88
permissions:
9-
contents: read
9+
issues: read
1010

1111
jobs:
1212
verify-freeze-period:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- name: Checking whether Eclipse project is currently in stabilization/code-freeze period ...
16-
run: |
17-
today=$(TZ=UTC date "+%Y-%m-%d")
18-
tomorrow=$(TZ=UTC date -d "+1 days" "+%Y-%m-%d")
19-
calId="prfk26fdmpru1mptlb06p0jh4s@group.calendar.google.com"
20-
calURL="https://clients6.google.com/calendar/v3/calendars/group.calendar.google.com/events?calendarId=${calId}&singleEvents=true&timeZone=UTC&maxResults=250&sanitizeHtml=true&timeMin=${today}T00:00:00Z&timeMax=${tomorrow}T00:00:00Z&key=AIzaSyBNlYH01_9Hc5S1J9vuFmu2nUqBZJNAXxs"
21-
echo "Querying calendar https://calendar.google.com/calendar/u/0/embed?src=${calId}"
22-
curl "${calURL}" | grep -i -P '(stabilization|signoff|(?<!M\d) promotion)'
23-
if [[ $? == 0 ]]; then
24-
echo "::error::Today is a freeze day"
25-
exit 1 #Exiting with non-0 makes this workflow fail
26-
fi
27-
echo "No code freeze today"
28-
shell: bash {0} # do not fail-fast
15+
- name: Checking for code-freeze period
16+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
17+
with:
18+
script: |
19+
// See
20+
// - https://octokit.github.io/rest.js/v21/#issues-list-milestones
21+
// - https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28#list-milestones
22+
// About pagination, see https://github.com/octokit/octokit.js#pagination
23+
const responseIterator = github.paginate.iterator(github.rest.issues.listMilestones, {
24+
...context.repo,
25+
state: 'open', sort: 'due_on', direction: 'desc',
26+
per_page: 6, // the six milestones of the current release are usually sufficient
27+
})
28+
const now = new Date()
29+
for await (const response of responseIterator) { // iterate through each response
30+
for (const milestone of response.data) {
31+
console.log('Checking milestone ' + milestone.title)
32+
const dueDate = new Date(milestone.due_on)
33+
if (milestone.title.includes('RC') && isInFreezePeriodOf(dueDate, now)) {
34+
core.setFailed('Active freeze period for ' + milestone.description)
35+
return;
36+
} else if (dueDate < now) {
37+
// As milestones are sorted by descending due-dates and this one's is in the past, following ones won't match either.
38+
return;
39+
}
40+
}
41+
}
42+
43+
function isInFreezePeriodOf(referenceDate, nowDate) {
44+
// A freeze period starts at the beginning of the third day before the milestone/RC
45+
// Two days for stabilization and one for sign-off before the promotion happens at the date.
46+
const freezePeriodStartOffset = 3
47+
const endDate = new Date(referenceDate)
48+
endDate.setUTCHours(24, 0, 0) // start of next day
49+
const startDate = new Date(referenceDate)
50+
startDate.setDate(startDate.getDate() - freezePeriodStartOffset); // handles month and year under-flow
51+
startDate.setUTCHours(0, 0, 0) // start of the day
52+
return startDate <= nowDate && nowDate < endDate
53+
}

0 commit comments

Comments
 (0)