2018-02-10 15:04:49 +02:00
|
|
|
package scoop
|
|
|
|
|
|
|
|
import (
|
2020-07-06 15:48:17 +02:00
|
|
|
ctx "context"
|
2018-02-10 15:04:49 +02:00
|
|
|
"os"
|
2018-09-06 12:20:12 +02:00
|
|
|
"path/filepath"
|
2019-01-05 16:30:26 +02:00
|
|
|
"testing"
|
2018-09-06 12:20:12 +02:00
|
|
|
|
2018-02-10 15:04:49 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/client"
|
2021-05-31 02:53:40 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/golden"
|
2018-09-12 19:18:01 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
2018-02-10 15:37:22 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
2018-08-15 04:50:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2018-08-21 03:20:04 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-02-10 15:04:49 +02:00
|
|
|
)
|
|
|
|
|
2018-02-10 15:37:22 +02:00
|
|
|
func TestDescription(t *testing.T) {
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
2018-02-10 15:37:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefault(t *testing.T) {
|
2020-12-12 18:27:35 +02:00
|
|
|
testlib.Mktmp(t)
|
2018-02-10 15:37:22 +02:00
|
|
|
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := &context.Context{
|
2019-08-13 20:28:03 +02:00
|
|
|
TokenType: context.TokenTypeGitHub,
|
2018-02-10 15:37:22 +02:00
|
|
|
Config: config.Project{
|
2018-09-30 16:04:32 +02:00
|
|
|
ProjectName: "barr",
|
2018-02-10 15:37:22 +02:00
|
|
|
Builds: []config.Build{
|
|
|
|
{
|
|
|
|
Binary: "foo",
|
|
|
|
Goos: []string{"linux", "darwin"},
|
|
|
|
Goarch: []string{"386", "amd64"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Binary: "bar",
|
|
|
|
Goos: []string{"linux", "darwin"},
|
|
|
|
Goarch: []string{"386", "amd64"},
|
|
|
|
Ignore: []config.IgnoredBuild{
|
|
|
|
{Goos: "darwin", Goarch: "amd64"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Binary: "foobar",
|
|
|
|
Goos: []string{"linux"},
|
|
|
|
Goarch: []string{"amd64"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, ctx.Config.ProjectName, ctx.Config.Scoop.Name)
|
|
|
|
require.NotEmpty(t, ctx.Config.Scoop.CommitAuthor.Name)
|
|
|
|
require.NotEmpty(t, ctx.Config.Scoop.CommitAuthor.Email)
|
|
|
|
require.NotEmpty(t, ctx.Config.Scoop.CommitMessageTemplate)
|
2018-02-10 15:37:22 +02:00
|
|
|
}
|
|
|
|
|
2018-02-10 15:55:03 +02:00
|
|
|
func Test_doRun(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
folder := testlib.Mktmp(t)
|
|
|
|
file := filepath.Join(folder, "archive")
|
|
|
|
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
|
2018-09-06 12:20:12 +02:00
|
|
|
|
2018-02-16 14:35:44 +02:00
|
|
|
type errChecker func(*testing.T, error)
|
2021-04-25 19:20:49 +02:00
|
|
|
shouldErr := func(msg string) errChecker {
|
2018-02-16 14:35:44 +02:00
|
|
|
return func(t *testing.T, err error) {
|
2021-01-15 14:54:31 +02:00
|
|
|
t.Helper()
|
2020-10-06 14:48:04 +02:00
|
|
|
require.Error(t, err)
|
|
|
|
require.EqualError(t, err, msg)
|
2018-02-16 14:35:44 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-25 19:20:49 +02:00
|
|
|
shouldNotErr := func(t *testing.T, err error) {
|
2021-01-15 14:54:31 +02:00
|
|
|
t.Helper()
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2018-02-16 14:35:44 +02:00
|
|
|
}
|
2018-02-10 15:55:03 +02:00
|
|
|
type args struct {
|
|
|
|
ctx *context.Context
|
|
|
|
client client.Client
|
|
|
|
}
|
|
|
|
tests := []struct {
|
2018-02-16 14:35:44 +02:00
|
|
|
name string
|
|
|
|
args args
|
2019-08-12 22:44:48 +02:00
|
|
|
artifacts []*artifact.Artifact
|
2018-02-16 14:35:44 +02:00
|
|
|
assertError errChecker
|
2018-02-10 15:55:03 +02:00
|
|
|
}{
|
|
|
|
{
|
2019-08-13 20:28:03 +02:00
|
|
|
"valid public github",
|
2018-02-10 15:55:03 +02:00
|
|
|
args{
|
|
|
|
&context.Context{
|
2019-08-13 20:28:03 +02:00
|
|
|
TokenType: context.TokenTypeGitHub,
|
2018-02-10 15:55:03 +02:00
|
|
|
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",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2018-02-10 15:55:03 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&DummyClient{},
|
|
|
|
},
|
2019-08-12 22:44:48 +02:00
|
|
|
[]*artifact.Artifact{
|
2018-09-06 12:20:12 +02:00
|
|
|
{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},
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2018-02-16 14:35:44 +02:00
|
|
|
shouldNotErr,
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2020-04-21 21:11:18 +02:00
|
|
|
{
|
|
|
|
"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{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2020-04-21 21:11:18 +02:00
|
|
|
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,
|
|
|
|
},
|
2018-02-11 18:36:59 +02:00
|
|
|
{
|
2019-08-13 20:28:03 +02:00
|
|
|
"valid enterprise github",
|
2018-02-11 18:36:59 +02:00
|
|
|
args{
|
|
|
|
&context.Context{
|
2019-08-13 20:28:03 +02:00
|
|
|
TokenType: context.TokenTypeGitHub,
|
2018-02-11 18:36:59 +02:00
|
|
|
Git: context.GitInfo{
|
|
|
|
CurrentTag: "v1.0.1",
|
|
|
|
},
|
|
|
|
Version: "1.0.1",
|
|
|
|
Artifacts: artifact.New(),
|
|
|
|
Config: config.Project{
|
|
|
|
GitHubURLs: config.GitHubURLs{Download: "https://api.custom.github.enterprise.com"},
|
|
|
|
Builds: []config.Build{
|
|
|
|
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
|
|
|
|
},
|
|
|
|
Dist: ".",
|
|
|
|
ProjectName: "run-pipe",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2018-02-11 18:36:59 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2018-02-11 18:36:59 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&DummyClient{},
|
|
|
|
},
|
2019-08-12 22:44:48 +02:00
|
|
|
[]*artifact.Artifact{
|
2018-09-06 12:20:12 +02:00
|
|
|
{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},
|
2018-02-11 18:36:59 +02:00
|
|
|
},
|
2018-02-16 14:35:44 +02:00
|
|
|
shouldNotErr,
|
2018-02-11 18:36:59 +02:00
|
|
|
},
|
2018-02-10 15:55:03 +02:00
|
|
|
{
|
2019-08-13 20:28:03 +02:00
|
|
|
"valid public gitlab",
|
2018-02-10 15:55:03 +02:00
|
|
|
args{
|
|
|
|
&context.Context{
|
2019-08-13 20:28:03 +02:00
|
|
|
TokenType: context.TokenTypeGitLab,
|
2018-02-10 15:55:03 +02:00
|
|
|
Git: context.GitInfo{
|
|
|
|
CurrentTag: "v1.0.1",
|
|
|
|
},
|
|
|
|
Version: "1.0.1",
|
|
|
|
Artifacts: artifact.New(),
|
|
|
|
Config: config.Project{
|
|
|
|
Builds: []config.Build{
|
2019-08-13 20:28:03 +02:00
|
|
|
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
|
|
|
Dist: ".",
|
|
|
|
ProjectName: "run-pipe",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
2019-08-13 20:28:03 +02:00
|
|
|
GitLab: config.Repo{
|
2018-02-10 15:55:03 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2018-02-10 15:55:03 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
2019-08-13 20:28:03 +02:00
|
|
|
Homepage: "https://gitlab.com/goreleaser",
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&DummyClient{},
|
|
|
|
},
|
2019-08-12 22:44:48 +02:00
|
|
|
[]*artifact.Artifact{
|
2019-08-13 20:28:03 +02:00
|
|
|
{
|
|
|
|
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,
|
|
|
|
},
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
shouldNotErr,
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
|
|
|
{
|
2019-08-13 20:28:03 +02:00
|
|
|
"valid enterprise gitlab",
|
2018-02-10 15:55:03 +02:00
|
|
|
args{
|
|
|
|
&context.Context{
|
2019-08-13 20:28:03 +02:00
|
|
|
TokenType: context.TokenTypeGitLab,
|
2018-02-10 15:55:03 +02:00
|
|
|
Git: context.GitInfo{
|
|
|
|
CurrentTag: "v1.0.1",
|
|
|
|
},
|
|
|
|
Version: "1.0.1",
|
|
|
|
Artifacts: artifact.New(),
|
|
|
|
Config: config.Project{
|
2019-08-13 20:28:03 +02:00
|
|
|
GitHubURLs: config.GitHubURLs{Download: "https://api.custom.gitlab.enterprise.com"},
|
2018-02-10 15:55:03 +02:00
|
|
|
Builds: []config.Build{
|
|
|
|
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
|
|
|
|
},
|
|
|
|
Dist: ".",
|
|
|
|
ProjectName: "run-pipe",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2018-02-10 15:59:20 +02:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2019-08-13 20:28:03 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://gitlab.com/goreleaser",
|
|
|
|
},
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
&DummyClient{},
|
|
|
|
},
|
2019-08-12 22:44:48 +02:00
|
|
|
[]*artifact.Artifact{
|
2019-08-13 20:28:03 +02:00
|
|
|
{
|
|
|
|
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,
|
|
|
|
},
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
shouldNotErr,
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
|
|
|
{
|
2019-08-13 20:28:03 +02:00
|
|
|
"token type not implemented for pipe",
|
2018-02-10 15:59:20 +02:00
|
|
|
args{
|
|
|
|
&context.Context{
|
|
|
|
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",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2018-02-10 15:59:20 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-07-06 15:48:17 +02:00
|
|
|
&DummyClient{NotImplemented: true},
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
2019-08-12 22:44:48 +02:00
|
|
|
[]*artifact.Artifact{
|
2018-09-06 12:20:12 +02:00
|
|
|
{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},
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
shouldErr(ErrTokenTypeNotImplementedForScoop.Error()),
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
|
|
|
{
|
2019-08-13 20:28:03 +02:00
|
|
|
"no windows build",
|
2018-02-10 15:59:20 +02:00
|
|
|
args{
|
|
|
|
&context.Context{
|
2019-08-13 20:28:03 +02:00
|
|
|
TokenType: context.TokenTypeGitHub,
|
2018-02-10 15:59:20 +02:00
|
|
|
Git: context.GitInfo{
|
|
|
|
CurrentTag: "v1.0.1",
|
|
|
|
},
|
|
|
|
Version: "1.0.1",
|
|
|
|
Artifacts: artifact.New(),
|
|
|
|
Config: config.Project{
|
|
|
|
Builds: []config.Build{
|
2019-08-13 20:28:03 +02:00
|
|
|
{Binary: "test"},
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
|
|
|
Dist: ".",
|
|
|
|
ProjectName: "run-pipe",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
2019-08-13 20:28:03 +02:00
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2018-02-10 15:59:20 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
},
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
&DummyClient{},
|
|
|
|
},
|
2019-08-12 22:44:48 +02:00
|
|
|
[]*artifact.Artifact{
|
2019-08-13 20:28:03 +02:00
|
|
|
{Name: "foo_1.0.1_linux_amd64.tar.gz", Goos: "linux", Goarch: "amd64"},
|
|
|
|
{Name: "foo_1.0.1_linux_386.tar.gz", Goos: "linux", Goarch: "386"},
|
2018-02-11 18:36:59 +02:00
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
shouldErr("scoop requires a windows build"),
|
2018-02-11 18:36:59 +02:00
|
|
|
},
|
|
|
|
{
|
2019-08-13 20:28:03 +02:00
|
|
|
"no scoop",
|
2018-02-11 18:36:59 +02:00
|
|
|
args{
|
|
|
|
&context.Context{
|
2019-08-13 20:28:03 +02:00
|
|
|
TokenType: context.TokenTypeGitHub,
|
2018-02-11 18:36:59 +02:00
|
|
|
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",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2018-02-11 18:36:59 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
2019-08-13 20:28:03 +02:00
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&DummyClient{},
|
|
|
|
},
|
|
|
|
[]*artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"},
|
|
|
|
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"},
|
|
|
|
},
|
2021-04-19 14:31:57 +02:00
|
|
|
shouldErr(pipe.ErrSkipDisabledPipe.Error()),
|
2019-08-13 20:28:03 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"no publish",
|
|
|
|
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",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2019-08-13 20:28:03 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
2018-02-11 18:36:59 +02:00
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2018-02-11 18:36:59 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
},
|
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
SkipPublish: true,
|
2018-02-11 18:36:59 +02:00
|
|
|
},
|
|
|
|
&DummyClient{},
|
|
|
|
},
|
2019-08-12 22:44:48 +02:00
|
|
|
[]*artifact.Artifact{
|
2019-08-13 20:28:03 +02:00
|
|
|
{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},
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
shouldErr(pipe.ErrSkipPublishEnabled.Error()),
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2019-06-29 16:02:40 +02:00
|
|
|
{
|
2019-08-13 20:28:03 +02:00
|
|
|
"is draft",
|
2019-06-29 16:02:40 +02:00
|
|
|
args{
|
|
|
|
&context.Context{
|
2019-08-13 20:28:03 +02:00
|
|
|
TokenType: context.TokenTypeGitHub,
|
2019-06-29 16:02:40 +02:00
|
|
|
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",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2019-06-29 16:02:40 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
2019-08-13 20:28:03 +02:00
|
|
|
Draft: true,
|
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2019-06-29 16:02:40 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
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},
|
|
|
|
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
|
|
|
},
|
|
|
|
shouldErr("release is marked as draft"),
|
|
|
|
},
|
2020-02-06 03:05:43 +02:00
|
|
|
{
|
|
|
|
"is prerelease and skip upload set to auto",
|
|
|
|
args{
|
|
|
|
&context.Context{
|
|
|
|
TokenType: context.TokenTypeGitHub,
|
|
|
|
Git: context.GitInfo{
|
|
|
|
CurrentTag: "v1.0.1-pre.1",
|
|
|
|
},
|
|
|
|
Semver: context.Semver{
|
|
|
|
Major: 1,
|
|
|
|
Minor: 0,
|
|
|
|
Patch: 1,
|
|
|
|
Prerelease: "-pre.1",
|
|
|
|
},
|
|
|
|
Version: "1.0.1-pre.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"},
|
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
|
|
|
SkipUpload: "auto",
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2020-02-06 03:05:43 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&DummyClient{},
|
|
|
|
},
|
|
|
|
[]*artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
|
|
|
|
{Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
|
|
|
},
|
|
|
|
shouldErr("release is prerelease"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"skip upload set to true",
|
|
|
|
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"},
|
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
|
|
|
SkipUpload: "true",
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2020-02-06 03:05:43 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&DummyClient{},
|
|
|
|
},
|
|
|
|
[]*artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
|
|
|
|
{Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
|
|
|
},
|
|
|
|
shouldErr("scoop.skip_upload is true"),
|
|
|
|
},
|
2019-08-29 01:34:09 +02:00
|
|
|
{
|
|
|
|
"release is disabled",
|
|
|
|
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",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2019-08-29 01:34:09 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
Disable: true,
|
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2019-08-29 01:34:09 +02:00
|
|
|
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},
|
|
|
|
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
|
|
|
},
|
|
|
|
shouldErr("release is disabled"),
|
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
{
|
|
|
|
"no archive",
|
|
|
|
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",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "binary"},
|
2019-08-13 20:28:03 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
Draft: true,
|
2019-06-29 16:02:40 +02:00
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2019-06-29 16:02:40 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&DummyClient{},
|
|
|
|
},
|
2019-08-12 22:44:48 +02:00
|
|
|
[]*artifact.Artifact{
|
2019-06-29 16:02:40 +02:00
|
|
|
{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},
|
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
shouldErr("archive format is binary"),
|
2019-06-29 16:02:40 +02:00
|
|
|
},
|
2018-02-10 15:55:03 +02:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := tt.args.ctx
|
2018-02-10 15:55:03 +02:00
|
|
|
for _, a := range tt.artifacts {
|
2018-08-21 03:20:04 +02:00
|
|
|
ctx.Artifacts.Add(a)
|
2018-02-10 15:55:03 +02:00
|
|
|
}
|
2018-08-21 03:20:04 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2020-04-29 22:45:18 +02:00
|
|
|
|
2018-08-21 03:20:04 +02:00
|
|
|
tt.assertError(t, doRun(ctx, tt.args.client))
|
2018-02-10 15:55:03 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-10 15:04:49 +02:00
|
|
|
func Test_buildManifest(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
folder := t.TempDir()
|
|
|
|
file := filepath.Join(folder, "archive")
|
|
|
|
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
|
2018-09-06 12:20:12 +02:00
|
|
|
|
2018-02-10 15:04:49 +02:00
|
|
|
tests := []struct {
|
2021-05-31 02:53:40 +02:00
|
|
|
desc string
|
|
|
|
ctx *context.Context
|
2018-02-10 15:04:49 +02:00
|
|
|
}{
|
|
|
|
{
|
2021-05-31 02:53:40 +02:00
|
|
|
"common",
|
2018-08-21 03:06:55 +02:00
|
|
|
&context.Context{
|
2020-07-06 15:48:17 +02:00
|
|
|
Context: ctx.Background(),
|
2019-08-13 20:28:03 +02:00
|
|
|
TokenType: context.TokenTypeGitHub,
|
2018-08-21 03:06:55 +02:00
|
|
|
Git: context.GitInfo{
|
|
|
|
CurrentTag: "v1.0.1",
|
|
|
|
},
|
|
|
|
Version: "1.0.1",
|
|
|
|
Artifacts: artifact.New(),
|
|
|
|
Config: config.Project{
|
|
|
|
GitHubURLs: config.GitHubURLs{
|
|
|
|
Download: "https://github.com",
|
2018-03-06 01:55:02 +02:00
|
|
|
},
|
2018-08-21 03:06:55 +02:00
|
|
|
Dist: ".",
|
|
|
|
ProjectName: "run-pipe",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2018-08-21 03:06:55 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2018-03-06 01:55:02 +02:00
|
|
|
},
|
|
|
|
},
|
2018-08-21 03:06:55 +02:00
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2018-08-21 03:06:55 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
2018-08-25 22:24:42 +02:00
|
|
|
Persist: []string{"data", "config", "test.ini"},
|
2018-08-21 03:06:55 +02:00
|
|
|
},
|
2018-03-06 01:55:02 +02:00
|
|
|
},
|
|
|
|
},
|
2018-02-10 15:04:49 +02:00
|
|
|
},
|
2020-12-05 17:16:32 +02:00
|
|
|
{
|
2021-05-31 02:53:40 +02:00
|
|
|
"pre-post-install",
|
2020-12-05 17:16:32 +02:00
|
|
|
&context.Context{
|
|
|
|
Context: ctx.Background(),
|
|
|
|
TokenType: context.TokenTypeGitHub,
|
|
|
|
Git: context.GitInfo{
|
|
|
|
CurrentTag: "v1.0.1",
|
|
|
|
},
|
|
|
|
Version: "1.0.1",
|
|
|
|
Artifacts: artifact.New(),
|
|
|
|
Config: config.Project{
|
|
|
|
GitHubURLs: config.GitHubURLs{
|
|
|
|
Download: "https://github.com",
|
|
|
|
},
|
|
|
|
Dist: ".",
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
|
|
|
Bucket: config.RepoRef{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
Persist: []string{"data", "config", "test.ini"},
|
|
|
|
PreInstall: []string{"Write-Host 'Running preinstall command'"},
|
|
|
|
PostInstall: []string{"Write-Host 'Running postinstall command'"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-02-10 15:04:49 +02:00
|
|
|
{
|
2021-05-31 02:53:40 +02:00
|
|
|
"url template",
|
2018-08-21 03:06:55 +02:00
|
|
|
&context.Context{
|
2020-07-06 15:48:17 +02:00
|
|
|
Context: ctx.Background(),
|
2019-08-13 20:28:03 +02:00
|
|
|
TokenType: context.TokenTypeGitHub,
|
2018-08-21 03:06:55 +02:00
|
|
|
Git: context.GitInfo{
|
|
|
|
CurrentTag: "v1.0.1",
|
|
|
|
},
|
|
|
|
Version: "1.0.1",
|
|
|
|
Artifacts: artifact.New(),
|
|
|
|
Config: config.Project{
|
|
|
|
GitHubURLs: config.GitHubURLs{
|
|
|
|
Download: "https://github.com",
|
2018-03-06 01:55:02 +02:00
|
|
|
},
|
2018-08-21 03:06:55 +02:00
|
|
|
Builds: []config.Build{
|
|
|
|
{Binary: "test"},
|
|
|
|
},
|
|
|
|
Dist: ".",
|
|
|
|
ProjectName: "run-pipe",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2018-08-21 03:06:55 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2018-03-06 01:55:02 +02:00
|
|
|
},
|
|
|
|
},
|
2018-08-21 03:06:55 +02:00
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2018-08-21 03:06:55 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
2020-04-29 22:45:18 +02:00
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
URLTemplate: "http://github.mycompany.com/foo/bar/{{ .Tag }}/{{ .ArtifactName }}",
|
|
|
|
CommitMessageTemplate: "chore(scoop): update {{ .ProjectName }} version {{ .Tag }}",
|
|
|
|
Persist: []string{"data.cfg", "etc"},
|
2018-08-21 03:06:55 +02:00
|
|
|
},
|
2018-03-06 01:55:02 +02:00
|
|
|
},
|
|
|
|
},
|
2018-02-10 15:04:49 +02:00
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
{
|
2021-05-31 02:53:40 +02:00
|
|
|
"gitlab url template",
|
2019-08-13 20:28:03 +02:00
|
|
|
&context.Context{
|
2020-07-06 15:48:17 +02:00
|
|
|
Context: ctx.Background(),
|
2019-08-13 20:28:03 +02:00
|
|
|
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",
|
2019-12-29 20:02:15 +02:00
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
2019-08-13 20:28:03 +02:00
|
|
|
},
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2019-08-13 20:28:03 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
2020-04-29 22:45:18 +02:00
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://gitlab.com/goreleaser",
|
2021-05-17 19:33:04 +02:00
|
|
|
URLTemplate: "http://gitlab.mycompany.com/foo/bar/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}",
|
2020-04-29 22:45:18 +02:00
|
|
|
CommitMessageTemplate: "chore(scoop): update {{ .ProjectName }} version {{ .Tag }}",
|
|
|
|
Persist: []string{"data.cfg", "etc"},
|
2019-08-13 20:28:03 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-02-10 15:04:49 +02:00
|
|
|
}
|
2018-08-21 03:06:55 +02:00
|
|
|
|
2018-02-10 15:04:49 +02:00
|
|
|
for _, tt := range tests {
|
2021-05-31 02:53:40 +02:00
|
|
|
t.Run(tt.desc, func(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := tt.ctx
|
2019-03-31 19:10:26 +02:00
|
|
|
err := Pipe{}.Default(ctx)
|
|
|
|
require.NoError(t, err)
|
2020-07-06 15:48:17 +02:00
|
|
|
|
|
|
|
cl, err := client.New(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
mf, err := dataFor(ctx, cl, []*artifact.Artifact{
|
2019-01-05 16:30:26 +02:00
|
|
|
{
|
|
|
|
Name: "foo_1.0.1_windows_amd64.tar.gz",
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Path: file,
|
|
|
|
Extra: map[string]interface{}{
|
2019-08-12 22:44:48 +02:00
|
|
|
"Builds": []*artifact.Artifact{
|
2019-01-05 16:30:26 +02:00
|
|
|
{
|
2020-04-02 23:59:01 +02:00
|
|
|
Name: "foo.exe",
|
2019-01-05 16:30:26 +02:00
|
|
|
},
|
|
|
|
{
|
2020-04-02 23:59:01 +02:00
|
|
|
Name: "bar.exe",
|
2019-01-05 16:30:26 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-18 20:40:23 +02:00
|
|
|
{
|
|
|
|
Name: "foo_1.0.1_windows_arm.tar.gz",
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "arm",
|
|
|
|
Path: file,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
"Builds": []*artifact.Artifact{
|
|
|
|
{
|
|
|
|
Name: "foo.exe",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "bar.exe",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-01-05 16:30:26 +02:00
|
|
|
{
|
|
|
|
Name: "foo_1.0.1_windows_386.tar.gz",
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "386",
|
|
|
|
Path: file,
|
|
|
|
Extra: map[string]interface{}{
|
2019-08-12 22:44:48 +02:00
|
|
|
"Builds": []*artifact.Artifact{
|
2019-01-05 16:30:26 +02:00
|
|
|
{
|
2020-04-02 23:59:01 +02:00
|
|
|
Name: "foo.exe",
|
2019-01-05 16:30:26 +02:00
|
|
|
},
|
|
|
|
{
|
2020-04-02 23:59:01 +02:00
|
|
|
Name: "bar.exe",
|
2019-01-05 16:30:26 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2020-07-06 15:48:17 +02:00
|
|
|
require.NoError(t, err)
|
2018-08-21 03:06:55 +02:00
|
|
|
|
2020-07-06 15:48:17 +02:00
|
|
|
out, err := doBuildManifest(mf)
|
2019-01-05 16:30:26 +02:00
|
|
|
require.NoError(t, err)
|
2018-08-21 03:06:55 +02:00
|
|
|
|
2021-05-31 02:53:40 +02:00
|
|
|
golden.RequireEqualJSON(t, out.Bytes())
|
2019-01-05 16:30:26 +02:00
|
|
|
})
|
2018-02-10 15:04:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 19:30:31 +02:00
|
|
|
func TestRunPipeScoopWithSkip(t *testing.T) {
|
|
|
|
folder := t.TempDir()
|
|
|
|
ctx := &context.Context{
|
|
|
|
Git: context.GitInfo{
|
|
|
|
CurrentTag: "v1.0.1",
|
|
|
|
},
|
|
|
|
Version: "1.0.1",
|
|
|
|
Artifacts: artifact.New(),
|
|
|
|
Config: config.Project{
|
|
|
|
Archives: []config.Archive{
|
|
|
|
{Format: "tar.gz"},
|
|
|
|
},
|
|
|
|
Builds: []config.Build{
|
|
|
|
{Binary: "test"},
|
|
|
|
},
|
2021-05-25 21:49:49 +02:00
|
|
|
Dist: folder,
|
2021-05-24 19:30:31 +02:00
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
|
|
|
Bucket: config.RepoRef{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
2021-05-25 21:49:49 +02:00
|
|
|
Name: "run-pipe",
|
|
|
|
SkipUpload: "true",
|
2021-05-24 19:30:31 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
path := filepath.Join(folder, "bin.tar.gz")
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: path,
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
"ID": "foo",
|
|
|
|
"Format": "tar.gz",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
f, err := os.Create(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, f.Close())
|
|
|
|
|
|
|
|
cli := &DummyClient{}
|
|
|
|
require.EqualError(t, doRun(ctx, cli), `scoop.skip_upload is true`)
|
|
|
|
|
|
|
|
distFile := filepath.Join(folder, ctx.Config.Scoop.Name+".json")
|
|
|
|
_, err = os.Stat(distFile)
|
|
|
|
require.NoError(t, err, "file should exist: "+distFile)
|
|
|
|
}
|
|
|
|
|
2020-04-21 21:11:18 +02:00
|
|
|
func TestWrapInDirectory(t *testing.T) {
|
2021-04-25 19:20:49 +02:00
|
|
|
folder := t.TempDir()
|
|
|
|
file := filepath.Join(folder, "archive")
|
|
|
|
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
|
|
|
|
ctx := &context.Context{
|
2020-04-21 21:11:18 +02:00
|
|
|
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{
|
2020-07-06 22:12:41 +02:00
|
|
|
Bucket: config.RepoRef{
|
2020-04-21 21:11:18 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
2020-04-29 22:45:18 +02:00
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://gitlab.com/goreleaser",
|
2021-05-17 19:33:04 +02:00
|
|
|
URLTemplate: "http://gitlab.mycompany.com/foo/bar/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}",
|
2020-04-29 22:45:18 +02:00
|
|
|
CommitMessageTemplate: "chore(scoop): update {{ .ProjectName }} version {{ .Tag }}",
|
|
|
|
Persist: []string{"data.cfg", "etc"},
|
2020-04-21 21:11:18 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2020-07-06 15:48:17 +02:00
|
|
|
cl, err := client.New(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
mf, err := dataFor(ctx, cl, []*artifact.Artifact{
|
2020-04-21 21:11:18 +02:00
|
|
|
{
|
|
|
|
Name: "foo_1.0.1_windows_amd64.tar.gz",
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Path: file,
|
|
|
|
Extra: map[string]interface{}{
|
2021-05-17 19:33:04 +02:00
|
|
|
"WrappedIn": "foo_1.0.1_windows_amd64",
|
2020-04-21 21:11:18 +02:00
|
|
|
"Builds": []*artifact.Artifact{
|
|
|
|
{
|
|
|
|
Name: "foo.exe",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "bar.exe",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2020-07-06 15:48:17 +02:00
|
|
|
require.NoError(t, err)
|
2020-04-21 21:11:18 +02:00
|
|
|
|
2020-07-06 15:48:17 +02:00
|
|
|
out, err := doBuildManifest(mf)
|
2020-04-21 21:11:18 +02:00
|
|
|
require.NoError(t, err)
|
2021-05-31 02:53:40 +02:00
|
|
|
golden.RequireEqualJSON(t, out.Bytes())
|
2020-04-21 21:11:18 +02:00
|
|
|
}
|
|
|
|
|
2018-02-10 15:04:49 +02:00
|
|
|
type DummyClient struct {
|
2020-07-06 15:48:17 +02:00
|
|
|
CreatedFile bool
|
|
|
|
Content string
|
|
|
|
NotImplemented bool
|
2018-02-10 15:04:49 +02:00
|
|
|
}
|
|
|
|
|
2020-07-09 22:40:37 +02:00
|
|
|
func (dc *DummyClient) CloseMilestone(ctx *context.Context, repo client.Repo, title string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-06 15:48:17 +02:00
|
|
|
func (dc *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID string, err error) {
|
2018-02-10 15:04:49 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-06 15:48:17 +02:00
|
|
|
func (dc *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
|
|
|
|
if dc.NotImplemented {
|
|
|
|
return "", client.NotImplementedError{}
|
|
|
|
}
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
2020-07-06 22:12:41 +02:00
|
|
|
func (dc *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo client.Repo, content []byte, path, msg string) (err error) {
|
2020-07-06 15:48:17 +02:00
|
|
|
dc.CreatedFile = true
|
|
|
|
dc.Content = string(content)
|
2018-02-10 15:04:49 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-06 15:48:17 +02:00
|
|
|
func (dc *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) (err error) {
|
2018-02-10 15:04:49 +02:00
|
|
|
return
|
|
|
|
}
|