From a393262eb46e6e81cfc3edf956c1d1350b52b0fc Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 10 Oct 2021 10:52:25 -0300 Subject: [PATCH] feat: support multiple binaries on gofish (#2569) Signed-off-by: Carlos A Becker --- internal/pipe/gofish/food_template.go | 11 ++- internal/pipe/gofish/gofish.go | 1 + internal/pipe/gofish/gofish_test.go | 36 ++++--- .../gofish/testdata/TestFullFood.lua.golden | 94 +++++++++++++++---- .../testdata/TestFullFoodLinuxOnly.lua.golden | 48 ++++++++-- .../TestFullFoodWindowsOnly.lua.golden | 14 ++- .../testdata/TestFullPipe/default.lua.golden | 6 +- .../TestFullPipe/default_gitlab.lua.golden | 6 +- .../multiple_armv5.lua.golden | 18 ++-- .../multiple_armv6.lua.golden | 18 ++-- .../multiple_armv7.lua.golden | 18 ++-- .../TestRunPipeNameTemplate.lua.golden | 6 +- 12 files changed, 194 insertions(+), 82 deletions(-) diff --git a/internal/pipe/gofish/food_template.go b/internal/pipe/gofish/food_template.go index a6aca633a..a3a91e576 100644 --- a/internal/pipe/gofish/food_template.go +++ b/internal/pipe/gofish/food_template.go @@ -14,6 +14,7 @@ type releasePackage struct { SHA256 string OS string Arch string + Binaries []string } const foodTemplate = `local name = "{{ .Name }}" @@ -28,19 +29,21 @@ food = { packages = { {{- range $element := .ReleasePackages}} {{- if ne $element.OS ""}} - { + { os = "{{ $element.OS }}", arch = "{{ $element.Arch }}", url = "{{ $element.DownloadURL }}", sha256 = "{{ $element.SHA256 }}", resources = { + {{- range $binary := $element.Binaries }} { - path = {{if ne $element.OS "windows"}}name{{else}}name .. ".exe"{{end}}, - installpath = {{if ne $element.OS "windows"}}"bin/" .. name,{{else}}"bin\\" .. name .. ".exe"{{end}} + path = {{if ne $element.OS "windows"}}"{{ $binary }}"{{else}}"{{ $binary }}.exe"{{end}}, + installpath = {{if ne $element.OS "windows"}}"bin/{{ $binary }}"{{else}}"bin\\{{ $binary }}.exe"{{end}}, {{- if ne $element.OS "windows"}} executable = true - {{- end }} + {{- end }} } + {{- end }} } }, {{- end }} diff --git a/internal/pipe/gofish/gofish.go b/internal/pipe/gofish/gofish.go index eef343564..41becdf86 100644 --- a/internal/pipe/gofish/gofish.go +++ b/internal/pipe/gofish/gofish.go @@ -211,6 +211,7 @@ func dataFor(ctx *context.Context, cfg config.GoFish, cl client.Client, artifact SHA256: sum, OS: artifact.Goos, Arch: artifact.Goarch, + Binaries: artifact.ExtraOr("Binaries", []string{}).([]string), } for _, v := range result.ReleasePackages { if v.OS == artifact.Goos && v.Arch == artifact.Goarch { diff --git a/internal/pipe/gofish/gofish_test.go b/internal/pipe/gofish/gofish_test.go index 21e1d7a7a..2b66ea99a 100644 --- a/internal/pipe/gofish/gofish_test.go +++ b/internal/pipe/gofish/gofish_test.go @@ -30,36 +30,42 @@ func createTemplateData() templateData { OS: "darwin", DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz", SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68", + Binaries: []string{"bin1", "bin2", "bin3"}, }, { Arch: "arm64", OS: "darwin", DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz", SHA256: "1633f61598ab0791e213135923624eb342196b349490sadasdsadsadasdasdsd", + Binaries: []string{"bin1", "bin2", "bin3"}, }, { Arch: "amd64", OS: "linux", DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz", SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", + Binaries: []string{"bin1", "bin2", "bin3"}, }, { Arch: "arm", OS: "linux", DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz", SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", + Binaries: []string{"bin1", "bin2", "bin3"}, }, { Arch: "arm64", OS: "linux", DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz", SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", + Binaries: []string{"bin1", "bin2", "bin3"}, }, { Arch: "amd64", OS: "windows", DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_windows_amd64.zip", SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", + Binaries: []string{"bin1", "bin2", "bin3"}, }, }, Name: "Test", @@ -202,8 +208,9 @@ func TestFullPipe(t *testing.T) { Goarch: "amd64", Type: artifact.UploadableArchive, Extra: map[string]interface{}{ - "ID": "foo", - "Format": "tar.gz", + "ID": "foo", + "Format": "tar.gz", + "Binaries": []string{"name"}, }, }) @@ -266,8 +273,9 @@ func TestRunPipeNameTemplate(t *testing.T) { Goarch: "amd64", Type: artifact.UploadableArchive, Extra: map[string]interface{}{ - "ID": "foo", - "Format": "tar.gz", + "ID": "foo", + "Format": "tar.gz", + "Binaries": []string{"foo"}, }, }) @@ -344,8 +352,9 @@ func TestRunPipeMultipleGoFishWithSkip(t *testing.T) { Goarch: "amd64", Type: artifact.UploadableArchive, Extra: map[string]interface{}{ - "ID": "foo", - "Format": "tar.gz", + "ID": "foo", + "Format": "tar.gz", + "Binaries": []string{"foo"}, }, }) @@ -459,8 +468,9 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) { Goarm: a.goarm, Type: artifact.UploadableArchive, Extra: map[string]interface{}{ - "ID": a.name, - "Format": "tar.gz", + "ID": a.name, + "Format": "tar.gz", + "Binaries": []string{"foo"}, }, }) f, err := os.Create(path) @@ -636,8 +646,9 @@ func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) { Goarch: ttt.goarch, Type: artifact.UploadableArchive, Extra: map[string]interface{}{ - "ID": fmt.Sprintf("foo%d", idx), - "Format": "tar.gz", + "ID": fmt.Sprintf("foo%d", idx), + "Format": "tar.gz", + "Binaries": []string{"foo"}, }, }) } @@ -702,8 +713,9 @@ func TestRunPipeNoUpload(t *testing.T) { Goarch: "amd64", Type: artifact.UploadableArchive, Extra: map[string]interface{}{ - "ID": "foo", - "Format": "tar.gz", + "ID": "foo", + "Format": "tar.gz", + "Binaries": []string{"foo"}, }, }) client := client.NewMock() diff --git a/internal/pipe/gofish/testdata/TestFullFood.lua.golden b/internal/pipe/gofish/testdata/TestFullFood.lua.golden index e579630b6..f7b7cb6ed 100644 --- a/internal/pipe/gofish/testdata/TestFullFood.lua.golden +++ b/internal/pipe/gofish/testdata/TestFullFood.lua.golden @@ -8,80 +8,138 @@ food = { homepage = "https://google.com", version = version, packages = { - { + { os = "darwin", arch = "amd64", url = "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz", sha256 = "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68", resources = { { - path = name, - installpath = "bin/" .. name, + path = "bin1", + installpath = "bin/bin1", + executable = true + } + { + path = "bin2", + installpath = "bin/bin2", + executable = true + } + { + path = "bin3", + installpath = "bin/bin3", executable = true } } }, - { + { os = "darwin", arch = "arm64", url = "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz", sha256 = "1633f61598ab0791e213135923624eb342196b349490sadasdsadsadasdasdsd", resources = { { - path = name, - installpath = "bin/" .. name, + path = "bin1", + installpath = "bin/bin1", + executable = true + } + { + path = "bin2", + installpath = "bin/bin2", + executable = true + } + { + path = "bin3", + installpath = "bin/bin3", executable = true } } }, - { + { os = "linux", arch = "amd64", url = "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz", sha256 = "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", resources = { { - path = name, - installpath = "bin/" .. name, + path = "bin1", + installpath = "bin/bin1", + executable = true + } + { + path = "bin2", + installpath = "bin/bin2", + executable = true + } + { + path = "bin3", + installpath = "bin/bin3", executable = true } } }, - { + { os = "linux", arch = "arm", url = "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz", sha256 = "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", resources = { { - path = name, - installpath = "bin/" .. name, + path = "bin1", + installpath = "bin/bin1", + executable = true + } + { + path = "bin2", + installpath = "bin/bin2", + executable = true + } + { + path = "bin3", + installpath = "bin/bin3", executable = true } } }, - { + { os = "linux", arch = "arm64", url = "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz", sha256 = "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", resources = { { - path = name, - installpath = "bin/" .. name, + path = "bin1", + installpath = "bin/bin1", + executable = true + } + { + path = "bin2", + installpath = "bin/bin2", + executable = true + } + { + path = "bin3", + installpath = "bin/bin3", executable = true } } }, - { + { os = "windows", arch = "amd64", url = "https://github.com/caarlos0/test/releases/download/v0.1.3/test_windows_amd64.zip", sha256 = "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", resources = { { - path = name .. ".exe", - installpath = "bin\\" .. name .. ".exe" + path = "bin1.exe", + installpath = "bin\\bin1.exe", + } + { + path = "bin2.exe", + installpath = "bin\\bin2.exe", + } + { + path = "bin3.exe", + installpath = "bin\\bin3.exe", } } }, diff --git a/internal/pipe/gofish/testdata/TestFullFoodLinuxOnly.lua.golden b/internal/pipe/gofish/testdata/TestFullFoodLinuxOnly.lua.golden index c0629c189..959a1e9b6 100644 --- a/internal/pipe/gofish/testdata/TestFullFoodLinuxOnly.lua.golden +++ b/internal/pipe/gofish/testdata/TestFullFoodLinuxOnly.lua.golden @@ -8,41 +8,71 @@ food = { homepage = "https://google.com", version = version, packages = { - { + { os = "linux", arch = "amd64", url = "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz", sha256 = "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", resources = { { - path = name, - installpath = "bin/" .. name, + path = "bin1", + installpath = "bin/bin1", + executable = true + } + { + path = "bin2", + installpath = "bin/bin2", + executable = true + } + { + path = "bin3", + installpath = "bin/bin3", executable = true } } }, - { + { os = "linux", arch = "arm", url = "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz", sha256 = "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", resources = { { - path = name, - installpath = "bin/" .. name, + path = "bin1", + installpath = "bin/bin1", + executable = true + } + { + path = "bin2", + installpath = "bin/bin2", + executable = true + } + { + path = "bin3", + installpath = "bin/bin3", executable = true } } }, - { + { os = "linux", arch = "arm64", url = "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz", sha256 = "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", resources = { { - path = name, - installpath = "bin/" .. name, + path = "bin1", + installpath = "bin/bin1", + executable = true + } + { + path = "bin2", + installpath = "bin/bin2", + executable = true + } + { + path = "bin3", + installpath = "bin/bin3", executable = true } } diff --git a/internal/pipe/gofish/testdata/TestFullFoodWindowsOnly.lua.golden b/internal/pipe/gofish/testdata/TestFullFoodWindowsOnly.lua.golden index 2b98981d1..40a663032 100644 --- a/internal/pipe/gofish/testdata/TestFullFoodWindowsOnly.lua.golden +++ b/internal/pipe/gofish/testdata/TestFullFoodWindowsOnly.lua.golden @@ -8,15 +8,23 @@ food = { homepage = "https://google.com", version = version, packages = { - { + { os = "windows", arch = "amd64", url = "https://github.com/caarlos0/test/releases/download/v0.1.3/test_windows_amd64.zip", sha256 = "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", resources = { { - path = name .. ".exe", - installpath = "bin\\" .. name .. ".exe" + path = "bin1.exe", + installpath = "bin\\bin1.exe", + } + { + path = "bin2.exe", + installpath = "bin\\bin2.exe", + } + { + path = "bin3.exe", + installpath = "bin\\bin3.exe", } } }, diff --git a/internal/pipe/gofish/testdata/TestFullPipe/default.lua.golden b/internal/pipe/gofish/testdata/TestFullPipe/default.lua.golden index df249e05c..4ae0e21dd 100644 --- a/internal/pipe/gofish/testdata/TestFullPipe/default.lua.golden +++ b/internal/pipe/gofish/testdata/TestFullPipe/default.lua.golden @@ -8,15 +8,15 @@ food = { homepage = "https://github.com/goreleaser", version = version, packages = { - { + { os = "darwin", arch = "amd64", url = "https://dummyhost/download/v1.0.1/bin.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "name", + installpath = "bin/name", executable = true } } diff --git a/internal/pipe/gofish/testdata/TestFullPipe/default_gitlab.lua.golden b/internal/pipe/gofish/testdata/TestFullPipe/default_gitlab.lua.golden index 0b5745690..a642a846b 100644 --- a/internal/pipe/gofish/testdata/TestFullPipe/default_gitlab.lua.golden +++ b/internal/pipe/gofish/testdata/TestFullPipe/default_gitlab.lua.golden @@ -8,15 +8,15 @@ food = { homepage = "https://gitlab.com/goreleaser", version = version, packages = { - { + { os = "darwin", arch = "amd64", url = "https://dummyhost/download/v1.0.1/bin.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "name", + installpath = "bin/name", executable = true } } diff --git a/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.lua.golden b/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.lua.golden index 0450d7f8b..230b57675 100644 --- a/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.lua.golden +++ b/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.lua.golden @@ -8,41 +8,41 @@ food = { homepage = "https://github.com/goreleaser", version = version, packages = { - { + { os = "darwin", arch = "amd64", url = "https://dummyhost/download/v1.0.1/bin.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "foo", + installpath = "bin/foo", executable = true } } }, - { + { os = "linux", arch = "arm64", url = "https://dummyhost/download/v1.0.1/arm64.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "foo", + installpath = "bin/foo", executable = true } } }, - { + { os = "linux", arch = "arm", url = "https://dummyhost/download/v1.0.1/armv5.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "foo", + installpath = "bin/foo", executable = true } } diff --git a/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.lua.golden b/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.lua.golden index 317153459..c4460814d 100644 --- a/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.lua.golden +++ b/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.lua.golden @@ -8,41 +8,41 @@ food = { homepage = "https://github.com/goreleaser", version = version, packages = { - { + { os = "darwin", arch = "amd64", url = "https://dummyhost/download/v1.0.1/bin.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "foo", + installpath = "bin/foo", executable = true } } }, - { + { os = "linux", arch = "arm64", url = "https://dummyhost/download/v1.0.1/arm64.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "foo", + installpath = "bin/foo", executable = true } } }, - { + { os = "linux", arch = "arm", url = "https://dummyhost/download/v1.0.1/armv6.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "foo", + installpath = "bin/foo", executable = true } } diff --git a/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.lua.golden b/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.lua.golden index b13c1bf11..667493332 100644 --- a/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.lua.golden +++ b/internal/pipe/gofish/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.lua.golden @@ -8,41 +8,41 @@ food = { homepage = "https://github.com/goreleaser", version = version, packages = { - { + { os = "darwin", arch = "amd64", url = "https://dummyhost/download/v1.0.1/bin.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "foo", + installpath = "bin/foo", executable = true } } }, - { + { os = "linux", arch = "arm64", url = "https://dummyhost/download/v1.0.1/arm64.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "foo", + installpath = "bin/foo", executable = true } } }, - { + { os = "linux", arch = "arm", url = "https://dummyhost/download/v1.0.1/armv7.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "foo", + installpath = "bin/foo", executable = true } } diff --git a/internal/pipe/gofish/testdata/TestRunPipeNameTemplate.lua.golden b/internal/pipe/gofish/testdata/TestRunPipeNameTemplate.lua.golden index e773c658f..4bc889dd7 100644 --- a/internal/pipe/gofish/testdata/TestRunPipeNameTemplate.lua.golden +++ b/internal/pipe/gofish/testdata/TestRunPipeNameTemplate.lua.golden @@ -8,15 +8,15 @@ food = { homepage = "", version = version, packages = { - { + { os = "darwin", arch = "amd64", url = "https://dummyhost/download/v1.0.1/bin.tar.gz", sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", resources = { { - path = name, - installpath = "bin/" .. name, + path = "foo", + installpath = "bin/foo", executable = true } }