1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-07 13:31:37 +02:00

fix: support multiple binaries in scoop pipe (#909)

* fix: support multiple binaries in scoop pipe

* fix: lint
This commit is contained in:
Carlos Alexandro Becker 2019-01-05 12:30:26 -02:00 committed by GitHub
parent 850205abf1
commit 23df4b562c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 27 deletions

View File

@ -109,9 +109,9 @@ type Manifest struct {
// Resource represents a combination of a url and a binary name for an architecture
type Resource struct {
URL string `json:"url"` // URL to the archive
Bin string `json:"bin"` // name of binary inside the archive
Hash string `json:"hash"` // the archive checksum
URL string `json:"url"` // URL to the archive
Bin []string `json:"bin"` // name of binary inside the archive
Hash string `json:"hash"` // the archive checksum
}
func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (bytes.Buffer, error) {
@ -145,7 +145,7 @@ func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (bytes.B
manifest.Architecture[arch] = Resource{
URL: url,
Bin: ctx.Config.Builds[0].Binary + ".exe", // TODO: this is wrong
Bin: binaries(artifact),
Hash: sum,
}
}
@ -157,3 +157,12 @@ func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (bytes.B
_, err = result.Write(data)
return result, err
}
func binaries(a artifact.Artifact) []string {
// nolint: prealloc
var bins []string
for _, b := range a.ExtraOr("Builds", []artifact.Artifact{}).([]artifact.Artifact) {
bins = append(bins, b.ExtraOr("Binary", "").(string)+".exe")
}
return bins
}

View File

@ -5,9 +5,8 @@ import (
"flag"
"io/ioutil"
"os"
"testing"
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client"
@ -403,9 +402,6 @@ func Test_buildManifest(t *testing.T) {
GitHubURLs: config.GitHubURLs{
Download: "https://github.com",
},
Builds: []config.Build{
{Binary: "test"},
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
@ -471,21 +467,61 @@ func Test_buildManifest(t *testing.T) {
}
for _, tt := range tests {
var ctx = tt.ctx
Pipe{}.Default(ctx)
out, err := buildManifest(ctx, []artifact.Artifact{
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
t.Run(tt.filename, func(t *testing.T) {
var ctx = tt.ctx
Pipe{}.Default(ctx)
out, err := buildManifest(ctx, []artifact.Artifact{
{
Name: "foo_1.0.1_windows_amd64.tar.gz",
Goos: "windows",
Goarch: "amd64",
Path: file,
Extra: map[string]interface{}{
"Builds": []artifact.Artifact{
{
Extra: map[string]interface{}{
"Binary": "foo",
},
},
{
Extra: map[string]interface{}{
"Binary": "bar",
},
},
},
},
},
{
Name: "foo_1.0.1_windows_386.tar.gz",
Goos: "windows",
Goarch: "386",
Path: file,
Extra: map[string]interface{}{
"Builds": []artifact.Artifact{
{
Extra: map[string]interface{}{
"Binary": "foo",
},
},
{
Extra: map[string]interface{}{
"Binary": "bar",
},
},
},
},
},
})
require.NoError(t, err)
if *update {
require.NoError(t, ioutil.WriteFile(tt.filename, out.Bytes(), 0655))
}
bts, err := ioutil.ReadFile(tt.filename)
require.NoError(t, err)
require.Equal(t, string(bts), out.String())
})
require.NoError(t, err)
if *update {
require.NoError(t, ioutil.WriteFile(tt.filename, out.Bytes(), 0655))
}
bts, err := ioutil.ReadFile(tt.filename)
require.NoError(t, err)
require.Equal(t, string(bts), out.String())
}
}

View File

@ -3,12 +3,18 @@
"architecture": {
"32bit": {
"url": "https://github.com/test/test/releases/download/v1.0.1/foo_1.0.1_windows_386.tar.gz",
"bin": "test.exe",
"bin": [
"foo.exe",
"bar.exe"
],
"hash": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"
},
"64bit": {
"url": "https://github.com/test/test/releases/download/v1.0.1/foo_1.0.1_windows_amd64.tar.gz",
"bin": "test.exe",
"bin": [
"foo.exe",
"bar.exe"
],
"hash": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"
}
},

View File

@ -3,12 +3,18 @@
"architecture": {
"32bit": {
"url": "http://github.mycompany.com/foo/bar/v1.0.1/foo_1.0.1_windows_386.tar.gz",
"bin": "test.exe",
"bin": [
"foo.exe",
"bar.exe"
],
"hash": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"
},
"64bit": {
"url": "http://github.mycompany.com/foo/bar/v1.0.1/foo_1.0.1_windows_amd64.tar.gz",
"bin": "test.exe",
"bin": [
"foo.exe",
"bar.exe"
],
"hash": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"
}
},