Skip to content

Commit

Permalink
fix: scoop wrap_in_directory (#1458)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Apr 21, 2020
1 parent f0cc745 commit fc1ef8a
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 5 deletions.
7 changes: 4 additions & 3 deletions internal/pipe/archive/archive.go
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion internal/pipe/archive/archive_test.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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", ""))
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion internal/pipe/scoop/scoop.go
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"path/filepath"
"strings"

"github.com/goreleaser/goreleaser/internal/artifact"
Expand Down Expand Up @@ -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
}
134 changes: 134 additions & 0 deletions internal/pipe/scoop/scoop_test.go
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions internal/pipe/scoop/testdata/test_buildmanifest_wrap.json.golden
@@ -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"
]
}

0 comments on commit fc1ef8a

Please sign in to comment.