1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-01 13:07:49 +02:00

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 <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>
This commit is contained in:
Leonardo Grasso 2020-04-02 15:18:05 +02:00 committed by GitHub
parent e2ef52032b
commit 1cf9100ecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 8 deletions

View File

@ -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

View File

@ -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{}))

View File

@ -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)

View File

@ -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{

View File

@ -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.

View File

@ -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.