1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00

feat(archives): format override to 'none' to skip certain goos (#4730)

closes #4644

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2024-03-29 16:20:05 -03:00 committed by GitHub
parent f0abada909
commit 1db9347363
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 56 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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