diff --git a/internal/pipe/archive/archive.go b/internal/pipe/archive/archive.go index d5e0fb7bf..7de9ae30f 100644 --- a/internal/pipe/archive/archive.go +++ b/internal/pipe/archive/archive.go @@ -112,15 +112,20 @@ func (Pipe) Run(ctx *context.Context) error { for group, artifacts := range artifacts { log.Debugf("group %s has %d binaries", group, len(artifacts)) artifacts := artifacts - if packageFormat(archive, artifacts[0].Goos) == "binary" { + format := packageFormat(archive, artifacts[0].Goos) + switch format { + case "none": + // do nothing + log.WithField("goos", artifacts[0].Goos).Info("ignored due to format override to 'none'") + case "binary": g.Go(func() error { return skip(ctx, archive, artifacts) }) - continue + default: + g.Go(func() error { + return create(ctx, archive, artifacts, format) + }) } - g.Go(func() error { - return create(ctx, archive, artifacts) - }) } } return g.Wait() @@ -138,15 +143,10 @@ func checkArtifacts(artifacts map[string][]*artifact.Artifact) error { } func createMeta(ctx *context.Context, arch config.Archive) error { - return doCreate(ctx, arch, nil, arch.Format) + return create(ctx, arch, nil, arch.Format) } -func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Artifact) error { - format := packageFormat(arch, binaries[0].Goos) - return doCreate(ctx, arch, binaries, format) -} - -func doCreate(ctx *context.Context, arch config.Archive, binaries []*artifact.Artifact, format string) error { +func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Artifact, format string) error { template := tmpl.New(ctx) if len(binaries) > 0 { template = template.WithArtifact(binaries[0]) diff --git a/internal/pipe/archive/archive_test.go b/internal/pipe/archive/archive_test.go index c99973976..bb1feef8b 100644 --- a/internal/pipe/archive/archive_test.go +++ b/internal/pipe/archive/archive_test.go @@ -73,7 +73,7 @@ func TestRunPipe(t *testing.T) { require.NoError(t, f.Close()) } require.NoError(t, os.MkdirAll(filepath.Join(folder, "foo", "bar", "foobar"), 0o755)) - f, err := os.Create(filepath.Join(filepath.Join(folder, "foo", "bar", "foobar", "blah.txt"))) + f, err := os.Create(filepath.Join(folder, "foo", "bar", "foobar", "blah.txt")) require.NoError(t, err) require.NoError(t, f.Close()) ctx := testctx.NewWithCfg( @@ -99,6 +99,10 @@ func TestRunPipe(t *testing.T) { Goos: "windows", Format: "zip", }, + { + Goos: "freebsd", + Format: "none", + }, }, }, }, @@ -188,6 +192,18 @@ func TestRunPipe(t *testing.T) { artifact.ExtraID: "default", }, } + freebsdAmd64Build := &artifact.Artifact{ + Goos: "freebsd", + Goarch: "amd64", + Goamd64: "v3", + Name: "bin/mybin", + Path: "will be ignored", + Type: artifact.Binary, + Extra: map[string]interface{}{ + artifact.ExtraBinary: "mybin", + artifact.ExtraID: "default", + }, + } ctx.Artifacts.Add(darwinBuild) ctx.Artifacts.Add(darwinUniversalBinary) ctx.Artifacts.Add(linux386Build) @@ -195,12 +211,23 @@ func TestRunPipe(t *testing.T) { ctx.Artifacts.Add(linuxMipsBuild) ctx.Artifacts.Add(windowsBuild) ctx.Artifacts.Add(linuxAmd64Build) + ctx.Artifacts.Add(freebsdAmd64Build) ctx.Version = "0.0.1" ctx.Git.CurrentTag = "v0.0.1" ctx.Config.Archives[0].Format = format require.NoError(t, Pipe{}.Run(ctx)) - archives := ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List() + require.Empty(t, ctx.Artifacts.Filter( + artifact.And( + artifact.ByGoos("freebsd"), + artifact.Or( + artifact.ByType(artifact.UploadableArchive), + artifact.ByType(artifact.UploadableBinary), + ), + ), + ).List(), "shouldn't have archived freebsd in any way") + + archives := ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List() for _, arch := range archives { expectBin := "bin/mybin" if arch.Goos == "windows" { @@ -820,12 +847,17 @@ func TestFormatFor(t *testing.T) { Goos: "windows", Format: "zip", }, + { + Goos: "darwin", + Format: "none", + }, }, }, }, }) require.Equal(t, "zip", packageFormat(ctx.Config.Archives[0], "windows")) require.Equal(t, "tar.gz", packageFormat(ctx.Config.Archives[0], "linux")) + require.Equal(t, "none", packageFormat(ctx.Config.Archives[0], "darwin")) } func TestBinaryOverride(t *testing.T) { diff --git a/pkg/config/config.go b/pkg/config/config.go index 06a7e0e96..5ed7d5c2d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -627,7 +627,7 @@ func (bh Hook) JSONSchema() *jsonschema.Schema { // FormatOverride is used to specify a custom format for a specific GOOS. type FormatOverride struct { Goos string `yaml:"goos,omitempty" json:"goos,omitempty"` - Format string `yaml:"format,omitempty" json:"format,omitempty" jsonschema:"enum=tar,enum=tgz,enum=tar.gz,enum=zip,enum=gz,enum=tar.xz,enum=txz,enum=binary,default=tar.gz"` + Format string `yaml:"format,omitempty" json:"format,omitempty" jsonschema:"enum=tar,enum=tgz,enum=tar.gz,enum=zip,enum=gz,enum=tar.xz,enum=txz,enum=binary,enum=none,default=tar.gz"` } // File is a file inside an archive. diff --git a/www/docs/customization/archive.md b/www/docs/customization/archive.md index 472914c70..29f4f302e 100644 --- a/www/docs/customization/archive.md +++ b/www/docs/customization/archive.md @@ -19,10 +19,12 @@ archives: builds: - default - # Archive format. Valid options are `tar.gz`, `tgz`, `tar.xz`, `txz`, tar`, `gz`, `zip` and `binary`. + # Archive format. + # # If format is `binary`, no archives are created and the binaries are instead # uploaded directly. # + # Valid options are `tar.gz`, `tgz`, `tar.xz`, `txz`, tar`, `gz`, `zip`, and `binary`. # Default: 'tar.gz' format: zip @@ -79,7 +81,12 @@ archives: # Can be used to change the archive formats for specific GOOSs. # Most common use case is to archive as zip on Windows. format_overrides: - - goos: windows + - # Which GOOS to override the format for. + goos: windows + + # The format to use for the given GOOS. + # + # Valid options are `tar.gz`, `tgz`, `tar.xz`, `txz`, tar`, `gz`, `zip`, `binary`, and `none`. format: zip # Additional files/globs you want to add to the archive.