@@ -27,6 +27,7 @@ import (
2727 "regexp"
2828 "runtime"
2929 "slices"
30+ "sort"
3031 "strconv"
3132 "strings"
3233 "sync"
@@ -2147,20 +2148,39 @@ func (Integration) BuildKubernetesTestData(ctx context.Context) error {
21472148// UpdateVersions runs an update on the `.agent-versions.yml` fetching
21482149// the latest version list from the artifact API.
21492150func (Integration ) UpdateVersions (ctx context.Context ) error {
2150- maxSnapshots := 3
2151+ agentVersion , err := version .ParseVersion (bversion .Agent )
2152+ if err != nil {
2153+ return fmt .Errorf ("failed to parse agent version %s: %w" , bversion .Agent , err )
2154+ }
2155+
2156+ // maxSnapshots is the maximum number of snapshots from
2157+ // releases branches we want to include in the snapshot list
2158+ maxSnapshots := 2
21512159
21522160 branches , err := git .GetReleaseBranches (ctx )
21532161 if err != nil {
21542162 return fmt .Errorf ("failed to list release branches: %w" , err )
21552163 }
21562164
2157- // -1 because we manually add 7.17 below
2158- if len (branches ) > maxSnapshots - 1 {
2159- branches = branches [:maxSnapshots - 1 ]
2165+ // limit the number of snapshot branches to the maxSnapshots
2166+ targetSnapshotBranches := branches [:maxSnapshots ]
2167+
2168+ // we also want to always include the latest snapshot from lts release branches
2169+ ltsBranches := []string {
2170+ // 7.17 is an LTS branch so we need to include it always
2171+ "7.17" ,
2172+ }
2173+
2174+ // if we have a newer version of the agent, we want to include the latest snapshot from 8.19 LTS branch
2175+ if agentVersion .Major () > 8 || agentVersion .Major () == 8 && agentVersion .Minor () > 19 {
2176+ // order is important
2177+ ltsBranches = append ([]string {"8.19" }, ltsBranches ... )
21602178 }
21612179
2162- // it's not a part of this repository, cannot be retrieved with `GetReleaseBranches`
2163- branches = append (branches , "7.17" )
2180+ // need to include the LTS branches, sort them and remove duplicates
2181+ targetSnapshotBranches = append (targetSnapshotBranches , ltsBranches ... )
2182+ sort .Slice (targetSnapshotBranches , git .Less (targetSnapshotBranches ))
2183+ targetSnapshotBranches = slices .Compact (targetSnapshotBranches )
21642184
21652185 // uncomment if want to have the current version snapshot on the list as well
21662186 // branches = append([]string{"master"}, branches...)
@@ -2170,7 +2190,7 @@ func (Integration) UpdateVersions(ctx context.Context) error {
21702190 CurrentMajors : 1 ,
21712191 PreviousMinors : 2 ,
21722192 PreviousMajors : 1 ,
2173- SnapshotBranches : branches ,
2193+ SnapshotBranches : targetSnapshotBranches ,
21742194 }
21752195 b , _ := json .MarshalIndent (reqs , "" , " " )
21762196 fmt .Println (string (b ))
0 commit comments