From 9b61bda97958239c35d91188ead26b0c16fc3777 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 27 Sep 2023 10:06:13 -0700 Subject: [PATCH] update GHReleases func to support tags without v prefix --- hack/update/github.go | 50 +++++++++++-------------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/hack/update/github.go b/hack/update/github.go index 8c7fde93055f..050046198136 100644 --- a/hack/update/github.go +++ b/hack/update/github.go @@ -48,38 +48,47 @@ func GHReleases(ctx context.Context, owner, repo string) (stable, latest, edge R // walk through the paginated list of up to ghSearchLimit newest releases opts := &github.ListOptions{PerPage: ghListPerPage} for (opts.Page+1)*ghListPerPage <= ghSearchLimit { - rls, resp, err := ghc.Repositories.ListReleases(ctx, owner, repo, opts) + rls, resp, err := ghc.Repositories.ListTags(ctx, owner, repo, opts) if err != nil { return stable, latest, edge, err } for _, rl := range rls { - ver := rl.GetTagName() + ver := rl.GetName() + commit := rl.GetCommit().GetSHA() if !semver.IsValid(ver) { - continue + ver = fmt.Sprintf("v%s", ver) + if !semver.IsValid(ver) { + continue + } } // check if ver version is release (ie, 'v1.19.2') or pre-release (ie, 'v1.19.3-rc.0' or 'v1.19.0-beta.2') prerls := semver.Prerelease(ver) if prerls == "" { if semver.Compare(ver, stable.Tag) == 1 { stable.Tag = ver + stable.Commit = commit } } else if strings.HasPrefix(prerls, "-rc") || strings.HasPrefix(prerls, "-beta") { if semver.Compare(ver, latest.Tag) == 1 { latest.Tag = ver + latest.Commit = commit } } else if strings.Contains(prerls, "-alpha") { if semver.Compare(ver, edge.Tag) == 1 { edge.Tag = ver + edge.Commit = commit } } // make sure that latest >= stable if semver.Compare(latest.Tag, stable.Tag) == -1 { latest.Tag = stable.Tag + latest.Commit = stable.Commit } // make sure that edge >= latest if semver.Compare(edge.Tag, latest.Tag) == -1 { edge.Tag = latest.Tag + edge.Commit = latest.Commit } } if resp.NextPage == 0 { @@ -87,41 +96,8 @@ func GHReleases(ctx context.Context, owner, repo string) (stable, latest, edge R } opts.Page = resp.NextPage } - // create a map where the key is the tag and the values is an array of releases (stable, latest, edge) that match the tag - releasesWithoutCommits := map[string][]*Release{} - for _, rl := range []*Release{&stable, &latest, &edge} { - releasesWithoutCommits[rl.Tag] = append(releasesWithoutCommits[rl.Tag], rl) - } - // run though the releases to find ones that don't yet have a commit and assign it - opts = &github.ListOptions{PerPage: ghListPerPage} - for (opts.Page+1)*ghListPerPage <= ghSearchLimit { - tags, resp, err := ghc.Repositories.ListTags(ctx, owner, repo, opts) - if err != nil { - return stable, latest, edge, err - } - for _, tag := range tags { - rls, ok := releasesWithoutCommits[*tag.Name] - if !ok { - continue - } - for _, rl := range rls { - rl.Commit = *tag.Commit.SHA - } - delete(releasesWithoutCommits, *tag.Name) - if len(releasesWithoutCommits) == 0 { - return stable, latest, edge, nil - } - } - if len(releasesWithoutCommits) == 0 { - break - } - if resp.NextPage == 0 { - break - } - opts.Page = resp.NextPage - } - return stable, latest, edge, fmt.Errorf("wasn't able to find commit for releases") + return stable, latest, edge, nil } func StableVersion(ctx context.Context, owner, repo string) (string, error) {