mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-05-31 23:19:45 +02:00
refactor: --skip=item (#4272)
Laying the ground work to allow skipping more pipes without adding new flags et al. --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
85c86d61cf
commit
622c426eb3
86
cmd/build.go
86
cmd/build.go
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -17,6 +18,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/middleware/logging"
|
||||
"github.com/goreleaser/goreleaser/internal/middleware/skip"
|
||||
"github.com/goreleaser/goreleaser/internal/pipeline"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"github.com/spf13/cobra"
|
||||
@ -28,21 +30,25 @@ type buildCmd struct {
|
||||
}
|
||||
|
||||
type buildOpts struct {
|
||||
config string
|
||||
ids []string
|
||||
snapshot bool
|
||||
skipValidate bool
|
||||
skipBefore bool
|
||||
skipPostHooks bool
|
||||
clean bool
|
||||
deprecated bool
|
||||
parallelism int
|
||||
timeout time.Duration
|
||||
singleTarget bool
|
||||
output string
|
||||
config string
|
||||
ids []string
|
||||
snapshot bool
|
||||
clean bool
|
||||
deprecated bool
|
||||
parallelism int
|
||||
timeout time.Duration
|
||||
singleTarget bool
|
||||
output string
|
||||
skips []string
|
||||
|
||||
// Deprecated: use clean instead.
|
||||
rmDist bool
|
||||
// Deprecated: use skip instead.
|
||||
skipValidate bool
|
||||
// Deprecated: use skip instead.
|
||||
skipBefore bool
|
||||
// Deprecated: use skip instead.
|
||||
skipPostHooks bool
|
||||
}
|
||||
|
||||
func newBuildCmd() *buildCmd {
|
||||
@ -88,7 +94,8 @@ When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`"
|
||||
_ = cmd.RegisterFlagCompletionFunc("timeout", cobra.NoFileCompletions)
|
||||
cmd.Flags().BoolVar(&root.opts.singleTarget, "single-target", false, "Builds only for current GOOS and GOARCH, regardless of what's set in the configuration file")
|
||||
cmd.Flags().StringArrayVar(&root.opts.ids, "id", nil, "Builds only the specified build ids")
|
||||
_ = cmd.RegisterFlagCompletionFunc("id", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
_ = cmd.RegisterFlagCompletionFunc("id", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
|
||||
// TODO: improve this
|
||||
cfg, err := loadConfig(root.opts.config)
|
||||
if err != nil {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
@ -105,6 +112,31 @@ When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`"
|
||||
_ = cmd.Flags().MarkHidden("rm-dist")
|
||||
_ = cmd.Flags().MarkHidden("deprecated")
|
||||
|
||||
for _, f := range []string{
|
||||
"post-hooks",
|
||||
"before",
|
||||
"validate",
|
||||
} {
|
||||
_ = cmd.Flags().MarkHidden("skip-" + f)
|
||||
_ = cmd.Flags().MarkDeprecated("skip-"+f, fmt.Sprintf("please use --skip=%s instead", f))
|
||||
}
|
||||
cmd.Flags().StringSliceVar(
|
||||
&root.opts.skips,
|
||||
"skip",
|
||||
nil,
|
||||
fmt.Sprintf("Skip the given options (valid options are %s)", skips.Build.String()),
|
||||
)
|
||||
_ = cmd.RegisterFlagCompletionFunc("skip", func(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
var result []string
|
||||
for _, k := range skips.Build {
|
||||
if strings.HasPrefix(string(k), strings.ToLower(toComplete)) {
|
||||
result = append(result, string(k))
|
||||
}
|
||||
}
|
||||
sort.Strings(result)
|
||||
return result, cobra.ShellCompDirectiveDefault
|
||||
})
|
||||
|
||||
root.cmd = cmd
|
||||
return root
|
||||
}
|
||||
@ -150,16 +182,34 @@ func setupBuildContext(ctx *context.Context, options buildOpts) error {
|
||||
}
|
||||
log.Debugf("parallelism: %v", ctx.Parallelism)
|
||||
ctx.Snapshot = options.snapshot
|
||||
ctx.SkipValidate = ctx.Snapshot || options.skipValidate
|
||||
ctx.SkipBefore = options.skipBefore
|
||||
ctx.SkipPostBuildHooks = options.skipPostHooks
|
||||
ctx.SkipTokenCheck = true
|
||||
ctx.Clean = options.clean || options.rmDist
|
||||
if err := skips.SetBuild(ctx, options.skips...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if options.skipValidate {
|
||||
skips.Set(ctx, skips.Validate)
|
||||
deprecate.NoticeCustom(ctx, "-skip", "--skip-validate was deprecated in favor of --skip=validate, check {{ .URL }} for more details")
|
||||
}
|
||||
if options.skipBefore {
|
||||
skips.Set(ctx, skips.Before)
|
||||
deprecate.NoticeCustom(ctx, "-skip", "--skip-before was deprecated in favor of --skip=before, check {{ .URL }} for more details")
|
||||
}
|
||||
if options.skipPostHooks {
|
||||
skips.Set(ctx, skips.PostBuildHooks)
|
||||
deprecate.NoticeCustom(ctx, "-skip", "--skip-post-hooks was deprecated in favor of --skip=post-hooks, check {{ .URL }} for more details")
|
||||
}
|
||||
|
||||
if options.rmDist {
|
||||
deprecate.NoticeCustom(ctx, "-rm-dist", "--rm-dist was deprecated in favor of --clean, check {{ .URL }} for more details")
|
||||
}
|
||||
|
||||
if ctx.Snapshot {
|
||||
skips.Set(ctx, skips.Validate)
|
||||
}
|
||||
|
||||
ctx.SkipTokenCheck = true
|
||||
ctx.Clean = options.clean || options.rmDist
|
||||
|
||||
if options.singleTarget {
|
||||
setupBuildSingleTarget(ctx)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/pipeline"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
@ -142,17 +143,27 @@ func TestBuildFlags(t *testing.T) {
|
||||
snapshot: true,
|
||||
})
|
||||
require.True(t, ctx.Snapshot)
|
||||
require.True(t, ctx.SkipValidate)
|
||||
requireAll(t, ctx, skips.Validate)
|
||||
require.True(t, ctx.SkipTokenCheck)
|
||||
})
|
||||
|
||||
t.Run("skips (old)", func(t *testing.T) {
|
||||
ctx := setup(buildOpts{
|
||||
skipValidate: true,
|
||||
skipPostHooks: true,
|
||||
})
|
||||
requireAll(t, ctx, skips.Validate, skips.PostBuildHooks)
|
||||
require.True(t, ctx.SkipTokenCheck)
|
||||
})
|
||||
|
||||
t.Run("skips", func(t *testing.T) {
|
||||
ctx := setup(buildOpts{
|
||||
skipValidate: true,
|
||||
skipPostHooks: true,
|
||||
skips: []string{
|
||||
string(skips.Validate),
|
||||
string(skips.PostBuildHooks),
|
||||
},
|
||||
})
|
||||
require.True(t, ctx.SkipValidate)
|
||||
require.True(t, ctx.SkipPostBuildHooks)
|
||||
requireAll(t, ctx, skips.Validate, skips.PostBuildHooks)
|
||||
require.True(t, ctx.SkipTokenCheck)
|
||||
})
|
||||
|
||||
|
16
cmd/helper_test.go
Normal file
16
cmd/helper_test.go
Normal file
@ -0,0 +1,16 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func requireAll(tb testing.TB, ctx *context.Context, keys ...skips.Key) {
|
||||
tb.Helper()
|
||||
for _, key := range keys {
|
||||
require.True(tb, ctx.Skips[string(key)], "expected %q to be true, but was false", key)
|
||||
}
|
||||
}
|
156
cmd/release.go
156
cmd/release.go
@ -1,7 +1,10 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/caarlos0/ctrlc"
|
||||
@ -12,6 +15,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/middleware/skip"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe/git"
|
||||
"github.com/goreleaser/goreleaser/internal/pipeline"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@ -22,31 +26,40 @@ type releaseCmd struct {
|
||||
}
|
||||
|
||||
type releaseOpts struct {
|
||||
config string
|
||||
releaseNotesFile string
|
||||
releaseNotesTmpl string
|
||||
releaseHeaderFile string
|
||||
releaseHeaderTmpl string
|
||||
releaseFooterFile string
|
||||
releaseFooterTmpl string
|
||||
autoSnapshot bool
|
||||
snapshot bool
|
||||
failFast bool
|
||||
skipPublish bool
|
||||
skipSign bool
|
||||
skipValidate bool
|
||||
skipAnnounce bool
|
||||
skipSBOMCataloging bool
|
||||
skipDocker bool
|
||||
skipKo bool
|
||||
skipBefore bool
|
||||
clean bool
|
||||
deprecated bool
|
||||
parallelism int
|
||||
timeout time.Duration
|
||||
config string
|
||||
releaseNotesFile string
|
||||
releaseNotesTmpl string
|
||||
releaseHeaderFile string
|
||||
releaseHeaderTmpl string
|
||||
releaseFooterFile string
|
||||
releaseFooterTmpl string
|
||||
autoSnapshot bool
|
||||
snapshot bool
|
||||
failFast bool
|
||||
clean bool
|
||||
deprecated bool
|
||||
parallelism int
|
||||
timeout time.Duration
|
||||
skips []string
|
||||
|
||||
// Deprecated: use clean instead.
|
||||
rmDist bool
|
||||
// Deprecated: use skips instead.
|
||||
skipPublish bool
|
||||
// Deprecated: use skips instead.
|
||||
skipSign bool
|
||||
// Deprecated: use skips instead.
|
||||
skipValidate bool
|
||||
// Deprecated: use skips instead.
|
||||
skipAnnounce bool
|
||||
// Deprecated: use skips instead.
|
||||
skipSBOMCataloging bool
|
||||
// Deprecated: use skips instead.
|
||||
skipDocker bool
|
||||
// Deprecated: use skips instead.
|
||||
skipKo bool
|
||||
// Deprecated: use skips instead.
|
||||
skipBefore bool
|
||||
}
|
||||
|
||||
func newReleaseCmd() *releaseCmd {
|
||||
@ -60,7 +73,7 @@ func newReleaseCmd() *releaseCmd {
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
RunE: timedRunE("release", func(cmd *cobra.Command, args []string) error {
|
||||
RunE: timedRunE("release", func(_ *cobra.Command, _ []string) error {
|
||||
ctx, err := releaseProject(root.opts)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -85,10 +98,10 @@ func newReleaseCmd() *releaseCmd {
|
||||
cmd.Flags().StringVar(&root.opts.releaseFooterTmpl, "release-footer-tmpl", "", "Load custom release notes footer from a templated markdown file (overrides --release-footer)")
|
||||
_ = cmd.MarkFlagFilename("release-footer-tmpl", "md", "mkd", "markdown")
|
||||
cmd.Flags().BoolVar(&root.opts.autoSnapshot, "auto-snapshot", false, "Automatically sets --snapshot if the repository is dirty")
|
||||
cmd.Flags().BoolVar(&root.opts.snapshot, "snapshot", false, "Generate an unversioned snapshot release, skipping all validations and without publishing any artifacts (implies --skip-publish, --skip-announce and --skip-validate)")
|
||||
cmd.Flags().BoolVar(&root.opts.snapshot, "snapshot", false, "Generate an unversioned snapshot release, skipping all validations and without publishing any artifacts (implies --skip=announce,publish,validate)")
|
||||
cmd.Flags().BoolVar(&root.opts.failFast, "fail-fast", false, "Whether to abort the release publishing on the first error")
|
||||
cmd.Flags().BoolVar(&root.opts.skipPublish, "skip-publish", false, "Skips publishing artifacts (implies --skip-announce)")
|
||||
cmd.Flags().BoolVar(&root.opts.skipAnnounce, "skip-announce", false, "Skips announcing releases (implies --skip-validate)")
|
||||
cmd.Flags().BoolVar(&root.opts.skipPublish, "skip-publish", false, "Skips publishing artifacts (implies --skip=announce)")
|
||||
cmd.Flags().BoolVar(&root.opts.skipAnnounce, "skip-announce", false, "Skips announcing releases (implies --skip=validate)")
|
||||
cmd.Flags().BoolVar(&root.opts.skipSign, "skip-sign", false, "Skips signing artifacts")
|
||||
cmd.Flags().BoolVar(&root.opts.skipSBOMCataloging, "skip-sbom", false, "Skips cataloging artifacts")
|
||||
cmd.Flags().BoolVar(&root.opts.skipDocker, "skip-docker", false, "Skips Docker Images/Manifests builds")
|
||||
@ -105,6 +118,35 @@ func newReleaseCmd() *releaseCmd {
|
||||
_ = cmd.Flags().MarkHidden("deprecated")
|
||||
_ = cmd.Flags().MarkHidden("rm-dist")
|
||||
_ = cmd.Flags().MarkDeprecated("rm-dist", "please use --clean instead")
|
||||
for _, f := range []string{
|
||||
"publish",
|
||||
"announce",
|
||||
"sign",
|
||||
"sbom",
|
||||
"docker",
|
||||
"ko",
|
||||
"before",
|
||||
"validate",
|
||||
} {
|
||||
_ = cmd.Flags().MarkHidden("skip-" + f)
|
||||
_ = cmd.Flags().MarkDeprecated("skip"+f, fmt.Sprintf("please use --skip=%s instead", f))
|
||||
}
|
||||
cmd.Flags().StringSliceVar(
|
||||
&root.opts.skips,
|
||||
"skip",
|
||||
nil,
|
||||
fmt.Sprintf("Skip the given options (valid options are %s)", skips.Release.String()),
|
||||
)
|
||||
_ = cmd.RegisterFlagCompletionFunc("skip", func(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
var result []string
|
||||
for _, k := range skips.Release {
|
||||
if strings.HasPrefix(string(k), strings.ToLower(toComplete)) {
|
||||
result = append(result, string(k))
|
||||
}
|
||||
}
|
||||
sort.Strings(result)
|
||||
return result, cobra.ShellCompDirectiveDefault
|
||||
})
|
||||
|
||||
root.cmd = cmd
|
||||
return root
|
||||
@ -117,7 +159,9 @@ func releaseProject(options releaseOpts) (*context.Context, error) {
|
||||
}
|
||||
ctx, cancel := context.NewWithTimeout(cfg, options.timeout)
|
||||
defer cancel()
|
||||
setupReleaseContext(ctx, options)
|
||||
if err := setupReleaseContext(ctx, options); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ctx, ctrlc.Default.Run(ctx, func() error {
|
||||
for _, pipe := range pipeline.Pipeline {
|
||||
if err := skip.Maybe(
|
||||
@ -134,7 +178,7 @@ func releaseProject(options releaseOpts) (*context.Context, error) {
|
||||
})
|
||||
}
|
||||
|
||||
func setupReleaseContext(ctx *context.Context, options releaseOpts) {
|
||||
func setupReleaseContext(ctx *context.Context, options releaseOpts) error {
|
||||
ctx.Deprecated = options.deprecated // test only
|
||||
ctx.Parallelism = runtime.GOMAXPROCS(0)
|
||||
if options.parallelism > 0 {
|
||||
@ -149,21 +193,59 @@ func setupReleaseContext(ctx *context.Context, options releaseOpts) {
|
||||
ctx.ReleaseFooterTmpl = options.releaseFooterTmpl
|
||||
ctx.Snapshot = options.snapshot
|
||||
ctx.FailFast = options.failFast
|
||||
ctx.Clean = options.clean || options.rmDist
|
||||
if options.autoSnapshot && git.CheckDirty(ctx) != nil {
|
||||
log.Info("git repository is dirty and --auto-snapshot is set, implying --snapshot")
|
||||
ctx.Snapshot = true
|
||||
}
|
||||
ctx.SkipPublish = ctx.Snapshot || options.skipPublish
|
||||
ctx.SkipAnnounce = ctx.Snapshot || options.skipPublish || options.skipAnnounce
|
||||
ctx.SkipValidate = ctx.Snapshot || options.skipValidate
|
||||
ctx.SkipSign = options.skipSign
|
||||
ctx.SkipSBOMCataloging = options.skipSBOMCataloging
|
||||
ctx.SkipDocker = options.skipDocker
|
||||
ctx.SkipKo = options.skipKo
|
||||
ctx.SkipBefore = options.skipBefore
|
||||
ctx.Clean = options.clean || options.rmDist
|
||||
|
||||
if err := skips.SetRelease(ctx, options.skips...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// wire deprecated options
|
||||
// XXX: remove soon
|
||||
if options.skipPublish {
|
||||
skips.Set(ctx, skips.Publish)
|
||||
deprecate.NoticeCustom(ctx, "-skip", "--skip-publish was deprecated in favor of --skip=publish, check {{ .URL }} for more details")
|
||||
}
|
||||
if options.skipSign {
|
||||
skips.Set(ctx, skips.Sign)
|
||||
deprecate.NoticeCustom(ctx, "-skip", "--skip-sign was deprecated in favor of --skip=sign, check {{ .URL }} for more details")
|
||||
}
|
||||
if options.skipValidate {
|
||||
skips.Set(ctx, skips.Validate)
|
||||
deprecate.NoticeCustom(ctx, "-skip", "--skip-validate was deprecated in favor of --skip=validate, check {{ .URL }} for more details")
|
||||
}
|
||||
if options.skipAnnounce {
|
||||
skips.Set(ctx, skips.Announce)
|
||||
deprecate.NoticeCustom(ctx, "-skip", "--skip-announce was deprecated in favor of --skip=announce, check {{ .URL }} for more details")
|
||||
}
|
||||
if options.skipSBOMCataloging {
|
||||
skips.Set(ctx, skips.SBOM)
|
||||
deprecate.NoticeCustom(ctx, "-skip", "--skip-sbom was deprecated in favor of --skip=sbom, check {{ .URL }} for more details")
|
||||
}
|
||||
if options.skipDocker {
|
||||
skips.Set(ctx, skips.Docker)
|
||||
deprecate.NoticeCustom(ctx, "-skip", "--skip-docker was deprecated in favor of --skip=docker, check {{ .URL }} for more details")
|
||||
}
|
||||
if options.skipKo {
|
||||
skips.Set(ctx, skips.Ko)
|
||||
deprecate.NoticeCustom(ctx, "-skip", "--skip-ko was deprecated in favor of --skip=ko, check {{ .URL }} for more details")
|
||||
}
|
||||
if options.skipBefore {
|
||||
skips.Set(ctx, skips.Before)
|
||||
deprecate.NoticeCustom(ctx, "-skip", "--skip-before was deprecated in favor of --skip=before, check {{ .URL }} for more details")
|
||||
}
|
||||
if options.rmDist {
|
||||
deprecate.NoticeCustom(ctx, "-rm-dist", "--rm-dist was deprecated in favor of --clean, check {{ .URL }} for more details")
|
||||
}
|
||||
|
||||
if ctx.Snapshot {
|
||||
skips.Set(ctx, skips.Publish, skips.Announce, skips.Validate)
|
||||
}
|
||||
if skips.Any(ctx, skips.Publish) {
|
||||
skips.Set(ctx, skips.Announce)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -66,21 +67,29 @@ func TestReleaseFlags(t *testing.T) {
|
||||
snapshot: true,
|
||||
})
|
||||
require.True(t, ctx.Snapshot)
|
||||
require.True(t, ctx.SkipPublish)
|
||||
require.True(t, ctx.SkipValidate)
|
||||
require.True(t, ctx.SkipAnnounce)
|
||||
requireAll(t, ctx, skips.Publish, skips.Validate, skips.Announce)
|
||||
})
|
||||
|
||||
t.Run("skips", func(t *testing.T) {
|
||||
t.Run("skips (old)", func(t *testing.T) {
|
||||
ctx := setup(t, releaseOpts{
|
||||
skipPublish: true,
|
||||
skipSign: true,
|
||||
skipValidate: true,
|
||||
})
|
||||
require.True(t, ctx.SkipSign)
|
||||
require.True(t, ctx.SkipPublish)
|
||||
require.True(t, ctx.SkipValidate)
|
||||
require.True(t, ctx.SkipAnnounce)
|
||||
|
||||
requireAll(t, ctx, skips.Sign, skips.Publish, skips.Validate, skips.Announce)
|
||||
})
|
||||
|
||||
t.Run("skips", func(t *testing.T) {
|
||||
ctx := setup(t, releaseOpts{
|
||||
skips: []string{
|
||||
string(skips.Publish),
|
||||
string(skips.Sign),
|
||||
string(skips.Validate),
|
||||
},
|
||||
})
|
||||
|
||||
requireAll(t, ctx, skips.Sign, skips.Publish, skips.Validate, skips.Announce)
|
||||
})
|
||||
|
||||
t.Run("parallelism", func(t *testing.T) {
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/pipe/telegram"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe/twitter"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe/webhook"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
)
|
||||
@ -52,7 +53,7 @@ type Pipe struct{}
|
||||
func (Pipe) String() string { return "announcing" }
|
||||
|
||||
func (Pipe) Skip(ctx *context.Context) (bool, error) {
|
||||
if ctx.SkipAnnounce {
|
||||
if skips.Any(ctx, skips.Announce) {
|
||||
return true, nil
|
||||
}
|
||||
return tmpl.New(ctx).Bool(ctx.Config.Announce.Skip)
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
@ -40,7 +41,7 @@ func TestAnnounceAllDisabled(t *testing.T) {
|
||||
|
||||
func TestSkip(t *testing.T) {
|
||||
t.Run("skip", func(t *testing.T) {
|
||||
ctx := testctx.New(testctx.SkipAnnounce)
|
||||
ctx := testctx.New(testctx.Skip(skips.Announce))
|
||||
b, err := Pipe{}.Skip(ctx)
|
||||
require.NoError(t, err)
|
||||
require.True(t, b)
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/caarlos0/log"
|
||||
"github.com/goreleaser/goreleaser/internal/gio"
|
||||
"github.com/goreleaser/goreleaser/internal/logext"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
)
|
||||
@ -19,8 +20,9 @@ import (
|
||||
type Pipe struct{}
|
||||
|
||||
func (Pipe) String() string { return "running before hooks" }
|
||||
|
||||
func (Pipe) Skip(ctx *context.Context) bool {
|
||||
return len(ctx.Config.Before.Hooks) == 0 || ctx.SkipBefore
|
||||
return len(ctx.Config.Before.Hooks) == 0 || skips.Any(ctx, skips.Before)
|
||||
}
|
||||
|
||||
// Run executes the hooks.
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/caarlos0/log"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
@ -103,8 +104,7 @@ func TestSkip(t *testing.T) {
|
||||
Before: config.Before{
|
||||
Hooks: []string{""},
|
||||
},
|
||||
})
|
||||
ctx.SkipBefore = true
|
||||
}, testctx.Skip(skips.Before))
|
||||
require.True(t, Pipe{}.Skip(ctx))
|
||||
})
|
||||
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/ids"
|
||||
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
||||
"github.com/goreleaser/goreleaser/internal/shell"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
builders "github.com/goreleaser/goreleaser/pkg/build"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
@ -102,7 +103,7 @@ func runPipeOnBuild(ctx *context.Context, g semerrgroup.Group, build config.Buil
|
||||
if err := doBuild(ctx, build, *opts); err != nil {
|
||||
return err
|
||||
}
|
||||
if !ctx.SkipPostBuildHooks {
|
||||
if !skips.Any(ctx, skips.PostBuildHooks) {
|
||||
if err := runHook(ctx, *opts, build.Env, build.Hooks.Post); err != nil {
|
||||
return fmt.Errorf("post hook failed: %w", err)
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/ids"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
@ -31,8 +32,11 @@ const (
|
||||
// Pipe for docker.
|
||||
type Pipe struct{}
|
||||
|
||||
func (Pipe) String() string { return "docker images" }
|
||||
func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Dockers) == 0 || ctx.SkipDocker }
|
||||
func (Pipe) String() string { return "docker images" }
|
||||
|
||||
func (Pipe) Skip(ctx *context.Context) bool {
|
||||
return len(ctx.Config.Dockers) == 0 || skips.Any(ctx, skips.Docker)
|
||||
}
|
||||
|
||||
func (Pipe) Dependencies(ctx *context.Context) []string {
|
||||
var cmds []string
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
@ -1343,8 +1344,7 @@ func TestSkip(t *testing.T) {
|
||||
t.Run("skip docker", func(t *testing.T) {
|
||||
ctx := testctx.NewWithCfg(config.Project{
|
||||
Dockers: []config.Docker{{}},
|
||||
})
|
||||
ctx.SkipDocker = true
|
||||
}, testctx.Skip(skips.Docker))
|
||||
require.True(t, Pipe{}.Skip(ctx))
|
||||
})
|
||||
|
||||
@ -1364,7 +1364,7 @@ func TestSkip(t *testing.T) {
|
||||
t.Run("skip docker", func(t *testing.T) {
|
||||
ctx := testctx.NewWithCfg(config.Project{
|
||||
DockerManifests: []config.DockerManifest{{}},
|
||||
}, testctx.SkipDocker)
|
||||
}, testctx.Skip(skips.Docker))
|
||||
require.True(t, ManifestPipe{}.Skip(ctx))
|
||||
})
|
||||
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/ids"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
@ -20,8 +21,9 @@ import (
|
||||
type ManifestPipe struct{}
|
||||
|
||||
func (ManifestPipe) String() string { return "docker manifests" }
|
||||
|
||||
func (ManifestPipe) Skip(ctx *context.Context) bool {
|
||||
return len(ctx.Config.DockerManifests) == 0 || ctx.SkipDocker
|
||||
return len(ctx.Config.DockerManifests) == 0 || skips.Any(ctx, skips.Docker)
|
||||
}
|
||||
|
||||
func (ManifestPipe) Dependencies(ctx *context.Context) []string {
|
||||
|
3
internal/pipe/env/env.go
vendored
3
internal/pipe/env/env.go
vendored
@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/caarlos0/log"
|
||||
"github.com/goreleaser/goreleaser/internal/logext"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
@ -132,7 +133,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
func checkErrors(ctx *context.Context, noTokens, noTokenErrs bool, gitlabTokenErr, githubTokenErr, giteaTokenErr error) error {
|
||||
if ctx.SkipTokenCheck || ctx.SkipPublish {
|
||||
if ctx.SkipTokenCheck || skips.Any(ctx, skips.Publish) {
|
||||
return nil
|
||||
}
|
||||
if b, err := tmpl.New(ctx).Bool(ctx.Config.Release.Disable); err != nil || b {
|
||||
|
3
internal/pipe/env/env_test.go
vendored
3
internal/pipe/env/env_test.go
vendored
@ -6,6 +6,7 @@ import (
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
@ -220,7 +221,7 @@ func TestEmptyGiteaEnvFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInvalidEnvChecksSkipped(t *testing.T) {
|
||||
ctx := testctx.New(testctx.SkipPublish)
|
||||
ctx := testctx.New(testctx.Skip(skips.Publish))
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"github.com/caarlos0/log"
|
||||
"github.com/goreleaser/goreleaser/internal/git"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
)
|
||||
@ -191,7 +192,7 @@ func validate(ctx *context.Context) error {
|
||||
if ctx.Snapshot {
|
||||
return pipe.ErrSnapshotEnabled
|
||||
}
|
||||
if ctx.SkipValidate {
|
||||
if skips.Any(ctx, skips.Validate) {
|
||||
return pipe.ErrSkipValidateEnabled
|
||||
}
|
||||
if _, err := os.Stat(".git/shallow"); err == nil {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
@ -112,7 +113,7 @@ func TestDirty(t *testing.T) {
|
||||
require.Contains(t, err.Error(), "git is in a dirty state")
|
||||
})
|
||||
t.Run("skip validate is set", func(t *testing.T) {
|
||||
ctx := testctx.New(testctx.SkipValidate)
|
||||
ctx := testctx.New(testctx.Skip(skips.Validate))
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
require.True(t, ctx.Git.Dirty)
|
||||
})
|
||||
@ -162,7 +163,7 @@ func TestShallowClone(t *testing.T) {
|
||||
require.NoError(t, Pipe{}.Run(testctx.New()))
|
||||
})
|
||||
t.Run("skip validate is set", func(t *testing.T) {
|
||||
ctx := testctx.New(testctx.SkipValidate)
|
||||
ctx := testctx.New(testctx.Skip(skips.Validate))
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
t.Run("snapshot", func(t *testing.T) {
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/ids"
|
||||
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
@ -55,7 +56,7 @@ type Pipe struct{}
|
||||
|
||||
func (Pipe) String() string { return "ko" }
|
||||
func (Pipe) Skip(ctx *context.Context) bool {
|
||||
return ctx.SkipKo || len(ctx.Config.Kos) == 0
|
||||
return skips.Any(ctx, skips.Ko) || len(ctx.Config.Kos) == 0
|
||||
}
|
||||
|
||||
// Default sets the Pipes defaults.
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/google/go-containerregistry/pkg/name"
|
||||
"github.com/google/go-containerregistry/pkg/v1/remote"
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
@ -88,8 +89,7 @@ func TestSkip(t *testing.T) {
|
||||
t.Run("skip ko set", func(t *testing.T) {
|
||||
ctx := testctx.NewWithCfg(config.Project{
|
||||
Kos: []config.Ko{{}},
|
||||
})
|
||||
ctx.SkipKo = true
|
||||
}, testctx.Skip(skips.Ko))
|
||||
require.True(t, Pipe{}.Skip(ctx))
|
||||
})
|
||||
t.Run("skip no kos", func(t *testing.T) {
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/ids"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
@ -364,7 +365,7 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar
|
||||
},
|
||||
}
|
||||
|
||||
if ctx.SkipSign {
|
||||
if skips.Any(ctx, skips.Sign) {
|
||||
info.APK.Signature = nfpm.APKSignature{}
|
||||
info.RPM.Signature = nfpm.RPMSignature{}
|
||||
info.Deb.Signature = nfpm.DebSignature{}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
@ -1327,7 +1328,7 @@ func TestSkipSign(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("skip sign set", func(t *testing.T) {
|
||||
ctx.SkipSign = true
|
||||
skips.Set(ctx, skips.Sign)
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/pipe/snapcraft"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe/upload"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe/winget"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
)
|
||||
|
||||
@ -69,7 +70,7 @@ type Pipe struct {
|
||||
}
|
||||
|
||||
func (Pipe) String() string { return "publishing" }
|
||||
func (Pipe) Skip(ctx *context.Context) bool { return ctx.SkipPublish }
|
||||
func (Pipe) Skip(ctx *context.Context) bool { return skips.Any(ctx, skips.Publish) }
|
||||
|
||||
func (p Pipe) Run(ctx *context.Context) error {
|
||||
memo := errhandler.Memo{}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
@ -72,7 +73,7 @@ func TestPublishError(t *testing.T) {
|
||||
|
||||
func TestSkip(t *testing.T) {
|
||||
t.Run("skip", func(t *testing.T) {
|
||||
ctx := testctx.New(testctx.SkipPublish)
|
||||
ctx := testctx.New(testctx.Skip(skips.Publish))
|
||||
require.True(t, Pipe{}.Skip(ctx))
|
||||
})
|
||||
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/ids"
|
||||
"github.com/goreleaser/goreleaser/internal/logext"
|
||||
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
@ -28,7 +29,7 @@ type Pipe struct{}
|
||||
|
||||
func (Pipe) String() string { return "cataloging artifacts" }
|
||||
func (Pipe) Skip(ctx *context.Context) bool {
|
||||
return ctx.SkipSBOMCataloging || len(ctx.Config.SBOMs) == 0
|
||||
return skips.Any(ctx, skips.SBOM) || len(ctx.Config.SBOMs) == 0
|
||||
}
|
||||
|
||||
func (Pipe) Dependencies(ctx *context.Context) []string {
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
@ -199,8 +200,7 @@ func TestSkipCataloging(t *testing.T) {
|
||||
Artifacts: "all",
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.SkipSBOMCataloging = true
|
||||
}, testctx.Skip(skips.SBOM))
|
||||
require.True(t, Pipe{}.Skip(ctx))
|
||||
})
|
||||
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/logext"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
@ -25,8 +26,11 @@ import (
|
||||
// Pipe that signs common artifacts.
|
||||
type Pipe struct{}
|
||||
|
||||
func (Pipe) String() string { return "signing artifacts" }
|
||||
func (Pipe) Skip(ctx *context.Context) bool { return ctx.SkipSign || len(ctx.Config.Signs) == 0 }
|
||||
func (Pipe) String() string { return "signing artifacts" }
|
||||
|
||||
func (Pipe) Skip(ctx *context.Context) bool {
|
||||
return skips.Any(ctx, skips.Sign) || len(ctx.Config.Signs) == 0
|
||||
}
|
||||
|
||||
func (Pipe) Dependencies(ctx *context.Context) []string {
|
||||
var cmds []string
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/ids"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
)
|
||||
|
||||
@ -16,7 +17,7 @@ type DockerPipe struct{}
|
||||
func (DockerPipe) String() string { return "signing docker images" }
|
||||
|
||||
func (DockerPipe) Skip(ctx *context.Context) bool {
|
||||
return ctx.SkipSign || len(ctx.Config.DockerSigns) == 0
|
||||
return skips.Any(ctx, skips.Sign) || len(ctx.Config.DockerSigns) == 0
|
||||
}
|
||||
|
||||
func (DockerPipe) Dependencies(ctx *context.Context) []string {
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/gio"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
@ -215,7 +216,7 @@ func TestDockerSkip(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("skip sign", func(t *testing.T) {
|
||||
ctx := testctx.New(testctx.SkipSign)
|
||||
ctx := testctx.New(testctx.Skip(skips.Sign))
|
||||
require.True(t, DockerPipe{}.Skip(ctx))
|
||||
})
|
||||
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/git"
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
@ -760,7 +761,7 @@ func TestSkip(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("skip sign", func(t *testing.T) {
|
||||
ctx := testctx.New(testctx.SkipSign)
|
||||
ctx := testctx.New(testctx.Skip(skips.Sign))
|
||||
require.True(t, Pipe{}.Skip(ctx))
|
||||
})
|
||||
|
||||
|
83
internal/skips/skips.go
Normal file
83
internal/skips/skips.go
Normal file
@ -0,0 +1,83 @@
|
||||
package skips
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
type Key string
|
||||
|
||||
const (
|
||||
PostBuildHooks Key = "post-hooks"
|
||||
Publish Key = "publish"
|
||||
Announce Key = "announce"
|
||||
Sign Key = "sign"
|
||||
Validate Key = "validate"
|
||||
SBOM Key = "sbom"
|
||||
Ko Key = "ko"
|
||||
Docker Key = "docker"
|
||||
Before Key = "before"
|
||||
)
|
||||
|
||||
func Any(ctx *context.Context, keys ...Key) bool {
|
||||
for _, key := range keys {
|
||||
if ctx.Skips[string(key)] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func Set(ctx *context.Context, keys ...Key) {
|
||||
for _, key := range keys {
|
||||
ctx.Skips[string(key)] = true
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
SetRelease = set(Release)
|
||||
SetBuild = set(Build)
|
||||
)
|
||||
|
||||
func set(allowed Keys) func(ctx *context.Context, keys ...string) error {
|
||||
return func(ctx *context.Context, keys ...string) error {
|
||||
for _, key := range keys {
|
||||
if !slices.Contains(allowed, Key(key)) {
|
||||
return fmt.Errorf("--skip=%s is not allowed. Valid options for skip are [%s]", key, allowed)
|
||||
}
|
||||
ctx.Skips[key] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
type Keys []Key
|
||||
|
||||
func (keys Keys) String() string {
|
||||
ss := make([]string, len(keys))
|
||||
for i, key := range keys {
|
||||
ss[i] = string(key)
|
||||
}
|
||||
slices.Sort(ss)
|
||||
return strings.Join(ss, ", ")
|
||||
}
|
||||
|
||||
var Release = Keys{
|
||||
Publish,
|
||||
Announce,
|
||||
Sign,
|
||||
Validate,
|
||||
SBOM,
|
||||
Ko,
|
||||
Docker,
|
||||
Before,
|
||||
}
|
||||
|
||||
var Build = Keys{
|
||||
PostBuildHooks,
|
||||
Validate,
|
||||
Before,
|
||||
}
|
@ -4,6 +4,7 @@ package testctx
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
)
|
||||
@ -105,30 +106,16 @@ func WithFakeRuntime(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func SkipPublish(ctx *context.Context) {
|
||||
ctx.SkipPublish = true
|
||||
}
|
||||
|
||||
func SkipAnnounce(ctx *context.Context) {
|
||||
ctx.SkipAnnounce = true
|
||||
}
|
||||
|
||||
func SkipDocker(ctx *context.Context) {
|
||||
ctx.SkipDocker = true
|
||||
}
|
||||
|
||||
func SkipValidate(ctx *context.Context) {
|
||||
ctx.SkipValidate = true
|
||||
func Skip(keys ...skips.Key) Opt {
|
||||
return func(ctx *context.Context) {
|
||||
skips.Set(ctx, keys...)
|
||||
}
|
||||
}
|
||||
|
||||
func Snapshot(ctx *context.Context) {
|
||||
ctx.Snapshot = true
|
||||
}
|
||||
|
||||
func SkipSign(ctx *context.Context) {
|
||||
ctx.SkipSign = true
|
||||
}
|
||||
|
||||
func NewWithCfg(c config.Project, opts ...Opt) *context.Context {
|
||||
ctx := context.New(c)
|
||||
for _, opt := range opts {
|
||||
|
@ -72,41 +72,33 @@ const (
|
||||
// Context carries along some data through the pipes.
|
||||
type Context struct {
|
||||
stdctx.Context
|
||||
Config config.Project
|
||||
Env Env
|
||||
SkipTokenCheck bool
|
||||
Token string
|
||||
TokenType TokenType
|
||||
Git GitInfo
|
||||
Date time.Time
|
||||
Artifacts *artifact.Artifacts
|
||||
ReleaseURL string
|
||||
ReleaseNotes string
|
||||
ReleaseNotesFile string
|
||||
ReleaseNotesTmpl string
|
||||
ReleaseHeaderFile string
|
||||
ReleaseHeaderTmpl string
|
||||
ReleaseFooterFile string
|
||||
ReleaseFooterTmpl string
|
||||
Version string
|
||||
ModulePath string
|
||||
Snapshot bool
|
||||
FailFast bool
|
||||
SkipPostBuildHooks bool
|
||||
SkipPublish bool
|
||||
SkipAnnounce bool
|
||||
SkipSign bool
|
||||
SkipValidate bool
|
||||
SkipSBOMCataloging bool
|
||||
SkipKo bool
|
||||
SkipDocker bool
|
||||
SkipBefore bool
|
||||
Clean bool
|
||||
PreRelease bool
|
||||
Deprecated bool
|
||||
Parallelism int
|
||||
Semver Semver
|
||||
Runtime Runtime
|
||||
Config config.Project
|
||||
Env Env
|
||||
Token string
|
||||
TokenType TokenType
|
||||
Git GitInfo
|
||||
Date time.Time
|
||||
Artifacts *artifact.Artifacts
|
||||
ReleaseURL string
|
||||
ReleaseNotes string
|
||||
ReleaseNotesFile string
|
||||
ReleaseNotesTmpl string
|
||||
ReleaseHeaderFile string
|
||||
ReleaseHeaderTmpl string
|
||||
ReleaseFooterFile string
|
||||
ReleaseFooterTmpl string
|
||||
Version string
|
||||
ModulePath string
|
||||
Snapshot bool
|
||||
FailFast bool
|
||||
SkipTokenCheck bool
|
||||
Clean bool
|
||||
PreRelease bool
|
||||
Deprecated bool
|
||||
Parallelism int
|
||||
Semver Semver
|
||||
Runtime Runtime
|
||||
Skips map[string]bool
|
||||
}
|
||||
|
||||
type Runtime struct {
|
||||
@ -142,6 +134,7 @@ func Wrap(ctx stdctx.Context, config config.Project) *Context {
|
||||
Parallelism: 4,
|
||||
Artifacts: artifact.New(),
|
||||
Date: time.Now(),
|
||||
Skips: map[string]bool{},
|
||||
Runtime: Runtime{
|
||||
Goos: runtime.GOOS,
|
||||
Goarch: runtime.GOARCH,
|
||||
|
@ -37,6 +37,52 @@ Description.
|
||||
|
||||
-->
|
||||
|
||||
### `--skip`
|
||||
|
||||
> since 2023-09-14
|
||||
|
||||
The following `goreleaser release` flags were deprecated:
|
||||
|
||||
- `--skip-announce`
|
||||
- `--skip-before`
|
||||
- `--skip-docker`
|
||||
- `--skip-ko`
|
||||
- `--skip-publish`
|
||||
- `--skip-sbom`
|
||||
- `--skip-sign`
|
||||
- `--skip-validate`
|
||||
|
||||
By the same token, the following `goreleaser build` flags were deprecated:
|
||||
|
||||
- `--skip-before`
|
||||
- `--skip-post-hooks`
|
||||
- `--skip-validate`
|
||||
|
||||
All these flags are now under a single `--skip` flag, that accepts multiple
|
||||
values.
|
||||
|
||||
=== "Before"
|
||||
|
||||
```sh
|
||||
goreleaser build --skip-before --skip-validate
|
||||
goreleaser release --skip-validate --skip-publish
|
||||
```
|
||||
|
||||
=== "After"
|
||||
|
||||
```sh
|
||||
goreleaser build --skip=before,validate
|
||||
goreleaser release --skip=validate,publish
|
||||
|
||||
# or
|
||||
|
||||
goreleaser build --skip=before --skip=validate
|
||||
goreleaser release --skip=validate --skip=publish
|
||||
```
|
||||
|
||||
You can check `goreleaser build --help` and `goreleaser release --help` to see
|
||||
the valid options, and shell autocompletion should work properly as well.
|
||||
|
||||
### scoops.bucket
|
||||
|
||||
> since 2023-06-13 (v1.19.0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user