1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-15 01:34:21 +02:00

Support make_latest for GitHub release (#4161)

This commit adds a `make_latest` boolean to the release configuration,
to allow signaling to GitHub if the release should be marked as latest.

Albeit being a boolean, the internal Go type is a string to allow
to distinguish an empty string (default behavior: `true`) from an
explicit `false`.

For more information around the GitHub API field, see

https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release

I did not include the `legacy` option, to not adopt something which
appears to be scheduled for removal in the future.

In addition, I opted for `make_latest` over `latest` because the
option is only available for GitHub. Which keeps the latter key
reserved for e.g. future use of a config option which is used across
Git providers.

Fixes #4159

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
This commit is contained in:
Hidde Beydals
2023-07-14 03:42:20 +02:00
committed by GitHub
parent a3a15fb18b
commit 9f6a810fbc
3 changed files with 15 additions and 0 deletions

View File

@ -349,6 +349,7 @@ func (c *githubClient) CreateRelease(ctx *context.Context, body string) (string,
Body: github.String(body), Body: github.String(body),
Draft: github.Bool(ctx.Config.Release.Draft), Draft: github.Bool(ctx.Config.Release.Draft),
Prerelease: github.Bool(ctx.PreRelease), Prerelease: github.Bool(ctx.PreRelease),
MakeLatest: github.String("true"),
} }
if ctx.Config.Release.DiscussionCategoryName != "" { if ctx.Config.Release.DiscussionCategoryName != "" {
@ -365,6 +366,10 @@ func (c *githubClient) CreateRelease(ctx *context.Context, body string) (string,
} }
} }
if latest := strings.TrimSpace(ctx.Config.Release.MakeLatest); latest == "false" {
data.MakeLatest = github.String(latest)
}
release, err := c.createOrUpdateRelease(ctx, data, body) release, err := c.createOrUpdateRelease(ctx, data, body)
if err != nil { if err != nil {
return "", fmt.Errorf("could not release: %w", err) return "", fmt.Errorf("could not release: %w", err)

View File

@ -661,6 +661,7 @@ type Release struct {
Disable string `yaml:"disable,omitempty" json:"disable,omitempty" jsonschema:"oneof_type=string;boolean"` Disable string `yaml:"disable,omitempty" json:"disable,omitempty" jsonschema:"oneof_type=string;boolean"`
SkipUpload string `yaml:"skip_upload,omitempty" json:"skip_upload,omitempty" jsonschema:"oneof_type=string;boolean"` SkipUpload string `yaml:"skip_upload,omitempty" json:"skip_upload,omitempty" jsonschema:"oneof_type=string;boolean"`
Prerelease string `yaml:"prerelease,omitempty" json:"prerelease,omitempty"` Prerelease string `yaml:"prerelease,omitempty" json:"prerelease,omitempty"`
MakeLatest string `yaml:"make_latest,omitempty" json:"make_latest,omitempty" jsonschema:"oneof_type=string;boolean"`
NameTemplate string `yaml:"name_template,omitempty" json:"name_template,omitempty"` NameTemplate string `yaml:"name_template,omitempty" json:"name_template,omitempty"`
IDs []string `yaml:"ids,omitempty" json:"ids,omitempty"` IDs []string `yaml:"ids,omitempty" json:"ids,omitempty"`
ExtraFiles []ExtraFile `yaml:"extra_files,omitempty" json:"extra_files,omitempty"` ExtraFiles []ExtraFile `yaml:"extra_files,omitempty" json:"extra_files,omitempty"`

View File

@ -75,6 +75,15 @@ release:
# Default is false. # Default is false.
prerelease: auto prerelease: auto
# If set to false, will NOT mark the release as "latest".
# This prevents it from being shown at the top of the release list,
# and from being returned when calling https://api.github.com/repos/OWNER/REPO/releases/latest.
#
# Available only for GitHub.
#
# Default is true.
make_latest: true
# What to do with the release notes in case there the release already exists. # What to do with the release notes in case there the release already exists.
# #
# Valid options are: # Valid options are: