Skip to content

Commit 4e49dee

Browse files
[9.1] (backport #8761) ci: always include 8.19 LTS release branch in snapshots of test versions (#8783)
* ci: always include 8.19 LTS release branch in snapshots of test versions (#8761) * ci: always include 8.19 LTS release branch in snapshots of test versions * update .upgrade-test-agent-versions.yml (cherry picked from commit e629b9e) * fix: update .upgrade-test-agent-versions.yml --------- Co-authored-by: Panos Koutsovasilis <[email protected]>
1 parent 023bfa5 commit 4e49dee

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

magefile.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"regexp"
2828
"runtime"
2929
"slices"
30+
"sort"
3031
"strconv"
3132
"strings"
3233
"sync"
@@ -2420,20 +2421,39 @@ func (Integration) BuildKubernetesTestData(ctx context.Context) error {
24202421
// UpdateVersions runs an update on the `.agent-versions.yml` fetching
24212422
// the latest version list from the artifact API.
24222423
func (Integration) UpdateVersions(ctx context.Context) error {
2423-
maxSnapshots := 3
2424+
agentVersion, err := version.ParseVersion(bversion.Agent)
2425+
if err != nil {
2426+
return fmt.Errorf("failed to parse agent version %s: %w", bversion.Agent, err)
2427+
}
2428+
2429+
// maxSnapshots is the maximum number of snapshots from
2430+
// releases branches we want to include in the snapshot list
2431+
maxSnapshots := 2
24242432

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

2430-
// -1 because we manually add 7.17 below
2431-
if len(branches) > maxSnapshots-1 {
2432-
branches = branches[:maxSnapshots-1]
2438+
// limit the number of snapshot branches to the maxSnapshots
2439+
targetSnapshotBranches := branches[:maxSnapshots]
2440+
2441+
// we also want to always include the latest snapshot from lts release branches
2442+
ltsBranches := []string{
2443+
// 7.17 is an LTS branch so we need to include it always
2444+
"7.17",
2445+
}
2446+
2447+
// if we have a newer version of the agent, we want to include the latest snapshot from 8.19 LTS branch
2448+
if agentVersion.Major() > 8 || agentVersion.Major() == 8 && agentVersion.Minor() > 19 {
2449+
// order is important
2450+
ltsBranches = append([]string{"8.19"}, ltsBranches...)
24332451
}
24342452

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

24382458
// uncomment if want to have the current version snapshot on the list as well
24392459
// branches = append([]string{"master"}, branches...)
@@ -2443,7 +2463,7 @@ func (Integration) UpdateVersions(ctx context.Context) error {
24432463
CurrentMajors: 1,
24442464
PreviousMinors: 2,
24452465
PreviousMajors: 1,
2446-
SnapshotBranches: branches,
2466+
SnapshotBranches: targetSnapshotBranches,
24472467
}
24482468
b, _ := json.MarshalIndent(reqs, "", " ")
24492469
fmt.Println(string(b))

pkg/testing/tools/git/git.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ func GetReleaseBranches(ctx context.Context) ([]string, error) {
4141
return nil, err
4242
}
4343

44-
sort.Slice(branchList, less(branchList))
44+
sort.Slice(branchList, Less(branchList))
4545

4646
return branchList, nil
4747
}
4848

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

52-
// less makes sure we have our release branches in the right order
53-
func less(branches []string) func(i, j int) bool {
52+
// Less makes sure we have our release branches in the right order
53+
func Less(branches []string) func(i, j int) bool {
5454
return func(i, j int) bool {
5555
// we complete the versions, so we can parse semver and compare
5656
var (

pkg/testing/tools/git/git_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestLess(t *testing.T) {
4747
"wrong",
4848
}
4949

50-
sort.Slice(branchList, less(branchList))
50+
sort.Slice(branchList, Less(branchList))
5151

5252
require.Equal(t, expected, branchList)
5353
}

testing/integration/testdata/.upgrade-test-agent-versions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# upgrade integration tests.
66

77
testVersions:
8+
- 9.0.4-SNAPSHOT
89
- 9.0.3
9-
- 9.0.3-SNAPSHOT
1010
- 8.19.0-SNAPSHOT
1111
- 8.18.3
12-
- 7.17.29-SNAPSHOT
12+
- 7.17.30-SNAPSHOT

0 commit comments

Comments
 (0)