1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-11 14:39:28 +02:00

feat: publishers.disable (#4239)

allows to disable a specific custom publisher based on a template, akin
to other pipes.

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2023-08-08 22:43:09 -03:00 committed by GitHub
parent acfc1b2274
commit c06ba3a94f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 5 deletions

View File

@ -350,6 +350,7 @@ publishers:
env:
- "FURY_TOKEN={{ .Env.FURY_TOKEN }}"
cmd: ./scripts/fury-upload.sh {{ .ArtifactName }}
disable: "{{ if .IsNightly }}true{{ end }}"
milestones:
- close: true

View File

@ -14,6 +14,7 @@ import (
"github.com/goreleaser/goreleaser/internal/extrafiles"
"github.com/goreleaser/goreleaser/internal/gio"
"github.com/goreleaser/goreleaser/internal/logext"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config"
@ -25,18 +26,30 @@ var passthroughEnvVars = []string{"HOME", "USER", "USERPROFILE", "TMPDIR", "TMP"
// Execute the given publisher
func Execute(ctx *context.Context, publishers []config.Publisher) error {
skips := pipe.SkipMemento{}
for _, p := range publishers {
log.WithField("name", p.Name).Debug("executing custom publisher")
err := executePublisher(ctx, p)
if err != nil && pipe.IsSkip(err) {
skips.Remember(err)
continue
}
if err != nil {
return err
}
}
return nil
return skips.Evaluate()
}
func executePublisher(ctx *context.Context, publisher config.Publisher) error {
disabled, err := tmpl.New(ctx).Bool(publisher.Disable)
if err != nil {
return err
}
if disabled {
return pipe.Skip("publisher is disabled")
}
log.Debugf("filtering %d artifacts", len(ctx.Artifacts.List()))
artifacts := filterArtifacts(ctx.Artifacts, publisher)

View File

@ -8,6 +8,7 @@ import (
"testing"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/testctx"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/stretchr/testify/require"
@ -113,8 +114,9 @@ func TestExecute(t *testing.T) {
"no filter",
[]config.Publisher{
{
Name: "test",
Cmd: MockCmd + " {{ .ArtifactName }}",
Name: "test",
Cmd: MockCmd + " {{ .ArtifactName }}",
Disable: "false",
Env: []string{
MarshalMockEnv(&MockData{
AnyOf: []MockCall{
@ -130,6 +132,30 @@ func TestExecute(t *testing.T) {
},
nil,
},
{
"disabled",
[]config.Publisher{
{
Name: "test",
Cmd: MockCmd + " {{ .ArtifactName }}",
Disable: "true",
Env: []string{},
},
},
pipe.ErrSkip{},
},
{
"disabled invalid tmpl",
[]config.Publisher{
{
Name: "test",
Cmd: MockCmd + " {{ .ArtifactName }}",
Disable: "{{ .NOPE }}",
Env: []string{},
},
},
fmt.Errorf(`template: tmpl:1:3: executing "tmpl" at <.NOPE>`),
},
{
"include checksum",
[]config.Publisher{
@ -324,6 +350,9 @@ func TestExecute(t *testing.T) {
{
"command error",
[]config.Publisher{
{
Disable: "true",
},
{
Name: "test",
IDs: []string{"debpkg"},
@ -355,7 +384,7 @@ func TestExecute(t *testing.T) {
return
}
require.Error(t, err)
require.True(t, strings.HasPrefix(err.Error(), tc.expectErr.Error()))
require.True(t, strings.HasPrefix(err.Error(), tc.expectErr.Error()), err.Error())
})
}
}

View File

@ -1121,6 +1121,7 @@ type Publisher struct {
Cmd string `yaml:"cmd,omitempty" json:"cmd,omitempty"`
Env []string `yaml:"env,omitempty" json:"env,omitempty"`
ExtraFiles []ExtraFile `yaml:"extra_files,omitempty" json:"extra_files,omitempty"`
Disable string `yaml:"disable,omitempty" json:"disable,omitempty" jsonschema:"oneof_type=string;boolean"`
}
// Source configuration.

View File

@ -121,6 +121,12 @@ publishers:
env:
- API_TOKEN=secret-token
# Whether to disable this particular upload configuration.
#
# Since: v1.20
# Templates: allowed
disable: "{{ if .IsNightly }}true{{ end }}"
# You can publish extra pre-existing files.
# The filename published will be the last part of the path (base).
# If another file with the same name exists, the last one found will be used.