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:
parent
e2ef52032b
commit
1cf9100ecc
@ -32,6 +32,10 @@ func (Pipe) String() string {
|
|||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(ctx *context.Context) error {
|
func (Pipe) Run(ctx *context.Context) error {
|
||||||
for _, build := range ctx.Config.Builds {
|
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")
|
log.WithField("build", build).Debug("building")
|
||||||
if err := runPipeOnBuild(ctx, build); err != nil {
|
if err := runPipeOnBuild(ctx, build); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -339,6 +339,23 @@ func TestDefaultFillSingleBuild(t *testing.T) {
|
|||||||
assert.Equal(t, ctx.Config.Builds[0].Binary, "foo")
|
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) {
|
func TestExtWindows(t *testing.T) {
|
||||||
assert.Equal(t, ".exe", extFor("windows_amd64", config.FlagArray{}))
|
assert.Equal(t, ".exe", extFor("windows_amd64", config.FlagArray{}))
|
||||||
assert.Equal(t, ".exe", extFor("windows_386", config.FlagArray{}))
|
assert.Equal(t, ".exe", extFor("windows_386", config.FlagArray{}))
|
||||||
|
@ -35,6 +35,17 @@ func (Pipe) Default(ctx *context.Context) error {
|
|||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(ctx *context.Context) (err error) {
|
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)
|
filename, err := tmpl.New(ctx).Apply(ctx.Config.Checksum.NameTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -50,13 +61,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
|||||||
defer file.Close() // nolint: errcheck
|
defer file.Close() // nolint: errcheck
|
||||||
|
|
||||||
var g = semerrgroup.New(ctx.Parallelism)
|
var g = semerrgroup.New(ctx.Parallelism)
|
||||||
for _, artifact := range ctx.Artifacts.Filter(
|
for _, artifact := range artifactList {
|
||||||
artifact.Or(
|
|
||||||
artifact.ByType(artifact.UploadableArchive),
|
|
||||||
artifact.ByType(artifact.UploadableBinary),
|
|
||||||
artifact.ByType(artifact.LinuxPackage),
|
|
||||||
),
|
|
||||||
).List() {
|
|
||||||
artifact := artifact
|
artifact := artifact
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return checksums(ctx.Config.Checksum.Algorithm, file, artifact)
|
return checksums(ctx.Config.Checksum.Algorithm, file, artifact)
|
||||||
|
@ -131,6 +131,12 @@ func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) {
|
|||||||
assert.Contains(t, err.Error(), "/checksums.txt: permission denied")
|
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) {
|
func TestDefault(t *testing.T) {
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
|
@ -156,6 +156,7 @@ type Build struct {
|
|||||||
Lang string `yaml:",omitempty"`
|
Lang string `yaml:",omitempty"`
|
||||||
Asmflags StringArray `yaml:",omitempty"`
|
Asmflags StringArray `yaml:",omitempty"`
|
||||||
Gcflags StringArray `yaml:",omitempty"`
|
Gcflags StringArray `yaml:",omitempty"`
|
||||||
|
Skip bool `yaml:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormatOverride is used to specify a custom format for a specific GOOS.
|
// FormatOverride is used to specify a custom format for a specific GOOS.
|
||||||
|
@ -111,6 +111,11 @@ builds:
|
|||||||
hooks:
|
hooks:
|
||||||
pre: rice embed-go
|
pre: rice embed-go
|
||||||
post: ./script.sh
|
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).
|
> 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
|
GoReleaser uses `git describe` to get the build tag. You can set
|
||||||
a different build tag using the environment variable `GORELEASER_CURRENT_TAG`.
|
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.
|
Loading…
x
Reference in New Issue
Block a user