@@ -27,6 +27,7 @@ import (
2727 "regexp"
2828 "runtime"
2929 "slices"
30+ "sort"
3031 "strconv"
3132 "strings"
3233 "sync"
@@ -2169,20 +2170,39 @@ func (Integration) BuildKubernetesTestData(ctx context.Context) error {
21692170// UpdateVersions runs an update on the `.agent-versions.yml` fetching
21702171// the latest version list from the artifact API.
21712172func (Integration ) UpdateVersions (ctx context.Context ) error {
2172- maxSnapshots := 3
2173+ agentVersion , err := version .ParseVersion (bversion .Agent )
2174+ if err != nil {
2175+ return fmt .Errorf ("failed to parse agent version %s: %w" , bversion .Agent , err )
2176+ }
2177+
2178+ // maxSnapshots is the maximum number of snapshots from
2179+ // releases branches we want to include in the snapshot list
2180+ maxSnapshots := 2
21732181
21742182 branches , err := git .GetReleaseBranches (ctx )
21752183 if err != nil {
21762184 return fmt .Errorf ("failed to list release branches: %w" , err )
21772185 }
21782186
2179- // -1 because we manually add 7.17 below
2180- if len (branches ) > maxSnapshots - 1 {
2181- branches = branches [:maxSnapshots - 1 ]
2187+ // limit the number of snapshot branches to the maxSnapshots
2188+ targetSnapshotBranches := branches [:maxSnapshots ]
2189+
2190+ // we also want to always include the latest snapshot from lts release branches
2191+ ltsBranches := []string {
2192+ // 7.17 is an LTS branch so we need to include it always
2193+ "7.17" ,
2194+ }
2195+
2196+ // if we have a newer version of the agent, we want to include the latest snapshot from 8.19 LTS branch
2197+ if agentVersion .Major () > 8 || agentVersion .Major () == 8 && agentVersion .Minor () > 19 {
2198+ // order is important
2199+ ltsBranches = append ([]string {"8.19" }, ltsBranches ... )
21822200 }
21832201
2184- // it's not a part of this repository, cannot be retrieved with `GetReleaseBranches`
2185- branches = append (branches , "7.17" )
2202+ // need to include the LTS branches, sort them and remove duplicates
2203+ targetSnapshotBranches = append (targetSnapshotBranches , ltsBranches ... )
2204+ sort .Slice (targetSnapshotBranches , git .Less (targetSnapshotBranches ))
2205+ targetSnapshotBranches = slices .Compact (targetSnapshotBranches )
21862206
21872207 // uncomment if want to have the current version snapshot on the list as well
21882208 // branches = append([]string{"master"}, branches...)
@@ -2192,7 +2212,7 @@ func (Integration) UpdateVersions(ctx context.Context) error {
21922212 CurrentMajors : 1 ,
21932213 PreviousMinors : 2 ,
21942214 PreviousMajors : 1 ,
2195- SnapshotBranches : branches ,
2215+ SnapshotBranches : targetSnapshotBranches ,
21962216 }
21972217 b , _ := json .MarshalIndent (reqs , "" , " " )
21982218 fmt .Println (string (b ))
0 commit comments