Skip to content

Commit 8d27211

Browse files
authored
Merge pull request #3547 from saschagrunert/schedule-builder-upcoming
Add upcoming monthly releases support to schedule-builder
2 parents 591d665 + 6bbde02 commit 8d27211

File tree

3 files changed

+115
-2
lines changed

3 files changed

+115
-2
lines changed

cmd/schedule-builder/cmd/markdown.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,25 @@ var tpls embed.FS
3737
// runs with `--type=patch` to return the patch schedule
3838
func parsePatchSchedule(patchSchedule PatchSchedule) string {
3939
output := []string{}
40+
41+
if len(patchSchedule.UpcomingReleases) > 0 {
42+
output = append(output, "### Upcoming Monthly Releases\n")
43+
tableString := &strings.Builder{}
44+
table := tablewriter.NewWriter(tableString)
45+
table.SetAutoWrapText(false)
46+
table.SetHeader([]string{"Monthly Patch Release", "Cherry Pick Deadline", "Target Date"})
47+
for _, upcoming := range patchSchedule.UpcomingReleases {
48+
table.Append([]string{strings.TrimSpace(upcoming.Release), strings.TrimSpace(upcoming.CherryPickDeadline), strings.TrimSpace(upcoming.TargetDate)})
49+
}
50+
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
51+
table.SetCenterSeparator("|")
52+
table.Render()
53+
54+
output = append(output, tableString.String())
55+
}
56+
4057
output = append(output, "### Timeline\n")
58+
4159
for _, releaseSchedule := range patchSchedule.Schedules {
4260
output = append(output, fmt.Sprintf("### %s\n", releaseSchedule.Release),
4361
fmt.Sprintf("Next patch release is **%s**\n", releaseSchedule.Next.Release),
@@ -207,6 +225,46 @@ func updatePatchSchedule(refTime time.Time, schedule PatchSchedule, filePath str
207225
}
208226
}
209227

228+
newUpcomingReleases := []*PatchRelease{}
229+
latestDate := refTime
230+
for _, upcomingRelease := range schedule.UpcomingReleases {
231+
upcomingTargetDate, err := time.Parse(refDate, upcomingRelease.TargetDate)
232+
if err != nil {
233+
return fmt.Errorf("parse upcoming release target date: %w", err)
234+
}
235+
236+
if refTime.After(upcomingTargetDate) {
237+
logrus.Infof("Skipping outdated upcoming release for %s (%s)", upcomingRelease.Release, upcomingRelease.TargetDate)
238+
continue
239+
}
240+
241+
logrus.Infof("Using existing upcoming release for %s (%s)", upcomingRelease.Release, upcomingRelease.TargetDate)
242+
newUpcomingReleases = append(newUpcomingReleases, upcomingRelease)
243+
latestDate = upcomingTargetDate
244+
}
245+
for {
246+
if len(newUpcomingReleases) >= 3 {
247+
logrus.Infof("Got 3 new upcoming releases, not adding any more")
248+
break
249+
}
250+
251+
latestDate = latestDate.AddDate(0, 1, 0)
252+
cherryPickDay := firstFriday(latestDate)
253+
targetDateDay := secondTuesday(latestDate)
254+
nextCherryPickDeadline := time.Date(latestDate.Year(), latestDate.Month(), cherryPickDay, 0, 0, 0, 0, time.UTC)
255+
nextTargetDate := time.Date(latestDate.Year(), latestDate.Month(), targetDateDay, 0, 0, 0, 0, time.UTC)
256+
257+
releaseName := nextTargetDate.Format("January 2006")
258+
logrus.Infof("Adding new upcoming release for %s", releaseName)
259+
260+
newUpcomingReleases = append(newUpcomingReleases, &PatchRelease{
261+
Release: releaseName,
262+
CherryPickDeadline: nextCherryPickDeadline.Format(refDate),
263+
TargetDate: nextTargetDate.Format(refDate),
264+
})
265+
}
266+
schedule.UpcomingReleases = newUpcomingReleases
267+
210268
yamlBytes, err := yaml.Marshal(schedule)
211269
if err != nil {
212270
return fmt.Errorf("marshal schedule YAML: %w", err)

cmd/schedule-builder/cmd/markdown_test.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ import (
2727
"sigs.k8s.io/yaml"
2828
)
2929

30-
const expectedPatchSchedule = `### Timeline
30+
const expectedPatchSchedule = `### Upcoming Monthly Releases
31+
32+
| MONTHLY PATCH RELEASE | CHERRY PICK DEADLINE | TARGET DATE |
33+
|-----------------------|----------------------|-------------|
34+
| June 2020 | 2020-06-12 | 2020-06-17 |
35+
36+
### Timeline
3137
3238
### X.Y
3339
@@ -158,6 +164,13 @@ func TestParsePatchSchedule(t *testing.T) {
158164
},
159165
},
160166
},
167+
UpcomingReleases: []*PatchRelease{
168+
{
169+
Release: "June 2020",
170+
CherryPickDeadline: "2020-06-12",
171+
TargetDate: "2020-06-17",
172+
},
173+
},
161174
},
162175
},
163176
{
@@ -193,6 +206,13 @@ func TestParsePatchSchedule(t *testing.T) {
193206
},
194207
},
195208
},
209+
UpcomingReleases: []*PatchRelease{
210+
{
211+
Release: "June 2020",
212+
CherryPickDeadline: "2020-06-12",
213+
TargetDate: "2020-06-17",
214+
},
215+
},
196216
},
197217
},
198218
}
@@ -350,6 +370,23 @@ func TestUpdatePatchSchedule(t *testing.T) {
350370
EndOfLifeDate: "2023-01-01",
351371
},
352372
},
373+
UpcomingReleases: []*PatchRelease{
374+
{
375+
Release: "March 2024",
376+
CherryPickDeadline: "2024-03-08",
377+
TargetDate: "2024-03-13",
378+
},
379+
{
380+
Release: "April 2024",
381+
CherryPickDeadline: "2024-04-12",
382+
TargetDate: "2024-04-17",
383+
},
384+
{
385+
Release: "May 2024",
386+
CherryPickDeadline: "2024-05-10",
387+
TargetDate: "2024-05-14",
388+
},
389+
},
353390
},
354391
expectedSchedule: PatchSchedule{
355392
Schedules: []*Schedule{
@@ -385,6 +422,23 @@ func TestUpdatePatchSchedule(t *testing.T) {
385422
EndOfLifeDate: "2023-01-01",
386423
},
387424
},
425+
UpcomingReleases: []*PatchRelease{
426+
{
427+
Release: "April 2024",
428+
CherryPickDeadline: "2024-04-12",
429+
TargetDate: "2024-04-17",
430+
},
431+
{
432+
Release: "May 2024",
433+
CherryPickDeadline: "2024-05-10",
434+
TargetDate: "2024-05-14",
435+
},
436+
{
437+
Release: "June 2024",
438+
CherryPickDeadline: "2024-06-07",
439+
TargetDate: "2024-06-11",
440+
},
441+
},
388442
},
389443
},
390444
} {

cmd/schedule-builder/cmd/model.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ package cmd
1818

1919
// PatchSchedule main struct to hold the schedules.
2020
type PatchSchedule struct {
21-
Schedules []*Schedule `json:"schedules,omitempty" yaml:"schedules,omitempty"`
21+
UpcomingReleases []*PatchRelease `json:"upcoming_releases,omitempty" yaml:"upcoming_releases,omitempty"`
22+
Schedules []*Schedule `json:"schedules,omitempty" yaml:"schedules,omitempty"`
2223
}
2324

2425
// PatchRelease struct to define the patch schedules.

0 commit comments

Comments
 (0)