@@ -27,6 +27,7 @@ import (
2727 "regexp"
2828 "runtime"
2929 "slices"
30+ "sort"
3031 "strconv"
3132 "strings"
3233 "sync"
@@ -2076,20 +2077,39 @@ func (Integration) BuildKubernetesTestData(ctx context.Context) error {
20762077// UpdateVersions runs an update on the `.agent-versions.yml` fetching
20772078// the latest version list from the artifact API.
20782079func (Integration ) UpdateVersions (ctx context.Context ) error {
2079- maxSnapshots := 3
2080+ agentVersion , err := version .ParseVersion (bversion .Agent )
2081+ if err != nil {
2082+ return fmt .Errorf ("failed to parse agent version %s: %w" , bversion .Agent , err )
2083+ }
2084+
2085+ // maxSnapshots is the maximum number of snapshots from
2086+ // releases branches we want to include in the snapshot list
2087+ maxSnapshots := 2
20802088
20812089 branches , err := git .GetReleaseBranches (ctx )
20822090 if err != nil {
20832091 return fmt .Errorf ("failed to list release branches: %w" , err )
20842092 }
20852093
2086- // -1 because we manually add 7.17 below
2087- if len (branches ) > maxSnapshots - 1 {
2088- branches = branches [:maxSnapshots - 1 ]
2094+ // limit the number of snapshot branches to the maxSnapshots
2095+ targetSnapshotBranches := branches [:maxSnapshots ]
2096+
2097+ // we also want to always include the latest snapshot from lts release branches
2098+ ltsBranches := []string {
2099+ // 7.17 is an LTS branch so we need to include it always
2100+ "7.17" ,
2101+ }
2102+
2103+ // if we have a newer version of the agent, we want to include the latest snapshot from 8.19 LTS branch
2104+ if agentVersion .Major () > 8 || agentVersion .Major () == 8 && agentVersion .Minor () > 19 {
2105+ // order is important
2106+ ltsBranches = append ([]string {"8.19" }, ltsBranches ... )
20892107 }
20902108
2091- // it's not a part of this repository, cannot be retrieved with `GetReleaseBranches`
2092- branches = append (branches , "7.17" )
2109+ // need to include the LTS branches, sort them and remove duplicates
2110+ targetSnapshotBranches = append (targetSnapshotBranches , ltsBranches ... )
2111+ sort .Slice (targetSnapshotBranches , git .Less (targetSnapshotBranches ))
2112+ targetSnapshotBranches = slices .Compact (targetSnapshotBranches )
20932113
20942114 // uncomment if want to have the current version snapshot on the list as well
20952115 // branches = append([]string{"master"}, branches...)
@@ -2099,7 +2119,7 @@ func (Integration) UpdateVersions(ctx context.Context) error {
20992119 CurrentMajors : 1 ,
21002120 PreviousMinors : 2 ,
21012121 PreviousMajors : 1 ,
2102- SnapshotBranches : branches ,
2122+ SnapshotBranches : targetSnapshotBranches ,
21032123 }
21042124 b , _ := json .MarshalIndent (reqs , "" , " " )
21052125 fmt .Println (string (b ))
0 commit comments