Skip to content

Commit

Permalink
Set GitHub release as 'latest' if target release is newest
Browse files Browse the repository at this point in the history
Signed-off-by: Marvin Beckers <[email protected]>
  • Loading branch information
embik committed Apr 5, 2024
1 parent 367414c commit a1a48b6
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions pkg/announce/github_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/sirupsen/logrus"

"k8s.io/utils/ptr"
"sigs.k8s.io/bom/pkg/serialize"
"sigs.k8s.io/bom/pkg/spdx"
"sigs.k8s.io/release-sdk/git"
Expand Down Expand Up @@ -297,13 +298,30 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) {
return fmt.Errorf("listing the repositories releases: %w", err)
}

// Does the release exist yet?
// Does the release exist yet and should it be marked as latest?
var releaseID int64
commitish := ""
// No pre-release should ever be marked as "latest"
markAsLatest := !isPrerelease

for _, release := range releases {
if release.GetTagName() == opts.Tag {
releaseID = release.GetID()
commitish = release.GetTargetCommitish()
} else if markAsLatest {
// If this release is not identical to the one being cut right now,
// we will check if *our* release is lower than the release from the loop.
// If the first page of releases does not include a release that is
// greater than *our* release, we can assume that ours will be the
// latest release right now.
releaseSemver, err := util.TagStringToSemver(release.GetTagName())
if err != nil {
return fmt.Errorf("parsing existing release tags as semver: %w", err)
}

if semver.LE(releaseSemver) {
markAsLatest = false
}
}
}

Expand All @@ -319,12 +337,24 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) {
// Post release data
logrus.Infof("%s the %s release on github...", releaseVerb, opts.Tag)

ghOpts := &github.UpdateReleasePageOptions{
Name: &opts.Name,
Body: ptr.To(output.String()),
Draft: &opts.Draft,
Prerelease: &isPrerelease,
}

if markAsLatest {
ghOpts.Latest = ptr.To(true)
}

// Call GitHub to set the release page
release, err := gh.UpdateReleasePage(
release, err := gh.UpdateReleasePageWithOptions(
opts.Owner, opts.Repo, releaseID,
opts.Tag, commitish, opts.Name, output.String(),
opts.Draft, isPrerelease,
opts.Tag, commitish,
ghOpts,
)

Check failure on line 357 in pkg/announce/github_page.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
if err != nil {
return fmt.Errorf("updating the release on GitHub: %w", err)
}
Expand Down

0 comments on commit a1a48b6

Please sign in to comment.