@@ -366,21 +366,22 @@ func (gr *Runner) DeleteTagFromRemote(
366366 return gr .runNoOut (undoPainful , "push" , string (remote ), ":" + refsTags + tag )
367367}
368368
369- func (gr * Runner ) GetLatestTag (releaseBranch string ) (string , error ) {
369+ func (gr * Runner ) GetLatestTag (releaseTag string ) (string , error ) {
370370 var latestTag string
371- // Assuming release branch has this format: release-path/to/module-vX.Y.Z
372- // and each release branch maintains tags, extract version from latest `releaseBranch`
373- gr .comment ("extract version from latest release branch" )
374- filteredBranchList , err := gr .run (noHarmDone , "branch" , "-a" , "--list" , "*" + releaseBranch + "*" , "--sort=-committerdate" )
375- if len (filteredBranchList ) < 1 {
376- _ = fmt .Errorf ("latest tag not found for %s" , releaseBranch )
371+ // Assuming release branch has this format: module/vX.Y.Z
372+ gr .comment ("extract version from latest release tag" )
373+
374+ // Using `creatordate` sort key as it is more accurate
375+ filteredTagList , err := gr .run (noHarmDone , "tag" , "-l" , "--sort=-creatordate" , releaseTag + "*" )
376+ if len (filteredTagList ) < 1 {
377+ _ = fmt .Errorf ("latest tag not found for %s" , releaseTag )
377378 return "" , err
378379 }
379- newestBranch := strings .Split (strings .ReplaceAll (filteredBranchList , "\r \n " , "\n " ), "\n " )
380- split := strings .Split (newestBranch [0 ], "- " )
380+ newestTag := strings .Split (strings .ReplaceAll (filteredTagList , "\r \n " , "\n " ), "\n " )
381+ split := strings .Split (newestTag [0 ], "/ " )
381382 latestTag = split [len (split )- 1 ]
382383 if err != nil {
383- _ = fmt .Errorf ("error getting latest tag for %s" , releaseBranch )
384+ _ = fmt .Errorf ("error getting latest tag for %s" , releaseTag )
384385 }
385386
386387 return latestTag , nil
0 commit comments