1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2024-12-31 01:53:50 +02:00

feat: added --skip-before flag (#3182)

* feat: added --skip-before flag

this would allow to skip global before hooks

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: skip docker test

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2022-06-22 21:56:53 -03:00 committed by GitHub
parent ae399220ef
commit d79484ef1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 4 deletions

View File

@ -30,6 +30,7 @@ type buildOpts struct {
id string
snapshot bool
skipValidate bool
skipBefore bool
skipPostHooks bool
rmDist bool
deprecated bool
@ -70,6 +71,7 @@ When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`"
cmd.Flags().StringVarP(&root.opts.config, "config", "f", "", "Load configuration from file")
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.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)")
@ -125,6 +127,7 @@ 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.RmDist = options.rmDist
ctx.SkipTokenCheck = true

View File

@ -36,6 +36,7 @@ type releaseOpts struct {
skipAnnounce bool
skipSBOMCataloging bool
skipDocker bool
skipBefore bool
rmDist bool
deprecated bool
parallelism int
@ -76,6 +77,7 @@ func newReleaseCmd() *releaseCmd {
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.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.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)")
@ -134,6 +136,7 @@ func setupReleaseContext(ctx *context.Context, options releaseOpts) *context.Con
ctx.SkipSign = options.skipSign
ctx.SkipSBOMCataloging = options.skipSBOMCataloging
ctx.SkipDocker = options.skipDocker
ctx.SkipBefore = options.skipBefore
ctx.RmDist = options.rmDist
// test only

View File

@ -18,8 +18,10 @@ import (
// Pipe is a global hook pipe.
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 }
func (Pipe) String() string { return "running before hooks" }
func (Pipe) Skip(ctx *context.Context) bool {
return len(ctx.Config.Before.Hooks) == 0 || ctx.SkipBefore
}
// Run executes the hooks.
func (Pipe) Run(ctx *context.Context) error {

View File

@ -97,6 +97,16 @@ func TestSkip(t *testing.T) {
require.True(t, Pipe{}.Skip(context.New(config.Project{})))
})
t.Run("skip before", func(t *testing.T) {
ctx := context.New(config.Project{
Before: config.Before{
Hooks: []string{""},
},
})
ctx.SkipBefore = true
require.True(t, Pipe{}.Skip(ctx))
})
t.Run("dont skip", func(t *testing.T) {
ctx := context.New(config.Project{
Before: config.Before{

View File

@ -1373,7 +1373,9 @@ func TestSkip(t *testing.T) {
})
t.Run("skip docker", func(t *testing.T) {
ctx := context.New(config.Project{})
ctx := context.New(config.Project{
Dockers: []config.Docker{{}},
})
ctx.SkipDocker = true
require.True(t, Pipe{}.Skip(ctx))
})
@ -1392,7 +1394,9 @@ func TestSkip(t *testing.T) {
})
t.Run("skip docker", func(t *testing.T) {
ctx := context.New(config.Project{})
ctx := context.New(config.Project{
DockerManifests: []config.DockerManifest{{}},
})
ctx.SkipDocker = true
require.True(t, ManifestPipe{}.Skip(ctx))
})

View File

@ -96,6 +96,7 @@ type Context struct {
SkipValidate bool
SkipSBOMCataloging bool
SkipDocker bool
SkipBefore bool
RmDist bool
PreRelease bool
Deprecated bool