mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-04 03:11:55 +02:00
feat: allow to template release.disable and releaser.skip_upload (#3710)
closes https://github.com/goreleaser/goreleaser/issues/3705 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
d386cbf3ce
commit
afc38b79a9
11
internal/pipe/env/env.go
vendored
11
internal/pipe/env/env.go
vendored
@ -114,8 +114,17 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func isSkipRelease(ctx *context.Context) bool {
|
||||
d, err := tmpl.New(ctx).Apply(ctx.Config.Release.Disable)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("could not execute release.disable template, will assume false")
|
||||
return false
|
||||
}
|
||||
return strings.ToLower(d) == "true"
|
||||
}
|
||||
|
||||
func checkErrors(ctx *context.Context, noTokens, noTokenErrs bool, gitlabTokenErr, githubTokenErr, giteaTokenErr error) error {
|
||||
if ctx.SkipTokenCheck || ctx.SkipPublish || ctx.Config.Release.Disable {
|
||||
if ctx.SkipTokenCheck || ctx.SkipPublish || isSkipRelease(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
47
internal/pipe/env/env_test.go
vendored
47
internal/pipe/env/env_test.go
vendored
@ -210,14 +210,49 @@ func TestInvalidEnvChecksSkipped(t *testing.T) {
|
||||
|
||||
func TestInvalidEnvReleaseDisabled(t *testing.T) {
|
||||
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{
|
||||
|
||||
t.Run("true", func(t *testing.T) {
|
||||
ctx := context.New(config.Project{
|
||||
Env: []string{},
|
||||
Release: config.Release{
|
||||
Disable: true,
|
||||
Disable: "true",
|
||||
},
|
||||
},
|
||||
}
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("tmpl true", func(t *testing.T) {
|
||||
ctx := context.New(config.Project{
|
||||
Env: []string{"FOO=true"},
|
||||
Release: config.Release{
|
||||
Disable: "{{ .Env.FOO }}",
|
||||
},
|
||||
})
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("tmpl false", func(t *testing.T) {
|
||||
ctx := context.New(config.Project{
|
||||
Env: []string{"FOO=true"},
|
||||
Release: config.Release{
|
||||
Disable: "{{ .Env.FOO }}-nope",
|
||||
},
|
||||
})
|
||||
require.EqualError(t, Pipe{}.Run(ctx), ErrMissingToken.Error())
|
||||
})
|
||||
|
||||
t.Run("tmpl error", func(t *testing.T) {
|
||||
ctx := context.New(config.Project{
|
||||
Release: config.Release{
|
||||
Disable: "{{ .Env.FOO }}",
|
||||
},
|
||||
})
|
||||
require.EqualError(t, Pipe{}.Run(ctx), ErrMissingToken.Error())
|
||||
})
|
||||
}
|
||||
|
||||
func TestInvalidEnvReleaseDisabledTmpl(t *testing.T) {
|
||||
require.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||
}
|
||||
|
||||
func TestLoadEnv(t *testing.T) {
|
||||
|
@ -14,7 +14,7 @@ func TestDescription(t *testing.T) {
|
||||
|
||||
func TestPublish(t *testing.T) {
|
||||
ctx := context.New(config.Project{})
|
||||
ctx.Config.Release.Disable = true
|
||||
ctx.Config.Release.Disable = "true"
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
for i := range ctx.Config.Dockers {
|
||||
ctx.Config.Dockers[i].SkipPush = "true"
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/caarlos0/log"
|
||||
@ -14,6 +15,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/git"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
)
|
||||
@ -25,8 +27,15 @@ var ErrMultipleReleases = errors.New("multiple releases are defined. Only one is
|
||||
// Pipe for github release.
|
||||
type Pipe struct{}
|
||||
|
||||
func (Pipe) String() string { return "scm releases" }
|
||||
func (Pipe) Skip(ctx *context.Context) bool { return ctx.Config.Release.Disable }
|
||||
func (Pipe) String() string { return "scm releases" }
|
||||
func (Pipe) Skip(ctx *context.Context) bool {
|
||||
d, err := tmpl.New(ctx).Apply(ctx.Config.Release.Disable)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("could not execute release.disable template, will assume false")
|
||||
return false
|
||||
}
|
||||
return strings.ToLower(d) == "true"
|
||||
}
|
||||
|
||||
// Default sets the pipe defaults.
|
||||
func (Pipe) Default(ctx *context.Context) error {
|
||||
@ -116,7 +125,11 @@ func doPublish(ctx *context.Context, client client.Client) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if ctx.Config.Release.SkipUpload {
|
||||
d, err := tmpl.New(ctx).Apply(ctx.Config.Release.SkipUpload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.ToLower(d) == "true" {
|
||||
return pipe.Skip("release.skip_upload is set")
|
||||
}
|
||||
|
||||
|
@ -520,7 +520,7 @@ func TestDefaultPipeDisabled(t *testing.T) {
|
||||
|
||||
ctx := context.New(config.Project{
|
||||
Release: config.Release{
|
||||
Disable: true,
|
||||
Disable: "true",
|
||||
},
|
||||
})
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
@ -606,16 +606,48 @@ func TestSkip(t *testing.T) {
|
||||
t.Run("skip", func(t *testing.T) {
|
||||
ctx := context.New(config.Project{
|
||||
Release: config.Release{
|
||||
Disable: true,
|
||||
Disable: "true",
|
||||
},
|
||||
})
|
||||
require.True(t, Pipe{}.Skip(ctx))
|
||||
})
|
||||
|
||||
t.Run("skip upload", func(t *testing.T) {
|
||||
t.Run("skip tmpl", func(t *testing.T) {
|
||||
ctx := context.New(config.Project{
|
||||
Env: []string{"FOO=true"},
|
||||
Release: config.Release{
|
||||
Disable: "{{ .Env.FOO }}",
|
||||
},
|
||||
})
|
||||
require.True(t, Pipe{}.Skip(ctx))
|
||||
})
|
||||
|
||||
t.Run("skip tmpl err", func(t *testing.T) {
|
||||
ctx := context.New(config.Project{
|
||||
Release: config.Release{
|
||||
SkipUpload: true,
|
||||
Disable: "{{ .Env.FOO }}",
|
||||
},
|
||||
})
|
||||
require.False(t, Pipe{}.Skip(ctx))
|
||||
})
|
||||
|
||||
t.Run("skip upload", func(t *testing.T) {
|
||||
ctx := context.New(config.Project{
|
||||
Env: []string{"FOO=true"},
|
||||
Release: config.Release{
|
||||
SkipUpload: "{{ .Env.FOO }}",
|
||||
},
|
||||
})
|
||||
client := &client.Mock{}
|
||||
testlib.AssertSkipped(t, doPublish(ctx, client))
|
||||
require.True(t, client.CreatedRelease)
|
||||
require.False(t, client.UploadedFile)
|
||||
})
|
||||
|
||||
t.Run("skip upload tmpl", func(t *testing.T) {
|
||||
ctx := context.New(config.Project{
|
||||
Release: config.Release{
|
||||
SkipUpload: "true",
|
||||
},
|
||||
})
|
||||
client := &client.Mock{}
|
||||
|
@ -142,7 +142,11 @@ func doPublish(ctx *context.Context, cl client.Client) error {
|
||||
if ctx.Config.Release.Draft {
|
||||
return pipe.Skip("release is marked as draft")
|
||||
}
|
||||
if ctx.Config.Release.Disable {
|
||||
d, err := tmpl.New(ctx).Apply(ctx.Config.Release.Disable)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.ToLower(d) == "true" {
|
||||
return pipe.Skip("release is disabled")
|
||||
}
|
||||
|
||||
|
@ -419,7 +419,7 @@ func Test_doRun(t *testing.T) {
|
||||
ctx := context.New(config.Project{
|
||||
ProjectName: "run-pipe",
|
||||
Release: config.Release{
|
||||
Disable: true,
|
||||
Disable: "true",
|
||||
},
|
||||
Scoop: config.Scoop{
|
||||
Bucket: config.RepoRef{
|
||||
|
@ -531,8 +531,8 @@ type Release struct {
|
||||
Draft bool `yaml:"draft,omitempty" json:"draft,omitempty"`
|
||||
ReplaceExistingDraft bool `yaml:"replace_existing_draft,omitempty" json:"replace_existing_draft,omitempty"`
|
||||
TargetCommitish string `yaml:"target_commitish,omitempty" json:"target_commitish,omitempty"`
|
||||
Disable bool `yaml:"disable,omitempty" json:"disable,omitempty"`
|
||||
SkipUpload bool `yaml:"skip_upload,omitempty" json:"skip_upload,omitempty"`
|
||||
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"`
|
||||
Prerelease string `yaml:"prerelease,omitempty" json:"prerelease,omitempty"`
|
||||
NameTemplate string `yaml:"name_template,omitempty" json:"name_template,omitempty"`
|
||||
IDs []string `yaml:"ids,omitempty" json:"ids,omitempty"`
|
||||
|
@ -25,6 +25,7 @@ release:
|
||||
|
||||
# If set to true, will not auto-publish the release.
|
||||
# Available only for GitHub and Gitea.
|
||||
#
|
||||
# Default is false.
|
||||
draft: true
|
||||
|
||||
@ -95,6 +96,7 @@ release:
|
||||
# URL, for instance, homebrew taps.
|
||||
#
|
||||
# Defaults to false.
|
||||
# Templateable since: v1.15.
|
||||
disable: true
|
||||
|
||||
# Set this to true if you want to disable just the artifact upload to the SCM.
|
||||
@ -103,6 +105,7 @@ release:
|
||||
#
|
||||
# Default: false.
|
||||
# Since: v1.11.
|
||||
# Templateable since: v1.15.
|
||||
skip_upload: true
|
||||
|
||||
# You can add extra pre-existing files to the release.
|
||||
|
Loading…
Reference in New Issue
Block a user