Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(archive): always strip parent if set #3256

Merged
merged 4 commits into from Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions internal/archivefiles/archivefiles.go
Expand Up @@ -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))
}
Expand Down
20 changes: 20 additions & 0 deletions internal/archivefiles/archivefiles_test.go
Expand Up @@ -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"}})

Expand Down
3 changes: 0 additions & 3 deletions www/docs/customization/archive.md
Expand Up @@ -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
Expand Down