mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-07 13:31:37 +02:00
fix: improve handling of --rm-dist deprecation (#3728)
- improved how we handle `--rm-dist` deprecation so it looks more like other deprecations - improved deprecation error message a bit as well Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
90a82157ca
commit
4954815ae4
14
cmd/build.go
14
cmd/build.go
@ -11,6 +11,7 @@ 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/middleware/errhandler"
|
||||
"github.com/goreleaser/goreleaser/internal/middleware/logging"
|
||||
@ -34,6 +35,7 @@ type buildOpts struct {
|
||||
skipBefore bool
|
||||
skipPostHooks bool
|
||||
clean bool
|
||||
rmDist bool // deprecated
|
||||
deprecated bool
|
||||
parallelism int
|
||||
timeout time.Duration
|
||||
@ -75,7 +77,7 @@ When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`"
|
||||
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, "Remove the dist folder before building")
|
||||
cmd.Flags().BoolVar(&root.opts.clean, "rm-dist", false, "Remove the dist folder before building")
|
||||
cmd.Flags().BoolVar(&root.opts.rmDist, "rm-dist", false, "Remove the dist folder before building")
|
||||
cmd.Flags().IntVarP(&root.opts.parallelism, "parallelism", "p", 0, "Amount tasks to run concurrently (default: number of CPUs)")
|
||||
cmd.Flags().DurationVar(&root.opts.timeout, "timeout", 30*time.Minute, "Timeout to the entire build process")
|
||||
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")
|
||||
@ -84,7 +86,6 @@ When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`"
|
||||
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.Flags().SetAnnotation("output", cobra.BashCompFilenameExt, []string{""})
|
||||
_ = cmd.Flags().MarkHidden("rm-dist")
|
||||
_ = cmd.Flags().MarkDeprecated("rm-dist", "please use --clean instead")
|
||||
_ = cmd.Flags().MarkHidden("deprecated")
|
||||
|
||||
root.cmd = cmd
|
||||
@ -125,6 +126,7 @@ func setupPipeline(ctx *context.Context, options buildOpts) []pipeline.Piper {
|
||||
}
|
||||
|
||||
func setupBuildContext(ctx *context.Context, options buildOpts) error {
|
||||
ctx.Deprecated = options.deprecated // test only
|
||||
ctx.Parallelism = runtime.NumCPU()
|
||||
if options.parallelism > 0 {
|
||||
ctx.Parallelism = options.parallelism
|
||||
@ -134,8 +136,12 @@ func setupBuildContext(ctx *context.Context, options buildOpts) error {
|
||||
ctx.SkipValidate = ctx.Snapshot || options.skipValidate
|
||||
ctx.SkipBefore = options.skipBefore
|
||||
ctx.SkipPostBuildHooks = options.skipPostHooks
|
||||
ctx.RmDist = options.clean
|
||||
ctx.SkipTokenCheck = true
|
||||
ctx.Clean = options.clean || options.rmDist
|
||||
|
||||
if options.rmDist {
|
||||
deprecate.NoticeCustom(ctx, "-rm-dist", "--rm-dist was deprecated in favor of --clean, check {{ .URL }} for more details")
|
||||
}
|
||||
|
||||
if options.singleTarget {
|
||||
setupBuildSingleTarget(ctx)
|
||||
@ -147,8 +153,6 @@ func setupBuildContext(ctx *context.Context, options buildOpts) error {
|
||||
}
|
||||
}
|
||||
|
||||
// test only
|
||||
ctx.Deprecated = options.deprecated
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ func TestBuildFlags(t *testing.T) {
|
||||
t.Run("rm dist", func(t *testing.T) {
|
||||
require.True(t, setup(buildOpts{
|
||||
clean: true,
|
||||
}).RmDist)
|
||||
}).Clean)
|
||||
})
|
||||
|
||||
t.Run("single-target", func(t *testing.T) {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/caarlos0/ctrlc"
|
||||
"github.com/caarlos0/log"
|
||||
"github.com/goreleaser/goreleaser/internal/deprecate"
|
||||
"github.com/goreleaser/goreleaser/internal/middleware/errhandler"
|
||||
"github.com/goreleaser/goreleaser/internal/middleware/logging"
|
||||
"github.com/goreleaser/goreleaser/internal/middleware/skip"
|
||||
@ -39,6 +40,7 @@ type releaseOpts struct {
|
||||
skipKo bool
|
||||
skipBefore bool
|
||||
clean bool
|
||||
rmDist bool
|
||||
deprecated bool
|
||||
parallelism int
|
||||
timeout time.Duration
|
||||
@ -82,7 +84,7 @@ func newReleaseCmd() *releaseCmd {
|
||||
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 folder")
|
||||
cmd.Flags().BoolVar(&root.opts.clean, "rm-dist", false, "Removes the dist folder")
|
||||
cmd.Flags().BoolVar(&root.opts.rmDist, "rm-dist", false, "Removes the dist folder")
|
||||
cmd.Flags().IntVarP(&root.opts.parallelism, "parallelism", "p", 0, "Amount tasks to run concurrently (default: number of CPUs)")
|
||||
cmd.Flags().DurationVar(&root.opts.timeout, "timeout", 30*time.Minute, "Timeout to the entire release process")
|
||||
cmd.Flags().BoolVar(&root.opts.deprecated, "deprecated", false, "Force print the deprecation message - tests only")
|
||||
@ -120,6 +122,7 @@ func releaseProject(options releaseOpts) (*context.Context, error) {
|
||||
}
|
||||
|
||||
func setupReleaseContext(ctx *context.Context, options releaseOpts) {
|
||||
ctx.Deprecated = options.deprecated // test only
|
||||
ctx.Parallelism = runtime.NumCPU()
|
||||
if options.parallelism > 0 {
|
||||
ctx.Parallelism = options.parallelism
|
||||
@ -144,8 +147,9 @@ func setupReleaseContext(ctx *context.Context, options releaseOpts) {
|
||||
ctx.SkipDocker = options.skipDocker
|
||||
ctx.SkipKo = options.skipKo
|
||||
ctx.SkipBefore = options.skipBefore
|
||||
ctx.RmDist = options.clean
|
||||
ctx.Clean = options.clean || options.rmDist
|
||||
|
||||
// test only
|
||||
ctx.Deprecated = options.deprecated
|
||||
if options.rmDist {
|
||||
deprecate.NoticeCustom(ctx, "-rm-dist", "--rm-dist was deprecated in favor of --clean, check {{ .URL }} for more details")
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +120,6 @@ func TestReleaseFlags(t *testing.T) {
|
||||
t.Run("rm dist", func(t *testing.T) {
|
||||
require.True(t, setup(t, releaseOpts{
|
||||
clean: true,
|
||||
}).RmDist)
|
||||
}).Clean)
|
||||
})
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ func shouldPrependRelease(cmd *cobra.Command, args []string) bool {
|
||||
|
||||
func deprecateWarn(ctx *context.Context) {
|
||||
if ctx.Deprecated {
|
||||
log.Warn(boldStyle.Render("your config is using deprecated properties, check logs above for details"))
|
||||
log.Warn(boldStyle.Render("you are using deprecated options, check the output above for details"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,10 +34,12 @@ func NoticeCustom(ctx *context.Context, property, tmpl string) {
|
||||
" ", "-",
|
||||
).Replace(property)
|
||||
var out bytes.Buffer
|
||||
if err := template.Must(template.New("deprecation").Parse("DEPRECATED: "+tmpl)).Execute(&out, templateData{
|
||||
URL: url,
|
||||
Property: property,
|
||||
}); err != nil {
|
||||
if err := template.
|
||||
Must(template.New("deprecation").Parse("DEPRECATED: "+tmpl)).
|
||||
Execute(&out, templateData{
|
||||
URL: url,
|
||||
Property: property,
|
||||
}); err != nil {
|
||||
panic(err) // this should never happen
|
||||
}
|
||||
|
||||
|
2
internal/pipe/dist/dist.go
vendored
2
internal/pipe/dist/dist.go
vendored
@ -24,7 +24,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
log.Debugf("%s doesn't exist, creating empty folder", ctx.Config.Dist)
|
||||
return mkdir(ctx)
|
||||
}
|
||||
if ctx.RmDist {
|
||||
if ctx.Clean {
|
||||
log.Infof("cleaning %s", ctx.Config.Dist)
|
||||
err = os.RemoveAll(ctx.Config.Dist)
|
||||
if err == nil {
|
||||
|
2
internal/pipe/dist/dist_test.go
vendored
2
internal/pipe/dist/dist_test.go
vendored
@ -38,7 +38,7 @@ func TestPopulatedDistExists(t *testing.T) {
|
||||
},
|
||||
}
|
||||
require.Error(t, Pipe{}.Run(ctx))
|
||||
ctx.RmDist = true
|
||||
ctx.Clean = true
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
_, err = os.Stat(dist)
|
||||
require.False(t, os.IsExist(err))
|
||||
|
@ -99,7 +99,7 @@ type Context struct {
|
||||
SkipKo bool
|
||||
SkipDocker bool
|
||||
SkipBefore bool
|
||||
RmDist bool
|
||||
Clean bool
|
||||
PreRelease bool
|
||||
Deprecated bool
|
||||
Parallelism int
|
||||
|
Loading…
x
Reference in New Issue
Block a user