From 1cf9100ecc1589f5de946727174bb0e74985221b Mon Sep 17 00:00:00 2001 From: Leonardo Grasso Date: Thu, 2 Apr 2020 15:18:05 +0200 Subject: [PATCH] feat: build.skip option, support for library projects (#1419) * fix: checksum pipe will not return an error when artifact list is empty Signed-off-by: Leonardo Grasso * new: build.skip option for libraries Signed-off-by: Leonardo Grasso * docs: update doc with build.skip option Signed-off-by: Leonardo Grasso --- internal/pipe/build/build.go | 4 ++++ internal/pipe/build/build_test.go | 17 +++++++++++++++++ internal/pipe/checksums/checksums.go | 19 ++++++++++++------- internal/pipe/checksums/checksums_test.go | 6 ++++++ pkg/config/config.go | 1 + www/content/build.md | 7 ++++++- 6 files changed, 46 insertions(+), 8 deletions(-) diff --git a/internal/pipe/build/build.go b/internal/pipe/build/build.go index 22914818c57..1c2cc0fcbb5 100644 --- a/internal/pipe/build/build.go +++ b/internal/pipe/build/build.go @@ -32,6 +32,10 @@ func (Pipe) String() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { for _, build := range ctx.Config.Builds { + if build.Skip { + log.WithField("id", build.ID).Info("skip is set") + continue + } log.WithField("build", build).Debug("building") if err := runPipeOnBuild(ctx, build); err != nil { return err diff --git a/internal/pipe/build/build_test.go b/internal/pipe/build/build_test.go index 165a66f6aa6..a29c586f3e6 100644 --- a/internal/pipe/build/build_test.go +++ b/internal/pipe/build/build_test.go @@ -339,6 +339,23 @@ func TestDefaultFillSingleBuild(t *testing.T) { assert.Equal(t, ctx.Config.Builds[0].Binary, "foo") } +func TestSkipBuild(t *testing.T) { + folder, back := testlib.Mktmp(t) + defer back() + var config = config.Project{ + Dist: folder, + Builds: []config.Build{ + { + Skip: true, + }, + }, + } + var ctx = context.New(config) + ctx.Git.CurrentTag = "2.4.5" + assert.NoError(t, Pipe{}.Run(ctx)) + assert.Len(t, ctx.Artifacts.List(), 0) +} + func TestExtWindows(t *testing.T) { assert.Equal(t, ".exe", extFor("windows_amd64", config.FlagArray{})) assert.Equal(t, ".exe", extFor("windows_386", config.FlagArray{})) diff --git a/internal/pipe/checksums/checksums.go b/internal/pipe/checksums/checksums.go index eac649f868e..f1227644291 100644 --- a/internal/pipe/checksums/checksums.go +++ b/internal/pipe/checksums/checksums.go @@ -35,6 +35,17 @@ func (Pipe) Default(ctx *context.Context) error { // Run the pipe func (Pipe) Run(ctx *context.Context) (err error) { + artifactList := ctx.Artifacts.Filter( + artifact.Or( + artifact.ByType(artifact.UploadableArchive), + artifact.ByType(artifact.UploadableBinary), + artifact.ByType(artifact.LinuxPackage), + ), + ).List() + if len(artifactList) == 0 { + return nil + } + filename, err := tmpl.New(ctx).Apply(ctx.Config.Checksum.NameTemplate) if err != nil { return err @@ -50,13 +61,7 @@ func (Pipe) Run(ctx *context.Context) (err error) { defer file.Close() // nolint: errcheck var g = semerrgroup.New(ctx.Parallelism) - for _, artifact := range ctx.Artifacts.Filter( - artifact.Or( - artifact.ByType(artifact.UploadableArchive), - artifact.ByType(artifact.UploadableBinary), - artifact.ByType(artifact.LinuxPackage), - ), - ).List() { + for _, artifact := range artifactList { artifact := artifact g.Go(func() error { return checksums(ctx.Config.Checksum.Algorithm, file, artifact) diff --git a/internal/pipe/checksums/checksums_test.go b/internal/pipe/checksums/checksums_test.go index cd24a2b0b54..4b5314fc872 100644 --- a/internal/pipe/checksums/checksums_test.go +++ b/internal/pipe/checksums/checksums_test.go @@ -131,6 +131,12 @@ func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) { assert.Contains(t, err.Error(), "/checksums.txt: permission denied") } +func TestPipeWhenNoArtifacts(t *testing.T) { + var ctx = &context.Context{} + assert.NoError(t, Pipe{}.Run(ctx)) + assert.Len(t, ctx.Artifacts.List(), 0) +} + func TestDefault(t *testing.T) { var ctx = &context.Context{ Config: config.Project{ diff --git a/pkg/config/config.go b/pkg/config/config.go index 677d1677fb7..13cf9ee9771 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -156,6 +156,7 @@ type Build struct { Lang string `yaml:",omitempty"` Asmflags StringArray `yaml:",omitempty"` Gcflags StringArray `yaml:",omitempty"` + Skip bool `yaml:",omitempty"` } // FormatOverride is used to specify a custom format for a specific GOOS. diff --git a/www/content/build.md b/www/content/build.md index b2bac6267d8..660280b94d7 100644 --- a/www/content/build.md +++ b/www/content/build.md @@ -111,6 +111,11 @@ builds: hooks: pre: rice embed-go post: ./script.sh + + # If true, skip the build. + # Useful for library projects. + # Default is false + skip: false ``` > Learn more about the [name template engine](/templates). @@ -154,4 +159,4 @@ GOVERSION=$(go version) goreleaser GoReleaser uses `git describe` to get the build tag. You can set a different build tag using the environment variable `GORELEASER_CURRENT_TAG`. -This is useful in scenarios where two tags point to the same commit. +This is useful in scenarios where two tags point to the same commit. \ No newline at end of file