mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-05-27 23:07:53 +02:00
parent
ce267acabf
commit
18b8be6818
@ -18,6 +18,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/archive"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
)
|
||||
|
||||
@ -90,7 +91,7 @@ func create(ctx *context.Context, binaries []artifact.Artifact) error {
|
||||
}
|
||||
archivePath := filepath.Join(ctx.Config.Dist, folder+"."+format)
|
||||
lock.Lock()
|
||||
if _, err := os.Stat(archivePath); !os.IsNotExist(err) {
|
||||
if _, err = os.Stat(archivePath); !os.IsNotExist(err) {
|
||||
lock.Unlock()
|
||||
return fmt.Errorf("archive named %s already exists. Check your archive name template", archivePath)
|
||||
}
|
||||
@ -101,12 +102,17 @@ func create(ctx *context.Context, binaries []artifact.Artifact) error {
|
||||
}
|
||||
lock.Unlock()
|
||||
defer archiveFile.Close() // nolint: errcheck
|
||||
|
||||
var log = log.WithField("archive", archivePath)
|
||||
log.Info("creating")
|
||||
var wrap string
|
||||
if ctx.Config.Archive.WrapInDirectory {
|
||||
wrap = folder
|
||||
|
||||
wrap, err := tmpl.New(ctx).
|
||||
WithArtifact(binaries[0], ctx.Config.Archive.Replacements).
|
||||
Apply(wrapFolder(ctx.Config.Archive))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var a = NewEnhancedArchive(archive.New(archiveFile), wrap)
|
||||
defer a.Close() // nolint: errcheck
|
||||
|
||||
@ -135,6 +141,17 @@ func create(ctx *context.Context, binaries []artifact.Artifact) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func wrapFolder(a config.Archive) string {
|
||||
switch a.WrapInDirectory {
|
||||
case "true":
|
||||
return a.NameTemplate
|
||||
case "false":
|
||||
return ""
|
||||
default:
|
||||
return a.WrapInDirectory
|
||||
}
|
||||
}
|
||||
|
||||
func skip(ctx *context.Context, binaries []artifact.Artifact) error {
|
||||
for _, binary := range binaries {
|
||||
log.WithField("binary", binary.Name).Info("skip archiving")
|
||||
|
@ -282,8 +282,11 @@ func TestRunPipeWrap(t *testing.T) {
|
||||
Dist: dist,
|
||||
Archive: config.Archive{
|
||||
NameTemplate: "foo",
|
||||
WrapInDirectory: true,
|
||||
WrapInDirectory: "foo_{{ .Os }}",
|
||||
Format: "tar.gz",
|
||||
Replacements: map[string]string{
|
||||
"darwin": "macOS",
|
||||
},
|
||||
Files: []string{
|
||||
"README.*",
|
||||
},
|
||||
@ -317,7 +320,7 @@ func TestRunPipeWrap(t *testing.T) {
|
||||
break
|
||||
}
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, filepath.Join("foo", n), h.Name)
|
||||
require.Equal(t, filepath.Join("foo_macOS", n), h.Name)
|
||||
}
|
||||
}
|
||||
|
||||
@ -520,3 +523,22 @@ func TestDuplicateFilesInsideArchive(t *testing.T) {
|
||||
require.NoError(t, a.Add("foo", ff.Name()))
|
||||
require.EqualError(t, a.Add("foo", ff.Name()), "file foo already exists in the archive")
|
||||
}
|
||||
|
||||
func TestWrapInDirectory(t *testing.T) {
|
||||
t.Run("false", func(t *testing.T) {
|
||||
require.Equal(t, "", wrapFolder(config.Archive{
|
||||
WrapInDirectory: "false",
|
||||
}))
|
||||
})
|
||||
t.Run("true", func(t *testing.T) {
|
||||
require.Equal(t, "foo", wrapFolder(config.Archive{
|
||||
WrapInDirectory: "true",
|
||||
NameTemplate: "foo",
|
||||
}))
|
||||
})
|
||||
t.Run("custom", func(t *testing.T) {
|
||||
require.Equal(t, "foobar", wrapFolder(config.Archive{
|
||||
WrapInDirectory: "foobar",
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ type Archive struct {
|
||||
|
||||
Format string `yaml:",omitempty"`
|
||||
FormatOverrides []FormatOverride `yaml:"format_overrides,omitempty"`
|
||||
WrapInDirectory bool `yaml:"wrap_in_directory,omitempty"`
|
||||
WrapInDirectory string `yaml:"wrap_in_directory,omitempty"`
|
||||
Files []string `yaml:",omitempty"`
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ archive:
|
||||
# If set to true and you extract the archive 'goreleaser_Linux_arm64.tar.gz',
|
||||
# you get a folder 'goreleaser_Linux_arm64'.
|
||||
# If set to false, all files are extracted separately.
|
||||
# You can also set it to a custom folder name.
|
||||
# Default is false.
|
||||
wrap_in_directory: true
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user