1
0
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:
Carlos Alexandro Becker 2022-07-27 09:55:55 -03:00 committed by GitHub
parent a02bcef337
commit 315935aedc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 6 deletions

View File

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

View File

@ -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"}})

View File

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