Skip to content

Commit

Permalink
feat: build.skip option, support for library projects (#1419)
Browse files Browse the repository at this point in the history
* fix: checksum pipe will not return an error when artifact list is empty

Signed-off-by: Leonardo Grasso <me@leonardograsso.com>

* new: build.skip option for libraries

Signed-off-by: Leonardo Grasso <me@leonardograsso.com>

* docs: update doc with build.skip option

Signed-off-by: Leonardo Grasso <me@leonardograsso.com>
  • Loading branch information
leogr committed Apr 2, 2020
1 parent e2ef520 commit 1cf9100
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
4 changes: 4 additions & 0 deletions internal/pipe/build/build.go
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions internal/pipe/build/build_test.go
Expand Up @@ -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{}))
Expand Down
19 changes: 12 additions & 7 deletions internal/pipe/checksums/checksums.go
Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions internal/pipe/checksums/checksums_test.go
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion www/content/build.md
Expand Up @@ -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).
Expand Down Expand Up @@ -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.

0 comments on commit 1cf9100

Please sign in to comment.