Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"regexp"
"runtime"
"slices"
"sort"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -2399,20 +2400,39 @@ func (Integration) BuildKubernetesTestData(ctx context.Context) error {
// UpdateVersions runs an update on the `.agent-versions.yml` fetching
// the latest version list from the artifact API.
func (Integration) UpdateVersions(ctx context.Context) error {
maxSnapshots := 3
agentVersion, err := version.ParseVersion(bversion.Agent)
if err != nil {
return fmt.Errorf("failed to parse agent version %s: %w", bversion.Agent, err)
}

// maxSnapshots is the maximum number of snapshots from
// releases branches we want to include in the snapshot list
maxSnapshots := 2

branches, err := git.GetReleaseBranches(ctx)
if err != nil {
return fmt.Errorf("failed to list release branches: %w", err)
}

// -1 because we manually add 7.17 below
if len(branches) > maxSnapshots-1 {
branches = branches[:maxSnapshots-1]
// limit the number of snapshot branches to the maxSnapshots
targetSnapshotBranches := branches[:maxSnapshots]

// we also want to always include the latest snapshot from lts release branches
ltsBranches := []string{
// 7.17 is an LTS branch so we need to include it always
"7.17",
}

// if we have a newer version of the agent, we want to include the latest snapshot from 8.19 LTS branch
if agentVersion.Major() > 8 || agentVersion.Major() == 8 && agentVersion.Minor() > 19 {
// order is important
ltsBranches = append([]string{"8.19"}, ltsBranches...)
}

// it's not a part of this repository, cannot be retrieved with `GetReleaseBranches`
branches = append(branches, "7.17")
// need to include the LTS branches, sort them and remove duplicates
targetSnapshotBranches = append(targetSnapshotBranches, ltsBranches...)
sort.Slice(targetSnapshotBranches, git.Less(targetSnapshotBranches))
targetSnapshotBranches = slices.Compact(targetSnapshotBranches)

// uncomment if want to have the current version snapshot on the list as well
// branches = append([]string{"master"}, branches...)
Expand All @@ -2422,7 +2442,7 @@ func (Integration) UpdateVersions(ctx context.Context) error {
CurrentMajors: 1,
PreviousMinors: 2,
PreviousMajors: 1,
SnapshotBranches: branches,
SnapshotBranches: targetSnapshotBranches,
}
b, _ := json.MarshalIndent(reqs, "", " ")
fmt.Println(string(b))
Expand Down
6 changes: 3 additions & 3 deletions pkg/testing/tools/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ func GetReleaseBranches(ctx context.Context) ([]string, error) {
return nil, err
}

sort.Slice(branchList, less(branchList))
sort.Slice(branchList, Less(branchList))

return branchList, nil
}

// we use this to emulate the maximum possible version value aliased by `.x`
var maxIntString = strconv.Itoa(math.MaxInt)

// less makes sure we have our release branches in the right order
func less(branches []string) func(i, j int) bool {
// Less makes sure we have our release branches in the right order
func Less(branches []string) func(i, j int) bool {
return func(i, j int) bool {
// we complete the versions, so we can parse semver and compare
var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/testing/tools/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestLess(t *testing.T) {
"wrong",
}

sort.Slice(branchList, less(branchList))
sort.Slice(branchList, Less(branchList))

require.Equal(t, expected, branchList)
}