mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
fix(archive): always strip parent if set (#3256)
* Always strip parents. * refactor: improve code a bit Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * refactor: even simpler Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> Co-authored-by: Nathan Hammond <nathan.hammond@vercel.com>
This commit is contained in:
parent
a02bcef337
commit
315935aedc
@ -64,9 +64,6 @@ func unique(in []config.File) []config.File {
|
||||
}
|
||||
|
||||
func destinationFor(f config.File, path string) string {
|
||||
if f.Destination == "" {
|
||||
return path
|
||||
}
|
||||
if f.StripParent {
|
||||
return filepath.Join(f.Destination, filepath.Base(path))
|
||||
}
|
||||
|
@ -31,6 +31,26 @@ func TestEval(t *testing.T) {
|
||||
}, result)
|
||||
})
|
||||
|
||||
t.Run("strip parent plays nicely with destination omitted", func(t *testing.T) {
|
||||
result, err := Eval(tmpl, []config.File{{Source: "./testdata/a/b", StripParent: true}})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []config.File{
|
||||
{Source: "testdata/a/b/a.txt", Destination: "a.txt"},
|
||||
{Source: "testdata/a/b/c/d.txt", Destination: "d.txt"},
|
||||
}, result)
|
||||
})
|
||||
|
||||
t.Run("strip parent plays nicely with destination as an empty string", func(t *testing.T) {
|
||||
result, err := Eval(tmpl, []config.File{{Source: "./testdata/a/b", Destination: "", StripParent: true}})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []config.File{
|
||||
{Source: "testdata/a/b/a.txt", Destination: "a.txt"},
|
||||
{Source: "testdata/a/b/c/d.txt", Destination: "d.txt"},
|
||||
}, result)
|
||||
})
|
||||
|
||||
t.Run("match multiple files within tree without destination", func(t *testing.T) {
|
||||
result, err := Eval(tmpl, []config.File{{Source: "./testdata/a"}})
|
||||
|
||||
|
@ -142,9 +142,6 @@ files:
|
||||
# ...
|
||||
```
|
||||
|
||||
!!! warning
|
||||
`strip_parent` is only effective if `dst` is not empty.
|
||||
|
||||
## Packaging only the binaries
|
||||
|
||||
Since GoReleaser will always add the `README` and `LICENSE` files to the
|
||||
|
Loading…
x
Reference in New Issue
Block a user