mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-18 03:56:52 +02:00
feat(gofish): support binary releases (#2577)
* feat(gofish): support binary releases Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: improve code Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
parent
cbb567ca74
commit
f4cef96055
@ -92,14 +92,13 @@ func (t Type) String() string {
|
||||
}
|
||||
|
||||
const (
|
||||
ExtraID = "ID"
|
||||
ExtraBinary = "Binary"
|
||||
ExtraExt = "Ext"
|
||||
ExtraBuilds = "Builds"
|
||||
ExtraFormat = "Format"
|
||||
ExtraWrappedIn = "WrappedIn"
|
||||
ExtraBinaries = "Binaries"
|
||||
ExtraBinariesClean = "BinariesClean"
|
||||
ExtraID = "ID"
|
||||
ExtraBinary = "Binary"
|
||||
ExtraExt = "Ext"
|
||||
ExtraBuilds = "Builds"
|
||||
ExtraFormat = "Format"
|
||||
ExtraWrappedIn = "WrappedIn"
|
||||
ExtraBinaries = "Binaries"
|
||||
)
|
||||
|
||||
// Artifact represents an artifact and its relevant info.
|
||||
|
@ -193,12 +193,11 @@ func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Arti
|
||||
Goarm: binaries[0].Goarm,
|
||||
Gomips: binaries[0].Gomips,
|
||||
Extra: map[string]interface{}{
|
||||
artifact.ExtraBuilds: binaries,
|
||||
artifact.ExtraID: arch.ID,
|
||||
artifact.ExtraFormat: arch.Format,
|
||||
artifact.ExtraWrappedIn: wrap,
|
||||
artifact.ExtraBinaries: bins,
|
||||
artifact.ExtraBinariesClean: bins,
|
||||
artifact.ExtraBuilds: binaries,
|
||||
artifact.ExtraID: arch.ID,
|
||||
artifact.ExtraFormat: arch.Format,
|
||||
artifact.ExtraWrappedIn: wrap,
|
||||
artifact.ExtraBinaries: bins,
|
||||
},
|
||||
})
|
||||
return nil
|
||||
@ -236,11 +235,10 @@ func skip(ctx *context.Context, archive config.Archive, binaries []*artifact.Art
|
||||
Goarm: binary.Goarm,
|
||||
Gomips: binary.Gomips,
|
||||
Extra: map[string]interface{}{
|
||||
artifact.ExtraBuilds: []*artifact.Artifact{binary},
|
||||
artifact.ExtraID: archive.ID,
|
||||
artifact.ExtraFormat: archive.Format,
|
||||
artifact.ExtraBinariesClean: []string{binary.Name},
|
||||
artifact.ExtraBinaries: []string{finalName},
|
||||
artifact.ExtraBuilds: []*artifact.Artifact{binary},
|
||||
artifact.ExtraID: archive.ID,
|
||||
artifact.ExtraFormat: archive.Format,
|
||||
artifact.ExtraBinary: binary.Name,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ func TestRunPipe(t *testing.T) {
|
||||
}
|
||||
require.Equal(t, "myid", arch.ID(), "all archives must have the archive ID set")
|
||||
require.Equal(t, []string{expectBin}, arch.ExtraOr(artifact.ExtraBinaries, []string{}).([]string))
|
||||
require.Equal(t, []string{expectBin}, arch.ExtraOr(artifact.ExtraBinariesClean, []string{}).([]string))
|
||||
require.Equal(t, "", arch.ExtraOr(artifact.ExtraBinary, "").(string))
|
||||
}
|
||||
require.Len(t, archives, 6)
|
||||
// TODO: should verify the artifact fields here too
|
||||
@ -401,13 +401,13 @@ func TestRunPipeBinary(t *testing.T) {
|
||||
windows := binaries.Filter(artifact.ByGoos("windows")).List()[0]
|
||||
require.Equal(t, "mybin_0.0.1_darwin_amd64", darwinThin.Name)
|
||||
require.Equal(t, []string{"mybin_0.0.1_darwin_amd64"}, darwinThin.ExtraOr(artifact.ExtraBinaries, []string{}))
|
||||
require.Equal(t, []string{"mybin"}, darwinThin.ExtraOr(artifact.ExtraBinariesClean, []string{}))
|
||||
require.Equal(t, "mybin", darwinThin.ExtraOr(artifact.ExtraBinary, ""))
|
||||
require.Equal(t, "myunibin_0.0.1_darwin_all", darwinUniversal.Name)
|
||||
require.Equal(t, []string{"myunibin_0.0.1_darwin_all"}, darwinUniversal.ExtraOr(artifact.ExtraBinaries, []string{}))
|
||||
require.Equal(t, []string{"myunibin"}, darwinUniversal.ExtraOr(artifact.ExtraBinariesClean, []string{}))
|
||||
require.Equal(t, "myunibin", darwinUniversal.ExtraOr(artifact.ExtraBinary, ""))
|
||||
require.Equal(t, "mybin_0.0.1_windows_amd64.exe", windows.Name)
|
||||
require.Equal(t, []string{"mybin_0.0.1_windows_amd64.exe"}, windows.ExtraOr(artifact.ExtraBinaries, []string{}))
|
||||
require.Equal(t, []string{"mybin.exe"}, windows.ExtraOr(artifact.ExtraBinariesClean, []string{}))
|
||||
require.Equal(t, "mybin.exe", windows.ExtraOr(artifact.ExtraBinary, ""))
|
||||
}
|
||||
|
||||
func TestRunPipeDistRemoved(t *testing.T) {
|
||||
|
@ -14,7 +14,11 @@ type releasePackage struct {
|
||||
SHA256 string
|
||||
OS string
|
||||
Arch string
|
||||
Binaries []string
|
||||
Binaries []binary
|
||||
}
|
||||
|
||||
type binary struct {
|
||||
Name, Target string
|
||||
}
|
||||
|
||||
const foodTemplate = `local name = "{{ .Name }}"
|
||||
@ -37,8 +41,8 @@ food = {
|
||||
resources = {
|
||||
{{- range $binary := $element.Binaries }}
|
||||
{
|
||||
path = "{{ $binary }}",
|
||||
installpath = {{if ne $element.OS "windows"}}"bin/{{ $binary }}"{{else}}"bin\\{{ $binary }}"{{end}},
|
||||
path = "{{ $binary.Name }}",
|
||||
installpath = {{if ne $element.OS "windows"}}"bin/{{ $binary.Target }}"{{else}}"bin\\{{ $binary.Target }}"{{end}},
|
||||
{{- if ne $element.OS "windows"}}
|
||||
executable = true
|
||||
{{- end }}
|
||||
|
@ -97,7 +97,10 @@ func doRun(ctx *context.Context, goFish config.GoFish, cl client.Client) error {
|
||||
artifact.ByGoarm(goFish.Goarm),
|
||||
),
|
||||
),
|
||||
artifact.ByType(artifact.UploadableArchive),
|
||||
artifact.Or(
|
||||
artifact.ByType(artifact.UploadableArchive),
|
||||
artifact.ByType(artifact.UploadableBinary),
|
||||
),
|
||||
}
|
||||
if len(goFish.IDs) > 0 {
|
||||
filters = append(filters, artifact.ByIDs(goFish.IDs...))
|
||||
@ -219,7 +222,21 @@ func dataFor(ctx *context.Context, cfg config.GoFish, cl client.Client, artifact
|
||||
SHA256: sum,
|
||||
OS: art.Goos,
|
||||
Arch: arch,
|
||||
Binaries: art.ExtraOr(artifact.ExtraBinaries, []string{}).([]string),
|
||||
Binaries: []binary{},
|
||||
}
|
||||
switch art.Type {
|
||||
case artifact.UploadableArchive:
|
||||
for _, bin := range art.ExtraOr(artifact.ExtraBinaries, []string{}).([]string) {
|
||||
releasePackage.Binaries = append(releasePackage.Binaries, binary{
|
||||
Name: bin,
|
||||
Target: bin,
|
||||
})
|
||||
}
|
||||
case artifact.UploadableBinary:
|
||||
releasePackage.Binaries = append(releasePackage.Binaries, binary{
|
||||
Name: art.Name,
|
||||
Target: art.ExtraOr(artifact.ExtraBinary, art.Name).(string),
|
||||
})
|
||||
}
|
||||
for _, v := range result.ReleasePackages {
|
||||
if v.OS == art.Goos && v.Arch == art.Goarch {
|
||||
|
@ -21,6 +21,13 @@ func TestDescription(t *testing.T) {
|
||||
}
|
||||
|
||||
func createTemplateData() templateData {
|
||||
binaries := func(ext string) []binary {
|
||||
return []binary{
|
||||
{Name: "bin1" + ext, Target: "bin1" + ext},
|
||||
{Name: "bin2" + ext, Target: "bin2" + ext},
|
||||
{Name: "bin3" + ext, Target: "bin3" + ext},
|
||||
}
|
||||
}
|
||||
return templateData{
|
||||
Desc: "Some desc",
|
||||
Homepage: "https://google.com",
|
||||
@ -30,42 +37,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"},
|
||||
Binaries: binaries(""),
|
||||
},
|
||||
{
|
||||
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"},
|
||||
Binaries: binaries(""),
|
||||
},
|
||||
{
|
||||
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"},
|
||||
Binaries: binaries(""),
|
||||
},
|
||||
{
|
||||
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"},
|
||||
Binaries: binaries(""),
|
||||
},
|
||||
{
|
||||
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"},
|
||||
Binaries: binaries(""),
|
||||
},
|
||||
{
|
||||
Arch: "amd64",
|
||||
OS: "windows",
|
||||
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_windows_amd64.zip",
|
||||
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
|
||||
Binaries: []string{"bin1.exe", "bin2.exe", "bin3.exe"},
|
||||
Binaries: binaries(".exe"),
|
||||
},
|
||||
},
|
||||
Name: "Test",
|
||||
@ -715,10 +722,19 @@ func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunPipeBinaryRelease(t *testing.T) {
|
||||
ctx := context.New(
|
||||
config.Project{
|
||||
folder := t.TempDir()
|
||||
ctx := &context.Context{
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.2.1",
|
||||
},
|
||||
Version: "1.2.1",
|
||||
Artifacts: artifact.New(),
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: "foo",
|
||||
Rigs: []config.GoFish{
|
||||
{
|
||||
Name: "foo",
|
||||
Rig: config.RepoRef{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
@ -726,17 +742,32 @@ func TestRunPipeBinaryRelease(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
path := filepath.Join(folder, "dist/foo_darwin_all/foo")
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
Name: "bin",
|
||||
Path: "doesnt mather",
|
||||
Name: "foo_macos",
|
||||
Path: path,
|
||||
Goos: "darwin",
|
||||
Goarch: "amd64",
|
||||
Type: artifact.Binary,
|
||||
Goarch: "all",
|
||||
Type: artifact.UploadableBinary,
|
||||
Extra: map[string]interface{}{
|
||||
artifact.ExtraID: "foo",
|
||||
artifact.ExtraFormat: "binary",
|
||||
artifact.ExtraBinary: "foo",
|
||||
},
|
||||
})
|
||||
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
|
||||
f, err := os.Create(path)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
|
||||
client := client.NewMock()
|
||||
require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
|
||||
require.False(t, client.CreatedFile)
|
||||
require.NoError(t, runAll(ctx, client))
|
||||
require.NoError(t, publishAll(ctx, client))
|
||||
require.True(t, client.CreatedFile)
|
||||
golden.RequireEqualRb(t, []byte(client.Content))
|
||||
}
|
||||
|
||||
func TestRunPipeNoUpload(t *testing.T) {
|
||||
|
38
internal/pipe/gofish/testdata/TestRunPipeBinaryRelease.rb.golden
vendored
Normal file
38
internal/pipe/gofish/testdata/TestRunPipeBinaryRelease.rb.golden
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
local name = "foo"
|
||||
local version = "1.2.1"
|
||||
|
||||
food = {
|
||||
name = name,
|
||||
description = "",
|
||||
license = "",
|
||||
homepage = "",
|
||||
version = version,
|
||||
packages = {
|
||||
{
|
||||
os = "darwin",
|
||||
arch = "amd64",
|
||||
url = "https://dummyhost/download/v1.2.1/foo_macos",
|
||||
sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||
resources = {
|
||||
{
|
||||
path = "foo_macos",
|
||||
installpath = "bin/foo",
|
||||
executable = true
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
os = "darwin",
|
||||
arch = "arm64",
|
||||
url = "https://dummyhost/download/v1.2.1/foo_macos",
|
||||
sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||
resources = {
|
||||
{
|
||||
path = "foo_macos",
|
||||
installpath = "bin/foo",
|
||||
executable = true
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user