Skip to content

Commit

Permalink
Merge pull request #3547 from saschagrunert/schedule-builder-upcoming
Browse files Browse the repository at this point in the history
Add upcoming monthly releases support to schedule-builder
  • Loading branch information
k8s-ci-robot authored Apr 4, 2024
2 parents 591d665 + 6bbde02 commit 8d27211
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 2 deletions.
58 changes: 58 additions & 0 deletions cmd/schedule-builder/cmd/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,25 @@ var tpls embed.FS
// runs with `--type=patch` to return the patch schedule
func parsePatchSchedule(patchSchedule PatchSchedule) string {
output := []string{}

if len(patchSchedule.UpcomingReleases) > 0 {
output = append(output, "### Upcoming Monthly Releases\n")
tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString)
table.SetAutoWrapText(false)
table.SetHeader([]string{"Monthly Patch Release", "Cherry Pick Deadline", "Target Date"})
for _, upcoming := range patchSchedule.UpcomingReleases {
table.Append([]string{strings.TrimSpace(upcoming.Release), strings.TrimSpace(upcoming.CherryPickDeadline), strings.TrimSpace(upcoming.TargetDate)})
}
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.Render()

output = append(output, tableString.String())
}

output = append(output, "### Timeline\n")

for _, releaseSchedule := range patchSchedule.Schedules {
output = append(output, fmt.Sprintf("### %s\n", releaseSchedule.Release),
fmt.Sprintf("Next patch release is **%s**\n", releaseSchedule.Next.Release),
Expand Down Expand Up @@ -207,6 +225,46 @@ func updatePatchSchedule(refTime time.Time, schedule PatchSchedule, filePath str
}
}

newUpcomingReleases := []*PatchRelease{}
latestDate := refTime
for _, upcomingRelease := range schedule.UpcomingReleases {
upcomingTargetDate, err := time.Parse(refDate, upcomingRelease.TargetDate)
if err != nil {
return fmt.Errorf("parse upcoming release target date: %w", err)
}

if refTime.After(upcomingTargetDate) {
logrus.Infof("Skipping outdated upcoming release for %s (%s)", upcomingRelease.Release, upcomingRelease.TargetDate)
continue
}

logrus.Infof("Using existing upcoming release for %s (%s)", upcomingRelease.Release, upcomingRelease.TargetDate)
newUpcomingReleases = append(newUpcomingReleases, upcomingRelease)
latestDate = upcomingTargetDate
}
for {
if len(newUpcomingReleases) >= 3 {
logrus.Infof("Got 3 new upcoming releases, not adding any more")
break
}

latestDate = latestDate.AddDate(0, 1, 0)
cherryPickDay := firstFriday(latestDate)
targetDateDay := secondTuesday(latestDate)
nextCherryPickDeadline := time.Date(latestDate.Year(), latestDate.Month(), cherryPickDay, 0, 0, 0, 0, time.UTC)
nextTargetDate := time.Date(latestDate.Year(), latestDate.Month(), targetDateDay, 0, 0, 0, 0, time.UTC)

releaseName := nextTargetDate.Format("January 2006")
logrus.Infof("Adding new upcoming release for %s", releaseName)

newUpcomingReleases = append(newUpcomingReleases, &PatchRelease{
Release: releaseName,
CherryPickDeadline: nextCherryPickDeadline.Format(refDate),
TargetDate: nextTargetDate.Format(refDate),
})
}
schedule.UpcomingReleases = newUpcomingReleases

yamlBytes, err := yaml.Marshal(schedule)
if err != nil {
return fmt.Errorf("marshal schedule YAML: %w", err)
Expand Down
56 changes: 55 additions & 1 deletion cmd/schedule-builder/cmd/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ import (
"sigs.k8s.io/yaml"
)

const expectedPatchSchedule = `### Timeline
const expectedPatchSchedule = `### Upcoming Monthly Releases
| MONTHLY PATCH RELEASE | CHERRY PICK DEADLINE | TARGET DATE |
|-----------------------|----------------------|-------------|
| June 2020 | 2020-06-12 | 2020-06-17 |
### Timeline
### X.Y
Expand Down Expand Up @@ -158,6 +164,13 @@ func TestParsePatchSchedule(t *testing.T) {
},
},
},
UpcomingReleases: []*PatchRelease{
{
Release: "June 2020",
CherryPickDeadline: "2020-06-12",
TargetDate: "2020-06-17",
},
},
},
},
{
Expand Down Expand Up @@ -193,6 +206,13 @@ func TestParsePatchSchedule(t *testing.T) {
},
},
},
UpcomingReleases: []*PatchRelease{
{
Release: "June 2020",
CherryPickDeadline: "2020-06-12",
TargetDate: "2020-06-17",
},
},
},
},
}
Expand Down Expand Up @@ -350,6 +370,23 @@ func TestUpdatePatchSchedule(t *testing.T) {
EndOfLifeDate: "2023-01-01",
},
},
UpcomingReleases: []*PatchRelease{
{
Release: "March 2024",
CherryPickDeadline: "2024-03-08",
TargetDate: "2024-03-13",
},
{
Release: "April 2024",
CherryPickDeadline: "2024-04-12",
TargetDate: "2024-04-17",
},
{
Release: "May 2024",
CherryPickDeadline: "2024-05-10",
TargetDate: "2024-05-14",
},
},
},
expectedSchedule: PatchSchedule{
Schedules: []*Schedule{
Expand Down Expand Up @@ -385,6 +422,23 @@ func TestUpdatePatchSchedule(t *testing.T) {
EndOfLifeDate: "2023-01-01",
},
},
UpcomingReleases: []*PatchRelease{
{
Release: "April 2024",
CherryPickDeadline: "2024-04-12",
TargetDate: "2024-04-17",
},
{
Release: "May 2024",
CherryPickDeadline: "2024-05-10",
TargetDate: "2024-05-14",
},
{
Release: "June 2024",
CherryPickDeadline: "2024-06-07",
TargetDate: "2024-06-11",
},
},
},
},
} {
Expand Down
3 changes: 2 additions & 1 deletion cmd/schedule-builder/cmd/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ package cmd

// PatchSchedule main struct to hold the schedules.
type PatchSchedule struct {
Schedules []*Schedule `json:"schedules,omitempty" yaml:"schedules,omitempty"`
UpcomingReleases []*PatchRelease `json:"upcoming_releases,omitempty" yaml:"upcoming_releases,omitempty"`
Schedules []*Schedule `json:"schedules,omitempty" yaml:"schedules,omitempty"`
}

// PatchRelease struct to define the patch schedules.
Expand Down

0 comments on commit 8d27211

Please sign in to comment.