2022-05-11 22:56:25 -03:00
|
|
|
package archivefiles
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2024-05-26 15:02:57 -03:00
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/testctx"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/testlib"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/tmpl"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/pkg/config"
|
2022-05-11 22:56:25 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEval(t *testing.T) {
|
|
|
|
now := time.Now().Truncate(time.Second)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
Env: []string{"OWNER=carlos", "FOLDER=d"},
|
2022-12-14 12:16:43 -03:00
|
|
|
})
|
|
|
|
ctx.Git.CommitDate = now
|
|
|
|
tmpl := tmpl.New(ctx)
|
|
|
|
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
t.Run("invalid glob", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
_, err := Eval(tmpl, []config.File{
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
{
|
|
|
|
Source: "../testdata/**/nope.txt",
|
|
|
|
Destination: "var/foobar/d.txt",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("templated src", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
result, err := Eval(tmpl, []config.File{
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
{
|
|
|
|
Source: "./testdata/**/{{ .Env.FOLDER }}.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "var/foobar/",
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []config.File{
|
|
|
|
{
|
|
|
|
Source: "testdata/a/b/c/d.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "var/foobar/d.txt",
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
},
|
|
|
|
}, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("templated src error", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
_, err := Eval(tmpl, []config.File{
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
{
|
|
|
|
Source: "./testdata/**/{{ .Env.NOPE }}.txt",
|
|
|
|
Destination: "var/foobar/d.txt",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
testlib.RequireTemplateError(t, err)
|
|
|
|
})
|
|
|
|
|
2022-12-14 12:16:43 -03:00
|
|
|
t.Run("templated info", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
result, err := Eval(tmpl, []config.File{
|
2022-12-14 12:16:43 -03:00
|
|
|
{
|
|
|
|
Source: "./testdata/**/d.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "var/foobar/",
|
2022-12-14 12:16:43 -03:00
|
|
|
Info: config.FileInfo{
|
|
|
|
MTime: "{{.CommitDate}}",
|
|
|
|
Owner: "{{ .Env.OWNER }}",
|
|
|
|
Group: "{{ .Env.OWNER }}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []config.File{
|
|
|
|
{
|
|
|
|
Source: "testdata/a/b/c/d.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "var/foobar/d.txt",
|
2022-12-14 12:16:43 -03:00
|
|
|
Info: config.FileInfo{
|
|
|
|
MTime: now.UTC().Format(time.RFC3339),
|
|
|
|
ParsedMTime: now.UTC(),
|
|
|
|
Owner: "carlos",
|
|
|
|
Group: "carlos",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("template info errors", func(t *testing.T) {
|
|
|
|
t.Run("owner", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
_, err := Eval(tmpl, []config.File{{
|
2022-12-14 12:16:43 -03:00
|
|
|
Source: "./testdata/**/d.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "var/foobar",
|
2022-12-14 12:16:43 -03:00
|
|
|
Info: config.FileInfo{
|
|
|
|
Owner: "{{ .Env.NOPE }}",
|
|
|
|
},
|
|
|
|
}})
|
|
|
|
testlib.RequireTemplateError(t, err)
|
|
|
|
})
|
|
|
|
t.Run("group", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
_, err := Eval(tmpl, []config.File{{
|
2022-12-14 12:16:43 -03:00
|
|
|
Source: "./testdata/**/d.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "var/foobar",
|
2022-12-14 12:16:43 -03:00
|
|
|
Info: config.FileInfo{
|
|
|
|
Group: "{{ .Env.NOPE }}",
|
|
|
|
},
|
|
|
|
}})
|
|
|
|
testlib.RequireTemplateError(t, err)
|
|
|
|
})
|
|
|
|
t.Run("mtime", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
_, err := Eval(tmpl, []config.File{{
|
2022-12-14 12:16:43 -03:00
|
|
|
Source: "./testdata/**/d.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "var/foobar",
|
2022-12-14 12:16:43 -03:00
|
|
|
Info: config.FileInfo{
|
|
|
|
MTime: "{{ .Env.NOPE }}",
|
|
|
|
},
|
|
|
|
}})
|
|
|
|
testlib.RequireTemplateError(t, err)
|
|
|
|
})
|
|
|
|
t.Run("mtime format", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
_, err := Eval(tmpl, []config.File{{
|
2022-12-14 12:16:43 -03:00
|
|
|
Source: "./testdata/**/d.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "var/foobar",
|
2022-12-14 12:16:43 -03:00
|
|
|
Info: config.FileInfo{
|
|
|
|
MTime: "2005-123-123",
|
|
|
|
},
|
|
|
|
}})
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
})
|
2022-05-11 22:56:25 -03:00
|
|
|
|
|
|
|
t.Run("single file", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
result, err := Eval(tmpl, []config.File{
|
2022-05-11 22:56:25 -03:00
|
|
|
{
|
|
|
|
Source: "./testdata/**/d.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "var/foobar",
|
2022-05-11 22:56:25 -03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []config.File{
|
|
|
|
{
|
|
|
|
Source: "testdata/a/b/c/d.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "var/foobar/d.txt",
|
2022-05-11 22:56:25 -03:00
|
|
|
},
|
|
|
|
}, result)
|
|
|
|
})
|
|
|
|
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
t.Run("rlcp", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
result, err := Eval(tmpl, []config.File{{
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
Source: "./testdata/a/**/*",
|
|
|
|
Destination: "foo/bar",
|
|
|
|
}})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []config.File{
|
|
|
|
{Source: "testdata/a/b/a.txt", Destination: "foo/bar/a.txt"},
|
|
|
|
{Source: "testdata/a/b/c/d.txt", Destination: "foo/bar/c/d.txt"},
|
|
|
|
}, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("rlcp empty destination", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
result, err := Eval(tmpl, []config.File{{
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
Source: "./testdata/a/**/*",
|
|
|
|
}})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []config.File{
|
|
|
|
{Source: "testdata/a/b/a.txt", Destination: "testdata/a/b/a.txt"},
|
|
|
|
{Source: "testdata/a/b/c/d.txt", Destination: "testdata/a/b/c/d.txt"},
|
|
|
|
}, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("rlcp no results", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
result, err := Eval(tmpl, []config.File{{
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
Source: "./testdata/abc/**/*",
|
|
|
|
Destination: "foo/bar",
|
|
|
|
}})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, result)
|
|
|
|
})
|
|
|
|
|
2022-07-27 09:55:55 -03:00
|
|
|
t.Run("strip parent plays nicely with destination omitted", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
result, err := Eval(tmpl, []config.File{{Source: "./testdata/a/b", StripParent: true}})
|
2022-07-27 09:55:55 -03:00
|
|
|
|
|
|
|
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) {
|
2023-06-06 13:54:43 -03:00
|
|
|
result, err := Eval(tmpl, []config.File{{Source: "./testdata/a/b", Destination: "", StripParent: true}})
|
2022-07-27 09:55:55 -03:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2022-05-11 22:56:25 -03:00
|
|
|
t.Run("match multiple files within tree without destination", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
result, err := Eval(tmpl, []config.File{{Source: "./testdata/a"}})
|
2022-05-11 22:56:25 -03:00
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []config.File{
|
|
|
|
{Source: "testdata/a/a.txt", Destination: "testdata/a/a.txt"},
|
|
|
|
{Source: "testdata/a/b/a.txt", Destination: "testdata/a/b/a.txt"},
|
|
|
|
{Source: "testdata/a/b/c/d.txt", Destination: "testdata/a/b/c/d.txt"},
|
|
|
|
}, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("match multiple files within tree specific destination", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
result, err := Eval(tmpl, []config.File{
|
2022-05-11 22:56:25 -03:00
|
|
|
{
|
|
|
|
Source: "./testdata/a",
|
|
|
|
Destination: "usr/local/test",
|
|
|
|
Info: config.FileInfo{
|
2022-12-14 12:16:43 -03:00
|
|
|
Owner: "carlos",
|
|
|
|
Group: "users",
|
|
|
|
Mode: 0o755,
|
|
|
|
ParsedMTime: now,
|
2022-05-11 22:56:25 -03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []config.File{
|
|
|
|
{
|
|
|
|
Source: "testdata/a/a.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "usr/local/test/a.txt",
|
2022-05-11 22:56:25 -03:00
|
|
|
Info: config.FileInfo{
|
2022-12-14 12:16:43 -03:00
|
|
|
Owner: "carlos",
|
|
|
|
Group: "users",
|
|
|
|
Mode: 0o755,
|
|
|
|
ParsedMTime: now,
|
2022-05-11 22:56:25 -03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: "testdata/a/b/a.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "usr/local/test/b/a.txt",
|
2022-05-11 22:56:25 -03:00
|
|
|
Info: config.FileInfo{
|
2022-12-14 12:16:43 -03:00
|
|
|
Owner: "carlos",
|
|
|
|
Group: "users",
|
|
|
|
Mode: 0o755,
|
|
|
|
ParsedMTime: now,
|
2022-05-11 22:56:25 -03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: "testdata/a/b/c/d.txt",
|
2023-06-06 13:54:43 -03:00
|
|
|
Destination: "usr/local/test/b/c/d.txt",
|
2022-05-11 22:56:25 -03:00
|
|
|
Info: config.FileInfo{
|
2022-12-14 12:16:43 -03:00
|
|
|
Owner: "carlos",
|
|
|
|
Group: "users",
|
|
|
|
Mode: 0o755,
|
|
|
|
ParsedMTime: now,
|
2022-05-11 22:56:25 -03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("match multiple files within tree specific destination stripping parents", func(t *testing.T) {
|
2023-06-06 13:54:43 -03:00
|
|
|
result, err := Eval(tmpl, []config.File{
|
2022-05-11 22:56:25 -03:00
|
|
|
{
|
|
|
|
Source: "./testdata/a",
|
|
|
|
Destination: "usr/local/test",
|
|
|
|
StripParent: true,
|
|
|
|
Info: config.FileInfo{
|
2022-12-14 12:16:43 -03:00
|
|
|
Owner: "carlos",
|
|
|
|
Group: "users",
|
|
|
|
Mode: 0o755,
|
|
|
|
ParsedMTime: now,
|
2022-05-11 22:56:25 -03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []config.File{
|
|
|
|
{
|
|
|
|
Source: "testdata/a/a.txt",
|
|
|
|
Destination: "usr/local/test/a.txt",
|
|
|
|
Info: config.FileInfo{
|
2022-12-14 12:16:43 -03:00
|
|
|
Owner: "carlos",
|
|
|
|
Group: "users",
|
|
|
|
Mode: 0o755,
|
|
|
|
ParsedMTime: now,
|
2022-05-11 22:56:25 -03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: "testdata/a/b/c/d.txt",
|
|
|
|
Destination: "usr/local/test/d.txt",
|
|
|
|
Info: config.FileInfo{
|
2022-12-14 12:16:43 -03:00
|
|
|
Owner: "carlos",
|
|
|
|
Group: "users",
|
|
|
|
Mode: 0o755,
|
|
|
|
ParsedMTime: now,
|
2022-05-11 22:56:25 -03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}, result)
|
|
|
|
})
|
|
|
|
}
|
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
|
|
|
|
|
|
|
func TestStrlcp(t *testing.T) {
|
|
|
|
for k, v := range map[string][2]string{
|
|
|
|
"/var/": {"/var/lib/foo", "/var/share/aaa"},
|
|
|
|
"/var/lib/": {"/var/lib/foo", "/var/lib/share/aaa"},
|
|
|
|
"/usr/share/": {"/usr/share/lib", "/usr/share/bin"},
|
|
|
|
"/usr/": {"/usr/share/lib", "/usr/bin"},
|
|
|
|
} {
|
|
|
|
t.Run(k, func(t *testing.T) {
|
|
|
|
require.Equal(t, k, strlcp(v[0], v[1]))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|