mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
fix: scoop wrap_in_directory (#1458)
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
parent
f0cc74521c
commit
fc1ef8a2a2
@ -170,9 +170,10 @@ func create(ctx *context.Context, archive config.Archive, binaries []*artifact.A
|
||||
Goarm: binaries[0].Goarm,
|
||||
Gomips: binaries[0].Gomips,
|
||||
Extra: map[string]interface{}{
|
||||
"Builds": binaries,
|
||||
"ID": archive.ID,
|
||||
"Format": archive.Format,
|
||||
"Builds": binaries,
|
||||
"ID": archive.ID,
|
||||
"Format": archive.Format,
|
||||
"WrappedIn": wrap,
|
||||
},
|
||||
})
|
||||
return nil
|
||||
|
@ -494,6 +494,10 @@ func TestRunPipeWrap(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
|
||||
var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List()
|
||||
require.Len(t, archives, 1)
|
||||
require.Equal(t, "foo_macOS", archives[0].ExtraOr("WrappedIn", ""))
|
||||
|
||||
// Check archive contents
|
||||
f, err := os.Open(filepath.Join(dist, "foo.tar.gz"))
|
||||
require.NoError(t, err)
|
||||
@ -648,11 +652,12 @@ func TestBinaryOverride(t *testing.T) {
|
||||
darwin := archives.Filter(artifact.ByGoos("darwin")).List()[0]
|
||||
require.Equal(tt, "foobar_0.0.1_darwin_amd64."+format, darwin.Name)
|
||||
require.Equal(tt, format, darwin.ExtraOr("Format", ""))
|
||||
require.Empty(tt, darwin.ExtraOr("WrappedIn", ""))
|
||||
|
||||
archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableBinary))
|
||||
windows := archives.Filter(artifact.ByGoos("windows")).List()[0]
|
||||
require.Equal(tt, "foobar_0.0.1_windows_amd64.exe", windows.Name)
|
||||
require.Equal(tt, format, windows.ExtraOr("Format", ""))
|
||||
require.Empty(tt, windows.ExtraOr("WrappedIn", ""))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
@ -196,8 +197,9 @@ func buildManifest(ctx *context.Context, artifacts []*artifact.Artifact) (bytes.
|
||||
func binaries(a *artifact.Artifact) []string {
|
||||
// nolint: prealloc
|
||||
var bins []string
|
||||
var wrap = a.ExtraOr("WrappedIn", "").(string)
|
||||
for _, b := range a.ExtraOr("Builds", []*artifact.Artifact{}).([]*artifact.Artifact) {
|
||||
bins = append(bins, b.Name)
|
||||
bins = append(bins, filepath.Join(wrap, b.Name))
|
||||
}
|
||||
return bins
|
||||
}
|
||||
|
@ -128,6 +128,65 @@ func Test_doRun(t *testing.T) {
|
||||
},
|
||||
shouldNotErr,
|
||||
},
|
||||
{
|
||||
"wrap in directory",
|
||||
args{
|
||||
&context.Context{
|
||||
TokenType: context.TokenTypeGitHub,
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.0.1",
|
||||
},
|
||||
Version: "1.0.1",
|
||||
Artifacts: artifact.New(),
|
||||
Config: config.Project{
|
||||
Builds: []config.Build{
|
||||
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
|
||||
},
|
||||
Dist: ".",
|
||||
ProjectName: "run-pipe",
|
||||
Archives: []config.Archive{
|
||||
{Format: "tar.gz", WrapInDirectory: "true"},
|
||||
},
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
},
|
||||
Scoop: config.Scoop{
|
||||
Bucket: config.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
Description: "A run pipe test formula",
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
},
|
||||
},
|
||||
},
|
||||
&DummyClient{},
|
||||
},
|
||||
[]*artifact.Artifact{
|
||||
{
|
||||
Name: "foo_1.0.1_windows_amd64.tar.gz",
|
||||
Goos: "windows",
|
||||
Goarch: "amd64",
|
||||
Path: file,
|
||||
Extra: map[string]interface{}{
|
||||
"Wrap": "foo_1.0.1_windows_amd64",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "foo_1.0.1_windows_386.tar.gz",
|
||||
Goos: "windows",
|
||||
Goarch: "386",
|
||||
Path: file,
|
||||
Extra: map[string]interface{}{
|
||||
"Wrap": "foo_1.0.1_windows_386",
|
||||
},
|
||||
},
|
||||
},
|
||||
shouldNotErr,
|
||||
},
|
||||
{
|
||||
"valid enterprise github",
|
||||
args{
|
||||
@ -864,6 +923,81 @@ func Test_buildManifest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrapInDirectory(t *testing.T) {
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
require.NoError(t, err)
|
||||
var file = filepath.Join(folder, "archive")
|
||||
require.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
|
||||
var ctx = &context.Context{
|
||||
TokenType: context.TokenTypeGitLab,
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.0.1",
|
||||
},
|
||||
Version: "1.0.1",
|
||||
Artifacts: artifact.New(),
|
||||
Config: config.Project{
|
||||
GitLabURLs: config.GitLabURLs{
|
||||
Download: "https://gitlab.com",
|
||||
},
|
||||
Builds: []config.Build{
|
||||
{Binary: "test"},
|
||||
},
|
||||
Dist: ".",
|
||||
ProjectName: "run-pipe",
|
||||
Archives: []config.Archive{
|
||||
{Format: "tar.gz", WrapInDirectory: "true"},
|
||||
},
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
},
|
||||
Scoop: config.Scoop{
|
||||
Bucket: config.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
Description: "A run pipe test formula",
|
||||
Homepage: "https://gitlab.com/goreleaser",
|
||||
URLTemplate: "http://gitlab.mycompany.com/foo/bar/uploads/{{ .ArtifactUploadHash }}/{{ .ArtifactName }}",
|
||||
Persist: []string{"data.cfg", "etc"},
|
||||
},
|
||||
},
|
||||
}
|
||||
require.NoError(t, 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{}{
|
||||
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
|
||||
"WrappedIn": "foo_1.0.1_windows_amd64",
|
||||
"Builds": []*artifact.Artifact{
|
||||
{
|
||||
Name: "foo.exe",
|
||||
},
|
||||
{
|
||||
Name: "bar.exe",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
var golden = "testdata/test_buildmanifest_wrap.json.golden"
|
||||
if *update {
|
||||
require.NoError(t, ioutil.WriteFile(golden, out.Bytes(), 0655))
|
||||
}
|
||||
bts, err := ioutil.ReadFile(golden)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, string(bts), out.String())
|
||||
}
|
||||
|
||||
type DummyClient struct {
|
||||
CreatedFile bool
|
||||
Content string
|
||||
|
19
internal/pipe/scoop/testdata/test_buildmanifest_wrap.json.golden
vendored
Normal file
19
internal/pipe/scoop/testdata/test_buildmanifest_wrap.json.golden
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.1",
|
||||
"architecture": {
|
||||
"64bit": {
|
||||
"url": "http://gitlab.mycompany.com/foo/bar/uploads/820ead5d9d2266c728dce6d4d55b6460/foo_1.0.1_windows_amd64.tar.gz",
|
||||
"bin": [
|
||||
"foo_1.0.1_windows_amd64/foo.exe",
|
||||
"foo_1.0.1_windows_amd64/bar.exe"
|
||||
],
|
||||
"hash": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"
|
||||
}
|
||||
},
|
||||
"homepage": "https://gitlab.com/goreleaser",
|
||||
"description": "A run pipe test formula",
|
||||
"persist": [
|
||||
"data.cfg",
|
||||
"etc"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user