mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-30 04:50:45 +02:00
feat: --skip-validate is back (#600)
This commit is contained in:
parent
956eeafdfe
commit
3db9913e1c
@ -34,6 +34,7 @@ type Context struct {
|
||||
Version string
|
||||
Snapshot bool
|
||||
SkipPublish bool
|
||||
SkipValidate bool
|
||||
RmDist bool
|
||||
Debug bool
|
||||
Parallelism int
|
||||
|
5
main.go
5
main.go
@ -103,6 +103,10 @@ func main() {
|
||||
Name: "skip-publish",
|
||||
Usage: "Generates all artifacts but does not publish them anywhere",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "skip-validate",
|
||||
Usage: "Skips all git state checks",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "rm-dist",
|
||||
Usage: "Remove the dist folder before building",
|
||||
@ -187,6 +191,7 @@ func releaseProject(flags Flags) error {
|
||||
}
|
||||
ctx.Snapshot = flags.Bool("snapshot")
|
||||
ctx.SkipPublish = ctx.Snapshot || flags.Bool("skip-publish")
|
||||
ctx.SkipValidate = ctx.Snapshot || flags.Bool("skip-validate")
|
||||
ctx.RmDist = flags.Bool("rm-dist")
|
||||
return doRelease(ctx)
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/git"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -114,7 +115,10 @@ func getSnapshotName(ctx *context.Context) (string, error) {
|
||||
|
||||
func validate(ctx *context.Context) error {
|
||||
if ctx.Snapshot {
|
||||
return nil
|
||||
return pipeline.ErrSnapshotEnabled
|
||||
}
|
||||
if ctx.SkipValidate {
|
||||
return pipeline.ErrSkipValidateEnabled
|
||||
}
|
||||
out, err := git.Run("status", "--porcelain")
|
||||
if strings.TrimSpace(out) != "" || err != nil {
|
||||
|
@ -60,7 +60,7 @@ func TestNoTagsSnapshot(t *testing.T) {
|
||||
},
|
||||
})
|
||||
ctx.Snapshot = true
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
assert.Contains(t, ctx.Version, "SNAPSHOT-")
|
||||
}
|
||||
|
||||
@ -112,9 +112,23 @@ func TestDirty(t *testing.T) {
|
||||
testlib.GitCommit(t, "commit2")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
assert.NoError(t, ioutil.WriteFile(dummy.Name(), []byte("lorem ipsum"), 0644))
|
||||
err = Pipe{}.Run(context.New(config.Project{}))
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "git is currently in a dirty state:")
|
||||
t.Run("all checks up", func(t *testing.T) {
|
||||
err = Pipe{}.Run(context.New(config.Project{}))
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "git is currently in a dirty state:")
|
||||
})
|
||||
t.Run("skip validate is set", func(t *testing.T) {
|
||||
ctx := context.New(config.Project{})
|
||||
ctx.SkipValidate = true
|
||||
err = Pipe{}.Run(ctx)
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
t.Run("snapshot", func(t *testing.T) {
|
||||
ctx := context.New(config.Project{})
|
||||
ctx.Snapshot = true
|
||||
err = Pipe{}.Run(ctx)
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
func TestTagIsNotLastCommit(t *testing.T) {
|
||||
@ -150,7 +164,7 @@ func TestSnapshotNoTags(t *testing.T) {
|
||||
testlib.GitCommit(t, "whatever")
|
||||
var ctx = context.New(config.Project{})
|
||||
ctx.Snapshot = true
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
assert.Equal(t, fakeInfo.CurrentTag, ctx.Git.CurrentTag)
|
||||
}
|
||||
|
||||
@ -160,7 +174,7 @@ func TestSnapshotNoCommits(t *testing.T) {
|
||||
testlib.GitInit(t)
|
||||
var ctx = context.New(config.Project{})
|
||||
ctx.Snapshot = true
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
assert.Equal(t, fakeInfo, ctx.Git)
|
||||
}
|
||||
|
||||
@ -169,7 +183,7 @@ func TestSnapshotWithoutRepo(t *testing.T) {
|
||||
defer back()
|
||||
var ctx = context.New(config.Project{})
|
||||
ctx.Snapshot = true
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
assert.Equal(t, fakeInfo, ctx.Git)
|
||||
}
|
||||
|
||||
@ -183,7 +197,7 @@ func TestSnapshotDirty(t *testing.T) {
|
||||
assert.NoError(t, ioutil.WriteFile(filepath.Join(folder, "foo"), []byte("foobar"), 0644))
|
||||
var ctx = context.New(config.Project{})
|
||||
ctx.Snapshot = true
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestShortCommitHash(t *testing.T) {
|
||||
@ -198,6 +212,6 @@ func TestShortCommitHash(t *testing.T) {
|
||||
})
|
||||
ctx.Snapshot = true
|
||||
ctx.Config.Git.ShortHash = true
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
assert.Len(t, ctx.Version, 7)
|
||||
}
|
||||
|
@ -22,6 +22,10 @@ var ErrSnapshotEnabled = Skip("disabled during snapshot mode")
|
||||
// It means that the part of a Piper that publishes its artifacts was not run.
|
||||
var ErrSkipPublishEnabled = Skip("publishing is disabled")
|
||||
|
||||
// ErrSkipValidateEnabled happens if --skip-validate is set.
|
||||
// It means that the part of a Piper that validates some things was not run.
|
||||
var ErrSkipValidateEnabled = Skip("validation is disabled")
|
||||
|
||||
// IsSkip returns true if the error is an ErrSkip
|
||||
func IsSkip(err error) bool {
|
||||
_, ok := err.(ErrSkip)
|
||||
|
Loading…
x
Reference in New Issue
Block a user