From e77082a3424f173d2a93f2113a679008d04a330b Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Sat, 10 Feb 2024 23:01:07 +0700 Subject: [PATCH] fix get latest tag --- cmd/gorepomod/internal/git/runner.go | 21 +++++++++++---------- cmd/gorepomod/internal/repo/manager.go | 15 ++------------- cmd/gorepomod/main.go | 7 ++++--- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/cmd/gorepomod/internal/git/runner.go b/cmd/gorepomod/internal/git/runner.go index 8db6759cbf..629f216bf0 100644 --- a/cmd/gorepomod/internal/git/runner.go +++ b/cmd/gorepomod/internal/git/runner.go @@ -366,21 +366,22 @@ func (gr *Runner) DeleteTagFromRemote( return gr.runNoOut(undoPainful, "push", string(remote), ":"+refsTags+tag) } -func (gr *Runner) GetLatestTag(releaseBranch string) (string, error) { +func (gr *Runner) GetLatestTag(releaseTag string) (string, error) { var latestTag string - // Assuming release branch has this format: release-path/to/module-vX.Y.Z - // and each release branch maintains tags, extract version from latest `releaseBranch` - gr.comment("extract version from latest release branch") - filteredBranchList, err := gr.run(noHarmDone, "branch", "-a", "--list", "*"+releaseBranch+"*", "--sort=-committerdate") - if len(filteredBranchList) < 1 { - _ = fmt.Errorf("latest tag not found for %s", releaseBranch) + // Assuming release branch has this format: module/vX.Y.Z + gr.comment("extract version from latest release tag") + + // Using `creatordate` sort key as it is more accurate + filteredTagList, err := gr.run(noHarmDone, "tag", "-l", "--sort=-creatordate", releaseTag+"*") + if len(filteredTagList) < 1 { + _ = fmt.Errorf("latest tag not found for %s", releaseTag) return "", err } - newestBranch := strings.Split(strings.ReplaceAll(filteredBranchList, "\r\n", "\n"), "\n") - split := strings.Split(newestBranch[0], "-") + newestTag := strings.Split(strings.ReplaceAll(filteredTagList, "\r\n", "\n"), "\n") + split := strings.Split(newestTag[0], "/") latestTag = split[len(split)-1] if err != nil { - _ = fmt.Errorf("error getting latest tag for %s", releaseBranch) + _ = fmt.Errorf("error getting latest tag for %s", releaseTag) } return latestTag, nil diff --git a/cmd/gorepomod/internal/repo/manager.go b/cmd/gorepomod/internal/repo/manager.go index 4079af32f5..6b21af458e 100644 --- a/cmd/gorepomod/internal/repo/manager.go +++ b/cmd/gorepomod/internal/repo/manager.go @@ -84,8 +84,8 @@ func (mgr *Manager) List() error { // Auto-update local tags gr := git.NewQuiet(mgr.AbsPath(), false, false) for _, module := range mgr.modules { - releaseBranch := fmt.Sprintf("release-%s", module.ShortName()) - _, err := gr.GetLatestTag(releaseBranch) + releaseTag := string(module.ShortName()) + _, err := gr.GetLatestTag(releaseTag) if err != nil { return fmt.Errorf("failed getting latest tags for %s", module) } @@ -204,17 +204,6 @@ func (mgr *Manager) Release( if err := gr.AssureCleanWorkspace(); err != nil { return err } - // Deprecated: no need to create new release branch, - // gorepomod will determine new version to publish based on release branch - // if err := gr.CheckoutReleaseBranch(mgr.remoteName, relBranch); err != nil { - // return err - // } - // if err := gr.MergeFromRemoteMain(mgr.remoteName); err != nil { - // return err - // } - // if err := gr.PushBranchToRemote(mgr.remoteName, relBranch); err != nil { - // return err - // } if err := gr.CreateLocalReleaseTag(relTag, relBranch); err != nil { return err } diff --git a/cmd/gorepomod/main.go b/cmd/gorepomod/main.go index 9fe091800d..22258ec3e5 100644 --- a/cmd/gorepomod/main.go +++ b/cmd/gorepomod/main.go @@ -83,9 +83,9 @@ func actualMain() error { if v.IsZero() { // Always use latest tag while does not removing manual usage capability - releaseBranch := fmt.Sprintf("release-%s", targetModule.ShortName()) - fmt.Printf("new version not specified, fall back to latest version according to release branch: %s-*\n", releaseBranch) - latest, err := gr.GetLatestTag(releaseBranch) + releaseTag := string(targetModule.ShortName()) + fmt.Printf("new version not specified, fall back to latest version according to release tag: %s/*\n", releaseTag) + latest, err := gr.GetLatestTag(releaseTag) if err != nil { v = targetModule.VersionLocal() err = mgr.Pin(args.DoIt(), targetModule, v) @@ -94,6 +94,7 @@ func actualMain() error { } return nil } + fmt.Printf("setting release tag to %s ...\n", latest) v, err = semver.Parse(latest) if err != nil { v = targetModule.VersionLocal()