Skip to content

Commit

Permalink
fix get latest tag
Browse files Browse the repository at this point in the history
  • Loading branch information
antoooks committed Feb 10, 2024
1 parent e76e0e3 commit e77082a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
21 changes: 11 additions & 10 deletions cmd/gorepomod/internal/git/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions cmd/gorepomod/internal/repo/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/gorepomod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit e77082a

Please sign in to comment.