@@ -27,6 +27,7 @@ import (
2727 "regexp"
2828 "runtime"
2929 "slices"
30+ "sort"
3031 "strconv"
3132 "strings"
3233 "sync"
@@ -2399,20 +2400,39 @@ func (Integration) BuildKubernetesTestData(ctx context.Context) error {
23992400// UpdateVersions runs an update on the `.agent-versions.yml` fetching
24002401// the latest version list from the artifact API.
24012402func (Integration ) UpdateVersions (ctx context.Context ) error {
2402- maxSnapshots := 3
2403+ agentVersion , err := version .ParseVersion (bversion .Agent )
2404+ if err != nil {
2405+ return fmt .Errorf ("failed to parse agent version %s: %w" , bversion .Agent , err )
2406+ }
2407+
2408+ // maxSnapshots is the maximum number of snapshots from
2409+ // releases branches we want to include in the snapshot list
2410+ maxSnapshots := 2
24032411
24042412 branches , err := git .GetReleaseBranches (ctx )
24052413 if err != nil {
24062414 return fmt .Errorf ("failed to list release branches: %w" , err )
24072415 }
24082416
2409- // -1 because we manually add 7.17 below
2410- if len (branches ) > maxSnapshots - 1 {
2411- branches = branches [:maxSnapshots - 1 ]
2417+ // limit the number of snapshot branches to the maxSnapshots
2418+ targetSnapshotBranches := branches [:maxSnapshots ]
2419+
2420+ // we also want to always include the latest snapshot from lts release branches
2421+ ltsBranches := []string {
2422+ // 7.17 is an LTS branch so we need to include it always
2423+ "7.17" ,
2424+ }
2425+
2426+ // if we have a newer version of the agent, we want to include the latest snapshot from 8.19 LTS branch
2427+ if agentVersion .Major () > 8 || agentVersion .Major () == 8 && agentVersion .Minor () > 19 {
2428+ // order is important
2429+ ltsBranches = append ([]string {"8.19" }, ltsBranches ... )
24122430 }
24132431
2414- // it's not a part of this repository, cannot be retrieved with `GetReleaseBranches`
2415- branches = append (branches , "7.17" )
2432+ // need to include the LTS branches, sort them and remove duplicates
2433+ targetSnapshotBranches = append (targetSnapshotBranches , ltsBranches ... )
2434+ sort .Slice (targetSnapshotBranches , git .Less (targetSnapshotBranches ))
2435+ targetSnapshotBranches = slices .Compact (targetSnapshotBranches )
24162436
24172437 // uncomment if want to have the current version snapshot on the list as well
24182438 // branches = append([]string{"master"}, branches...)
@@ -2422,7 +2442,7 @@ func (Integration) UpdateVersions(ctx context.Context) error {
24222442 CurrentMajors : 1 ,
24232443 PreviousMinors : 2 ,
24242444 PreviousMajors : 1 ,
2425- SnapshotBranches : branches ,
2445+ SnapshotBranches : targetSnapshotBranches ,
24262446 }
24272447 b , _ := json .MarshalIndent (reqs , "" , " " )
24282448 fmt .Println (string (b ))
0 commit comments