Skip to content

Commit

Permalink
feat!: more v2 cleanups (#4892)
Browse files Browse the repository at this point in the history
<!--

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>
  • Loading branch information
caarlos0 committed May 25, 2024
1 parent 4fa8df6 commit b6b2df6
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 154 deletions.
42 changes: 1 addition & 41 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions cmd/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
84 changes: 1 addition & 83 deletions cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
14 changes: 2 additions & 12 deletions cmd/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand Down
8 changes: 1 addition & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"} {
Expand Down

0 comments on commit b6b2df6

Please sign in to comment.