mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-24 04:16:27 +02:00
feat!: more v2 cleanups (#4892)
<!-- Hi, thanks for contributing! Please make sure you read our CONTRIBUTING guide. Also, add tests and the respective documentation changes as well. --> <!-- If applied, this commit will... --> ... <!-- Why is this change being made? --> ... <!-- # Provide links to any relevant tickets, URLs or other resources --> ... --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
4fa8df6413
commit
b6b2df6312
42
cmd/build.go
42
cmd/build.go
@ -10,7 +10,6 @@ import (
|
||||
"github.com/caarlos0/ctrlc"
|
||||
"github.com/caarlos0/log"
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/deprecate"
|
||||
"github.com/goreleaser/goreleaser/internal/gio"
|
||||
"github.com/goreleaser/goreleaser/internal/logext"
|
||||
"github.com/goreleaser/goreleaser/internal/middleware/errhandler"
|
||||
@ -39,15 +38,6 @@ type buildOpts struct {
|
||||
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 {
|
||||
@ -82,11 +72,7 @@ When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`"
|
||||
cmd.Flags().StringVarP(&root.opts.config, "config", "f", "", "Load configuration from file")
|
||||
_ = cmd.MarkFlagFilename("config", "yaml", "yml")
|
||||
cmd.Flags().BoolVar(&root.opts.snapshot, "snapshot", false, "Generate an unversioned snapshot build, skipping all validations")
|
||||
cmd.Flags().BoolVar(&root.opts.skipValidate, "skip-validate", false, "Skips several sanity checks")
|
||||
cmd.Flags().BoolVar(&root.opts.skipBefore, "skip-before", false, "Skips global before hooks")
|
||||
cmd.Flags().BoolVar(&root.opts.skipPostHooks, "skip-post-hooks", false, "Skips all post-build hooks")
|
||||
cmd.Flags().BoolVar(&root.opts.clean, "clean", false, "Removes the 'dist' directory before building")
|
||||
cmd.Flags().BoolVar(&root.opts.rmDist, "rm-dist", false, "Removes the 'dist' directory before building")
|
||||
cmd.Flags().IntVarP(&root.opts.parallelism, "parallelism", "p", 0, "Number of tasks to run concurrently (default: number of CPUs)")
|
||||
_ = cmd.RegisterFlagCompletionFunc("parallelism", cobra.NoFileCompletions)
|
||||
cmd.Flags().DurationVar(&root.opts.timeout, "timeout", 30*time.Minute, "Timeout to the entire build process")
|
||||
@ -108,17 +94,8 @@ When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`"
|
||||
cmd.Flags().BoolVar(&root.opts.deprecated, "deprecated", false, "Force print the deprecation message - tests only")
|
||||
cmd.Flags().StringVarP(&root.opts.output, "output", "o", "", "Copy the binary to the path after the build. Only taken into account when using --single-target and a single id (either with --id or if configuration only has one build)")
|
||||
_ = cmd.MarkFlagFilename("output", "")
|
||||
_ = 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",
|
||||
@ -180,29 +157,12 @@ func setupBuildContext(ctx *context.Context, options buildOpts) error {
|
||||
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
|
||||
ctx.Clean = options.clean
|
||||
|
||||
if options.singleTarget {
|
||||
ctx.Partial = true
|
||||
|
@ -151,15 +151,6 @@ func TestBuildFlags(t *testing.T) {
|
||||
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{
|
||||
skips: []string{
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/caarlos0/ctrlc"
|
||||
"github.com/caarlos0/log"
|
||||
"github.com/goreleaser/goreleaser/internal/deprecate"
|
||||
"github.com/goreleaser/goreleaser/internal/logext"
|
||||
"github.com/goreleaser/goreleaser/internal/middleware/errhandler"
|
||||
"github.com/goreleaser/goreleaser/internal/middleware/logging"
|
||||
@ -41,25 +40,6 @@ type releaseOpts struct {
|
||||
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 {
|
||||
@ -101,37 +81,13 @@ func newReleaseCmd() *releaseCmd {
|
||||
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.draft, "draft", false, "Whether to set the release to draft. Overrides release.draft in the configuration file")
|
||||
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.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")
|
||||
cmd.Flags().BoolVar(&root.opts.skipKo, "skip-ko", false, "Skips Ko builds")
|
||||
cmd.Flags().BoolVar(&root.opts.skipBefore, "skip-before", false, "Skips global before hooks")
|
||||
cmd.Flags().BoolVar(&root.opts.skipValidate, "skip-validate", false, "Skips git checks")
|
||||
cmd.Flags().BoolVar(&root.opts.clean, "clean", false, "Removes the 'dist' directory")
|
||||
cmd.Flags().BoolVar(&root.opts.rmDist, "rm-dist", false, "Removes the 'dist' directory")
|
||||
cmd.Flags().IntVarP(&root.opts.parallelism, "parallelism", "p", 0, "Amount tasks to run concurrently (default: number of CPUs)")
|
||||
_ = cmd.RegisterFlagCompletionFunc("parallelism", cobra.NoFileCompletions)
|
||||
cmd.Flags().DurationVar(&root.opts.timeout, "timeout", 30*time.Minute, "Timeout to the entire release process")
|
||||
_ = cmd.RegisterFlagCompletionFunc("timeout", cobra.NoFileCompletions)
|
||||
cmd.Flags().BoolVar(&root.opts.deprecated, "deprecated", false, "Force print the deprecation message - tests only")
|
||||
_ = 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",
|
||||
@ -188,7 +144,7 @@ func setupReleaseContext(ctx *context.Context, options releaseOpts) error {
|
||||
ctx.ReleaseFooterTmpl = options.releaseFooterTmpl
|
||||
ctx.Snapshot = options.snapshot
|
||||
ctx.FailFast = options.failFast
|
||||
ctx.Clean = options.clean || options.rmDist
|
||||
ctx.Clean = options.clean
|
||||
if options.autoSnapshot && git.CheckDirty(ctx) != nil {
|
||||
log.Info("git repository is dirty and --auto-snapshot is set, implying --snapshot")
|
||||
ctx.Snapshot = true
|
||||
@ -202,44 +158,6 @@ func setupReleaseContext(ctx *context.Context, options releaseOpts) error {
|
||||
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)
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func TestReleaseAutoSnapshot(t *testing.T) {
|
||||
t.Run("clean", func(t *testing.T) {
|
||||
setup(t)
|
||||
cmd := newReleaseCmd()
|
||||
cmd.cmd.SetArgs([]string{"--auto-snapshot", "--skip-publish"})
|
||||
cmd.cmd.SetArgs([]string{"--auto-snapshot", "--skip=publish"})
|
||||
require.NoError(t, cmd.cmd.Execute())
|
||||
require.FileExists(t, "dist/fake_0.0.2_checksums.txt", "should have created checksums when run with --snapshot")
|
||||
})
|
||||
@ -31,7 +31,7 @@ func TestReleaseAutoSnapshot(t *testing.T) {
|
||||
setup(t)
|
||||
createFile(t, "foo", "force dirty tree")
|
||||
cmd := newReleaseCmd()
|
||||
cmd.cmd.SetArgs([]string{"--auto-snapshot", "--skip-publish"})
|
||||
cmd.cmd.SetArgs([]string{"--auto-snapshot", "--skip=publish"})
|
||||
require.NoError(t, cmd.cmd.Execute())
|
||||
matches, err := filepath.Glob("./dist/fake_0.0.2-SNAPSHOT-*_checksums.txt")
|
||||
require.NoError(t, err)
|
||||
@ -100,16 +100,6 @@ func TestReleaseFlags(t *testing.T) {
|
||||
requireAll(t, ctx, skips.Publish, skips.Validate, skips.Announce)
|
||||
})
|
||||
|
||||
t.Run("skips (old)", func(t *testing.T) {
|
||||
ctx := setup(t, releaseOpts{
|
||||
skipPublish: true,
|
||||
skipSign: true,
|
||||
skipValidate: true,
|
||||
})
|
||||
|
||||
requireAll(t, ctx, skips.Sign, skips.Publish, skips.Validate, skips.Announce)
|
||||
})
|
||||
|
||||
t.Run("skips", func(t *testing.T) {
|
||||
ctx := setup(t, releaseOpts{
|
||||
skips: []string{
|
||||
|
@ -51,9 +51,6 @@ type rootCmd struct {
|
||||
cmd *cobra.Command
|
||||
verbose bool
|
||||
exit func(int)
|
||||
|
||||
// Deprecated: use verbose instead.
|
||||
debug bool
|
||||
}
|
||||
|
||||
func newRootCmd(version goversion.Info, exit func(int)) *rootCmd {
|
||||
@ -78,7 +75,7 @@ Check out our website for more information, examples and documentation: https://
|
||||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
PersistentPreRun: func(*cobra.Command, []string) {
|
||||
if root.verbose || root.debug {
|
||||
if root.verbose {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
log.Debug("verbose output enabled")
|
||||
}
|
||||
@ -89,10 +86,7 @@ Check out our website for more information, examples and documentation: https://
|
||||
}
|
||||
cmd.SetVersionTemplate("{{.Version}}")
|
||||
|
||||
cmd.PersistentFlags().BoolVar(&root.debug, "debug", false, "Enable verbose mode")
|
||||
cmd.PersistentFlags().BoolVar(&root.verbose, "verbose", false, "Enable verbose mode")
|
||||
_ = cmd.Flags().MarkDeprecated("debug", "please use --verbose instead")
|
||||
_ = cmd.Flags().MarkHidden("debug")
|
||||
cmd.AddCommand(
|
||||
newBuildCmd().cmd,
|
||||
newReleaseCmd().cmd,
|
||||
|
@ -73,11 +73,11 @@ func TestShouldPrependRelease(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("release args", func(t *testing.T) {
|
||||
require.True(t, result([]string{"--skip-validate"}))
|
||||
require.True(t, result([]string{"--skip=validate"}))
|
||||
})
|
||||
|
||||
t.Run("several release args", func(t *testing.T) {
|
||||
require.True(t, result([]string{"--skip-validate", "--snapshot"}))
|
||||
require.True(t, result([]string{"--skip=validate", "--snapshot"}))
|
||||
})
|
||||
|
||||
for _, s := range []string{"--help", "-h", "-v", "--version"} {
|
||||
|
Loading…
x
Reference in New Issue
Block a user