2018-02-10 15:04:49 +02:00
|
|
|
package scoop
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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"
|
2023-11-04 01:22:50 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/skips"
|
2023-03-02 05:01:11 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testctx"
|
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
|
|
|
)
|
|
|
|
|
2023-06-20 14:33:59 +02:00
|
|
|
func TestContinueOnError(t *testing.T) {
|
|
|
|
require.True(t, Pipe{}.ContinueOnError())
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(
|
2023-05-01 02:29:36 +02:00
|
|
|
config.Project{
|
|
|
|
ProjectName: "barr",
|
|
|
|
Scoops: []config.Scoop{
|
|
|
|
{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-05-01 02:29:36 +02:00
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.GitHubTokenType,
|
|
|
|
)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2023-05-01 02:29:36 +02:00
|
|
|
require.Len(t, ctx.Config.Scoops, 1)
|
|
|
|
require.Equal(t, ctx.Config.ProjectName, ctx.Config.Scoops[0].Name)
|
|
|
|
require.NotEmpty(t, ctx.Config.Scoops[0].CommitAuthor.Name)
|
|
|
|
require.NotEmpty(t, ctx.Config.Scoops[0].CommitAuthor.Email)
|
|
|
|
require.NotEmpty(t, ctx.Config.Scoops[0].CommitMessageTemplate)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultDeprecated(t *testing.T) {
|
|
|
|
testlib.Mktmp(t)
|
|
|
|
|
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "barr",
|
|
|
|
Scoop: config.Scoop{
|
|
|
|
Bucket: config.RepoRef{
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
)
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Len(t, ctx.Config.Scoops, 1)
|
|
|
|
require.Equal(t, ctx.Config.ProjectName, ctx.Config.Scoops[0].Name)
|
|
|
|
require.NotEmpty(t, ctx.Config.Scoops[0].CommitAuthor.Name)
|
|
|
|
require.NotEmpty(t, ctx.Config.Scoops[0].CommitAuthor.Email)
|
|
|
|
require.NotEmpty(t, ctx.Config.Scoops[0].CommitMessageTemplate)
|
2023-06-14 05:13:21 +02:00
|
|
|
require.Equal(t, "foo", ctx.Config.Scoops[0].Repository.Name)
|
|
|
|
require.True(t, ctx.Deprecated)
|
2018-02-10 15:37:22 +02:00
|
|
|
}
|
|
|
|
|
2018-02-10 15:55:03 +02:00
|
|
|
func Test_doRun(t *testing.T) {
|
2023-04-30 15:18:13 +02:00
|
|
|
folder := t.TempDir()
|
2021-04-25 19:20:49 +02:00
|
|
|
file := filepath.Join(folder, "archive")
|
|
|
|
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
|
2018-09-06 12:20:12 +02:00
|
|
|
|
2021-06-26 19:14:42 +02:00
|
|
|
type args struct {
|
2023-04-30 15:18:13 +02:00
|
|
|
ctx *context.Context
|
2021-10-03 18:24:20 +02:00
|
|
|
client *client.Mock
|
2021-06-26 19:14:42 +02:00
|
|
|
}
|
|
|
|
|
2022-11-02 19:54:16 +02:00
|
|
|
type asserter func(testing.TB, args)
|
|
|
|
type errChecker func(testing.TB, error)
|
2021-04-25 19:20:49 +02:00
|
|
|
shouldErr := func(msg string) errChecker {
|
2022-11-02 19:54:16 +02:00
|
|
|
return func(tb testing.TB, err error) {
|
|
|
|
tb.Helper()
|
|
|
|
require.Error(tb, err)
|
|
|
|
require.EqualError(tb, err, msg)
|
2018-02-16 14:35:44 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-02 19:54:16 +02:00
|
|
|
noAssertions := func(tb testing.TB, _ args) {
|
|
|
|
tb.Helper()
|
2021-06-26 19:14:42 +02:00
|
|
|
}
|
2022-11-02 19:54:16 +02:00
|
|
|
shouldNotErr := func(tb testing.TB, err error) {
|
|
|
|
tb.Helper()
|
|
|
|
require.NoError(tb, err)
|
2018-02-16 14:35:44 +02:00
|
|
|
}
|
2021-06-26 19:14:42 +02:00
|
|
|
|
2018-02-10 15:55:03 +02:00
|
|
|
tests := []struct {
|
2021-09-18 15:21:29 +02:00
|
|
|
name string
|
|
|
|
args args
|
2021-12-07 23:04:29 +02:00
|
|
|
artifacts []artifact.Artifact
|
2021-09-18 15:21:29 +02:00
|
|
|
assertRunError errChecker
|
|
|
|
assertPublishError errChecker
|
|
|
|
assert asserter
|
2018-02-10 15:55:03 +02:00
|
|
|
}{
|
2023-05-01 02:29:36 +02:00
|
|
|
{
|
|
|
|
"multiple_artifacts",
|
|
|
|
args{
|
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Dist: t.TempDir(),
|
|
|
|
ProjectName: "multi-arts",
|
|
|
|
Scoops: []config.Scoop{{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-05-01 02:29:36 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Folder: "scoops",
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
|
|
|
client.NewMock(),
|
|
|
|
},
|
|
|
|
[]artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
2023-07-18 02:26:18 +02:00
|
|
|
{Name: "foo_1.0.1_windows_arm64.tar.gz", Goos: "windows", Goarch: "arm64", Path: file},
|
2023-05-01 02:29:36 +02:00
|
|
|
{Name: "foos_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
|
|
|
},
|
|
|
|
func(tb testing.TB, err error) {
|
|
|
|
tb.Helper()
|
|
|
|
require.EqualError(tb, err, ErrIncorrectArchiveCount{
|
|
|
|
goamd64: "v1",
|
|
|
|
archives: []*artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1_windows_amd64.tar.gz"},
|
2023-07-18 02:26:18 +02:00
|
|
|
{Name: "foo_1.0.1_windows_arm64.tar.gz"},
|
2023-05-01 02:29:36 +02:00
|
|
|
{Name: "foos_1.0.1_windows_amd64.tar.gz"},
|
|
|
|
},
|
|
|
|
}.Error())
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
noAssertions,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"multiple_binaries",
|
|
|
|
args{
|
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Dist: t.TempDir(),
|
|
|
|
ProjectName: "multi-bins",
|
|
|
|
Scoops: []config.Scoop{{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-05-01 02:29:36 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
IDs: []string{"id2"},
|
|
|
|
Folder: "scoops",
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
|
|
|
client.NewMock(),
|
|
|
|
},
|
|
|
|
[]artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file, Extra: map[string]any{
|
|
|
|
artifact.ExtraID: "id1",
|
|
|
|
artifact.ExtraBinaries: []string{"bin1", "bin2"},
|
|
|
|
}},
|
|
|
|
{Name: "foos_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file, Extra: map[string]any{
|
|
|
|
artifact.ExtraID: "id2",
|
|
|
|
artifact.ExtraBinaries: []string{"bin4", "bin3"},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
shouldNotErr,
|
|
|
|
shouldNotErr,
|
|
|
|
func(tb testing.TB, a args) {
|
|
|
|
tb.Helper()
|
|
|
|
require.Equal(tb, "scoops/multi-bins.json", a.client.Path)
|
|
|
|
golden.RequireEqualJSON(tb, []byte(a.client.Content))
|
|
|
|
},
|
|
|
|
},
|
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{
|
2023-04-30 15:18:13 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Dist: t.TempDir(),
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
Folder: "scoops",
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
2021-10-03 18:24:20 +02:00
|
|
|
client.NewMock(),
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2021-12-07 23:04:29 +02:00
|
|
|
[]artifact.Artifact{
|
2022-04-14 02:29:39 +02:00
|
|
|
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
2018-09-06 12:20:12 +02:00
|
|
|
{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,
|
2021-09-18 15:21:29 +02:00
|
|
|
shouldNotErr,
|
2022-11-02 19:54:16 +02:00
|
|
|
func(tb testing.TB, a args) {
|
|
|
|
tb.Helper()
|
|
|
|
require.Equal(tb, "scoops/run-pipe.json", a.client.Path)
|
2023-05-01 02:29:36 +02:00
|
|
|
golden.RequireEqualJSON(tb, []byte(a.client.Content))
|
2021-06-26 19:14:42 +02:00
|
|
|
},
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2020-04-21 21:11:18 +02:00
|
|
|
{
|
2023-04-30 15:18:13 +02:00
|
|
|
"git_remote",
|
2020-04-21 21:11:18 +02:00
|
|
|
args{
|
2023-04-30 15:18:13 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "git-run-pipe",
|
|
|
|
Dist: t.TempDir(),
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Name: "test",
|
|
|
|
Branch: "main",
|
|
|
|
Git: config.GitRepoRef{
|
|
|
|
URL: testlib.GitMakeBareRepository(t),
|
2023-10-06 16:16:51 +02:00
|
|
|
PrivateKey: testlib.MakeNewSSHKey(t, ""),
|
2023-03-02 05:01:11 +02:00
|
|
|
},
|
2020-04-21 21:11:18 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
Folder: "scoops",
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
2020-04-21 21:11:18 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
|
|
|
client.NewMock(),
|
|
|
|
},
|
|
|
|
[]artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
|
|
|
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
|
|
|
},
|
|
|
|
shouldNotErr,
|
|
|
|
shouldNotErr,
|
|
|
|
func(tb testing.TB, a args) {
|
|
|
|
tb.Helper()
|
2023-09-24 22:07:10 +02:00
|
|
|
content := testlib.CatFileFromBareRepositoryOnBranch(
|
2023-04-30 15:18:13 +02:00
|
|
|
tb,
|
2023-06-14 05:13:21 +02:00
|
|
|
a.ctx.Config.Scoop.Repository.Git.URL,
|
2023-09-24 22:07:10 +02:00
|
|
|
a.ctx.Config.Scoop.Repository.Branch,
|
2023-04-30 15:18:13 +02:00
|
|
|
"scoops/git-run-pipe.json",
|
|
|
|
)
|
|
|
|
golden.RequireEqualJSON(tb, content)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"wrap in directory",
|
|
|
|
args{
|
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
2021-10-03 18:24:20 +02:00
|
|
|
client.NewMock(),
|
2020-04-21 21:11:18 +02:00
|
|
|
},
|
2021-12-07 23:04:29 +02:00
|
|
|
[]artifact.Artifact{
|
2020-04-21 21:11:18 +02:00
|
|
|
{
|
2022-04-12 03:43:22 +02:00
|
|
|
Name: "foo_1.0.1_windows_amd64.tar.gz",
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-04-12 03:43:22 +02:00
|
|
|
Path: file,
|
2020-04-21 21:11:18 +02:00
|
|
|
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,
|
2021-09-18 15:21:29 +02:00
|
|
|
shouldNotErr,
|
2021-06-26 19:14:42 +02:00
|
|
|
noAssertions,
|
2020-04-21 21:11:18 +02:00
|
|
|
},
|
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{
|
2023-04-30 15:18:13 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
GitHubURLs: config.GitHubURLs{Download: "https://api.custom.github.enterprise.com"},
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2018-02-11 18:36:59 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
2018-02-11 18:36:59 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
2021-10-03 18:24:20 +02:00
|
|
|
client.NewMock(),
|
2018-02-11 18:36:59 +02:00
|
|
|
},
|
2021-12-07 23:04:29 +02:00
|
|
|
[]artifact.Artifact{
|
2022-04-14 02:29:39 +02:00
|
|
|
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
2018-09-06 12:20:12 +02:00
|
|
|
{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,
|
2021-09-18 15:21:29 +02:00
|
|
|
shouldNotErr,
|
2022-11-02 19:54:16 +02:00
|
|
|
func(tb testing.TB, a args) {
|
|
|
|
tb.Helper()
|
|
|
|
require.Equal(tb, "run-pipe.json", a.client.Path)
|
2021-06-26 19:14:42 +02:00
|
|
|
},
|
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{
|
2023-04-30 15:18:13 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://gitlab.com/goreleaser",
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
2021-10-03 18:24:20 +02:00
|
|
|
client.NewMock(),
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2021-12-07 23:04:29 +02:00
|
|
|
[]artifact.Artifact{
|
2019-08-13 20:28:03 +02:00
|
|
|
{
|
2022-04-12 03:43:22 +02:00
|
|
|
Name: "foo_1.0.1_windows_amd64.tar.gz",
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-04-12 03:43:22 +02:00
|
|
|
Path: file,
|
2019-08-13 20:28:03 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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,
|
2021-09-18 15:21:29 +02:00
|
|
|
shouldNotErr,
|
2021-06-26 19:14:42 +02:00
|
|
|
noAssertions,
|
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{
|
2023-04-30 15:18:13 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
GitHubURLs: config.GitHubURLs{Download: "https://api.custom.gitlab.enterprise.com"},
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2019-08-13 20:28:03 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://gitlab.com/goreleaser",
|
2019-08-13 20:28:03 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
2021-10-03 18:24:20 +02:00
|
|
|
client.NewMock(),
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
2021-12-07 23:04:29 +02:00
|
|
|
[]artifact.Artifact{
|
2019-08-13 20:28:03 +02:00
|
|
|
{
|
2022-04-12 03:43:22 +02:00
|
|
|
Name: "foo_1.0.1_windows_amd64.tar.gz",
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-04-12 03:43:22 +02:00
|
|
|
Path: file,
|
2019-08-13 20:28:03 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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,
|
2021-09-18 15:21:29 +02:00
|
|
|
shouldNotErr,
|
2021-06-26 19:14:42 +02:00
|
|
|
noAssertions,
|
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{
|
2023-04-30 15:18:13 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
2018-02-10 15:59:20 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
2021-10-03 18:24:20 +02:00
|
|
|
client.NewMock(),
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2022-04-12 01:19:58 +02:00
|
|
|
[]artifact.Artifact{},
|
2023-05-01 02:29:36 +02:00
|
|
|
shouldErr(ErrIncorrectArchiveCount{"v1", nil, nil}.Error()),
|
2021-09-18 15:21:29 +02:00
|
|
|
shouldNotErr,
|
2021-06-26 19:14:42 +02:00
|
|
|
noAssertions,
|
2018-02-10 15:55:03 +02:00
|
|
|
},
|
2020-02-06 03:05:43 +02:00
|
|
|
{
|
|
|
|
"is prerelease and skip upload set to auto",
|
|
|
|
args{
|
2023-04-30 15:18:13 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
|
|
|
SkipUpload: "auto",
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2020-02-06 03:05:43 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
2020-02-06 03:05:43 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1-pre.1"),
|
|
|
|
testctx.WithVersion("1.0.1-pre.1"),
|
|
|
|
testctx.WithSemver(1, 0, 0, "pre.1"),
|
|
|
|
),
|
2021-10-03 18:24:20 +02:00
|
|
|
client.NewMock(),
|
2020-02-06 03:05:43 +02:00
|
|
|
},
|
2021-12-07 23:04:29 +02:00
|
|
|
[]artifact.Artifact{
|
2022-04-14 02:29:39 +02:00
|
|
|
{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
2020-02-06 03:05:43 +02:00
|
|
|
{Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
|
|
|
},
|
2021-09-18 15:21:29 +02:00
|
|
|
shouldNotErr,
|
2020-02-06 03:05:43 +02:00
|
|
|
shouldErr("release is prerelease"),
|
2021-06-26 19:14:42 +02:00
|
|
|
noAssertions,
|
2020-02-06 03:05:43 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"skip upload set to true",
|
|
|
|
args{
|
2023-04-30 15:18:13 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
|
|
|
SkipUpload: "true",
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2020-02-06 03:05:43 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
2020-02-06 03:05:43 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
2021-10-03 18:24:20 +02:00
|
|
|
client.NewMock(),
|
2020-02-06 03:05:43 +02:00
|
|
|
},
|
2021-12-07 23:04:29 +02:00
|
|
|
[]artifact.Artifact{
|
2022-04-14 02:29:39 +02:00
|
|
|
{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
2020-02-06 03:05:43 +02:00
|
|
|
{Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
|
|
|
},
|
2021-09-18 15:21:29 +02:00
|
|
|
shouldNotErr,
|
2020-02-06 03:05:43 +02:00
|
|
|
shouldErr("scoop.skip_upload is true"),
|
2021-06-26 19:14:42 +02:00
|
|
|
noAssertions,
|
2020-02-06 03:05:43 +02:00
|
|
|
},
|
2019-08-13 20:28:03 +02:00
|
|
|
{
|
|
|
|
"no archive",
|
|
|
|
args{
|
2023-04-30 15:18:13 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2019-06-29 16:02:40 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
2019-06-29 16:02:40 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
2021-10-03 18:24:20 +02:00
|
|
|
client.NewMock(),
|
2019-06-29 16:02:40 +02:00
|
|
|
},
|
2022-04-12 01:19:58 +02:00
|
|
|
[]artifact.Artifact{},
|
2023-05-01 02:29:36 +02:00
|
|
|
shouldErr(ErrIncorrectArchiveCount{"v1", nil, nil}.Error()),
|
2021-09-18 15:21:29 +02:00
|
|
|
shouldNotErr,
|
2021-06-26 19:14:42 +02:00
|
|
|
noAssertions,
|
2019-06-29 16:02:40 +02:00
|
|
|
},
|
2023-05-30 18:41:24 +02:00
|
|
|
{
|
|
|
|
"invalid name tmpl",
|
|
|
|
args{
|
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-05-30 18:41:24 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Name: "{{.Nope}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
|
|
|
client.NewMock(),
|
|
|
|
},
|
|
|
|
[]artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
|
|
|
},
|
|
|
|
testlib.RequireTemplateError,
|
|
|
|
shouldNotErr,
|
|
|
|
noAssertions,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid description tmpl",
|
|
|
|
args{
|
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-05-30 18:41:24 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Description: "{{.Nope}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
|
|
|
client.NewMock(),
|
|
|
|
},
|
|
|
|
[]artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
|
|
|
},
|
|
|
|
testlib.RequireTemplateError,
|
|
|
|
shouldNotErr,
|
|
|
|
noAssertions,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid homepage tmpl",
|
|
|
|
args{
|
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-05-30 18:41:24 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
Homepage: "{{.Nope}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
|
|
|
client.NewMock(),
|
|
|
|
},
|
|
|
|
[]artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
|
|
|
},
|
|
|
|
testlib.RequireTemplateError,
|
|
|
|
shouldNotErr,
|
|
|
|
noAssertions,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid skip upload tmpl",
|
|
|
|
args{
|
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-05-30 18:41:24 +02:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
SkipUpload: "{{.Nope}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
|
|
|
client.NewMock(),
|
|
|
|
},
|
|
|
|
[]artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
|
|
|
},
|
|
|
|
testlib.RequireTemplateError,
|
|
|
|
shouldNotErr,
|
|
|
|
noAssertions,
|
|
|
|
},
|
2022-11-02 19:54:16 +02:00
|
|
|
{
|
|
|
|
"invalid ref tmpl",
|
|
|
|
args{
|
2023-04-30 15:18:13 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Owner: "{{ .Env.aaaaaa }}",
|
|
|
|
Name: "test",
|
2022-11-02 19:54:16 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
Folder: "scoops",
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
2022-11-02 19:54:16 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
2022-11-02 19:54:16 +02:00
|
|
|
client.NewMock(),
|
|
|
|
},
|
|
|
|
[]artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
|
|
|
},
|
|
|
|
testlib.RequireTemplateError,
|
2023-05-19 16:25:39 +02:00
|
|
|
shouldNotErr,
|
2022-11-02 19:54:16 +02:00
|
|
|
noAssertions,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"ref templ",
|
|
|
|
args{
|
2023-04-30 15:18:13 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Env: []string{"FOO=test", "BRANCH=main"},
|
|
|
|
ProjectName: "run-pipe",
|
2023-05-01 02:29:36 +02:00
|
|
|
Scoops: []config.Scoop{{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-30 15:18:13 +02:00
|
|
|
Owner: "{{ .Env.FOO }}",
|
|
|
|
Name: "{{ .Env.FOO }}",
|
|
|
|
Branch: "{{ .Env.BRANCH }}",
|
2022-11-02 19:54:16 +02:00
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
Folder: "scoops",
|
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
2023-05-01 02:29:36 +02:00
|
|
|
}},
|
2023-04-30 15:18:13 +02:00
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
2022-11-02 19:54:16 +02:00
|
|
|
client.NewMock(),
|
|
|
|
},
|
|
|
|
[]artifact.Artifact{
|
|
|
|
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Goamd64: "v1", Path: file},
|
|
|
|
},
|
|
|
|
shouldNotErr,
|
|
|
|
shouldNotErr,
|
|
|
|
func(tb testing.TB, a args) {
|
|
|
|
tb.Helper()
|
|
|
|
require.Equal(tb, "scoops/run-pipe.json", a.client.Path)
|
|
|
|
},
|
|
|
|
},
|
2018-02-10 15:55:03 +02:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-04-30 15:18:13 +02:00
|
|
|
ctx := tt.args.ctx
|
2023-06-01 19:15:21 +02:00
|
|
|
ctx.Config.Dist = t.TempDir()
|
2018-02-10 15:55:03 +02:00
|
|
|
for _, a := range tt.artifacts {
|
2023-05-01 02:29:36 +02:00
|
|
|
a := a
|
2021-12-08 02:52:35 +02:00
|
|
|
a.Type = artifact.UploadableArchive
|
2021-12-07 23:04:29 +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))
|
2023-05-01 02:29:36 +02:00
|
|
|
tt.assertRunError(t, runAll(ctx, tt.args.client))
|
|
|
|
if tt.assertPublishError != nil {
|
|
|
|
tt.assertPublishError(t, publishAll(ctx, tt.args.client))
|
|
|
|
}
|
2021-06-26 19:14:42 +02:00
|
|
|
tt.assert(t, tt.args)
|
2018-02-10 15:55:03 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-07 16:48:49 +02:00
|
|
|
func TestRunPipePullRequest(t *testing.T) {
|
|
|
|
folder := t.TempDir()
|
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
ProjectName: "foo",
|
2023-05-01 02:29:36 +02:00
|
|
|
Scoops: []config.Scoop{{
|
2023-05-30 18:41:24 +02:00
|
|
|
Name: "{{.Env.FOO}}",
|
|
|
|
Homepage: "https://{{.Env.FOO}}.com",
|
|
|
|
Description: "Fake desc for {{.ProjectName}}",
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2023-04-07 16:48:49 +02:00
|
|
|
Owner: "foo",
|
|
|
|
Name: "bar",
|
|
|
|
Branch: "update-{{.Version}}",
|
|
|
|
PullRequest: config.PullRequest{
|
|
|
|
Enabled: true,
|
|
|
|
},
|
|
|
|
},
|
2023-05-01 02:29:36 +02:00
|
|
|
}},
|
2023-04-07 16:48:49 +02:00
|
|
|
},
|
|
|
|
testctx.WithVersion("1.2.1"),
|
|
|
|
testctx.WithCurrentTag("v1.2.1"),
|
2023-05-30 18:41:24 +02:00
|
|
|
testctx.WithEnv(map[string]string{"FOO": "foobar"}),
|
2023-04-07 16:48:49 +02:00
|
|
|
)
|
|
|
|
path := filepath.Join(folder, "dist/foo_windows_amd64/foo.exe")
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Name: "foo_windows_amd64.tar.gz",
|
|
|
|
Path: path,
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "foo",
|
|
|
|
artifact.ExtraFormat: "tar.gz",
|
|
|
|
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()
|
2023-05-01 02:29:36 +02:00
|
|
|
require.NoError(t, runAll(ctx, client))
|
|
|
|
require.NoError(t, publishAll(ctx, client))
|
2023-04-07 16:48:49 +02:00
|
|
|
require.True(t, client.CreatedFile)
|
|
|
|
require.True(t, client.OpenedPullRequest)
|
|
|
|
golden.RequireEqualJSON(t, []byte(client.Content))
|
|
|
|
}
|
|
|
|
|
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",
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
2018-08-21 03:06:55 +02:00
|
|
|
GitHubURLs: config.GitHubURLs{
|
|
|
|
Download: "https://github.com",
|
2018-03-06 01:55:02 +02:00
|
|
|
},
|
2018-08-21 03:06:55 +02:00
|
|
|
ProjectName: "run-pipe",
|
|
|
|
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{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: 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
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
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",
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
2020-12-05 17:16:32 +02:00
|
|
|
GitHubURLs: config.GitHubURLs{
|
|
|
|
Download: "https://github.com",
|
|
|
|
},
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2020-12-05 17:16:32 +02:00
|
|
|
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'"},
|
|
|
|
},
|
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
2020-12-05 17:16:32 +02:00
|
|
|
},
|
2018-02-10 15:04:49 +02:00
|
|
|
{
|
2021-05-31 02:53:40 +02:00
|
|
|
"url template",
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
2018-08-21 03:06:55 +02:00
|
|
|
GitHubURLs: config.GitHubURLs{
|
|
|
|
Download: "https://github.com",
|
2018-03-06 01:55:02 +02:00
|
|
|
},
|
2018-08-21 03:06:55 +02:00
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: 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
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
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",
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.NewWithCfg(
|
|
|
|
config.Project{
|
2019-08-13 20:28:03 +02:00
|
|
|
GitLabURLs: config.GitLabURLs{
|
|
|
|
Download: "https://gitlab.com",
|
|
|
|
},
|
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: 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
|
|
|
},
|
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
),
|
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)
|
2022-04-12 03:43:22 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2020-07-06 15:48:17 +02:00
|
|
|
|
2023-05-01 02:29:36 +02:00
|
|
|
mf, err := dataFor(ctx, ctx.Config.Scoops[0], cl, []*artifact.Artifact{
|
2019-01-05 16:30:26 +02:00
|
|
|
{
|
2022-04-12 03:43:22 +02:00
|
|
|
Name: "foo_1.0.1_windows_amd64.tar.gz",
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-04-12 03:43:22 +02:00
|
|
|
Path: file,
|
2019-01-05 16:30:26 +02:00
|
|
|
Extra: map[string]interface{}{
|
2023-05-01 02:29:36 +02:00
|
|
|
artifact.ExtraBinaries: []string{
|
|
|
|
"foo.exe",
|
|
|
|
"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{}{
|
2023-07-18 02:26:18 +02:00
|
|
|
artifact.ExtraBinaries: []string{
|
|
|
|
"foo.exe",
|
|
|
|
"bar.exe",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "foo_1.0.1_windows_arm64.tar.gz",
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "arm64",
|
|
|
|
Path: file,
|
|
|
|
Extra: map[string]interface{}{
|
2023-05-01 02:29:36 +02:00
|
|
|
artifact.ExtraBinaries: []string{
|
|
|
|
"foo.exe",
|
|
|
|
"bar.exe",
|
2021-04-18 20:40:23 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
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{}{
|
2023-05-01 02:29:36 +02:00
|
|
|
artifact.ExtraBinaries: []string{
|
|
|
|
"foo.exe",
|
|
|
|
"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-08-03 04:37:02 +02:00
|
|
|
func getScoopPipeSkipCtx(folder string) (*context.Context, string) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
2021-05-25 21:49:49 +02:00
|
|
|
Dist: folder,
|
2021-05-24 19:30:31 +02:00
|
|
|
ProjectName: "run-pipe",
|
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2021-05-24 19:30:31 +02:00
|
|
|
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",
|
2021-05-24 19:30:31 +02:00
|
|
|
},
|
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
)
|
2021-08-03 04:37:02 +02:00
|
|
|
|
2021-05-24 19:30:31 +02:00
|
|
|
path := filepath.Join(folder, "bin.tar.gz")
|
2021-08-03 04:37:02 +02:00
|
|
|
|
2021-05-24 19:30:31 +02:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2022-04-12 03:43:22 +02:00
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: path,
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-04-12 03:43:22 +02:00
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "foo",
|
|
|
|
artifact.ExtraFormat: "tar.gz",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Name: "ignored.tar.gz",
|
|
|
|
Path: path,
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Goamd64: "v3",
|
|
|
|
Type: artifact.UploadableArchive,
|
2021-05-24 19:30:31 +02:00
|
|
|
Extra: map[string]interface{}{
|
2021-10-17 03:46:11 +02:00
|
|
|
artifact.ExtraID: "foo",
|
|
|
|
artifact.ExtraFormat: "tar.gz",
|
2021-05-24 19:30:31 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2021-08-03 04:37:02 +02:00
|
|
|
return ctx, path
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipeScoopWithSkipUpload(t *testing.T) {
|
|
|
|
folder := t.TempDir()
|
|
|
|
ctx, path := getScoopPipeSkipCtx(folder)
|
|
|
|
ctx.Config.Scoop.SkipUpload = "true"
|
|
|
|
|
2021-05-24 19:30:31 +02:00
|
|
|
f, err := os.Create(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, f.Close())
|
|
|
|
|
2021-10-03 18:24:20 +02:00
|
|
|
cli := client.NewMock()
|
2022-04-12 03:43:22 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2023-05-01 02:29:36 +02:00
|
|
|
require.NoError(t, runAll(ctx, cli))
|
|
|
|
require.EqualError(t, publishAll(ctx, cli), `scoop.skip_upload is true`)
|
2021-05-24 19:30:31 +02:00
|
|
|
|
2023-06-25 04:38:09 +02:00
|
|
|
distFile := filepath.Join(folder, "scoop", ctx.Config.Scoop.Name+".json")
|
2021-05-24 19:30:31 +02:00
|
|
|
_, 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))
|
2023-03-02 05:01:11 +02:00
|
|
|
|
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
2020-04-21 21:11:18 +02:00
|
|
|
GitLabURLs: config.GitLabURLs{
|
|
|
|
Download: "https://gitlab.com",
|
|
|
|
},
|
|
|
|
ProjectName: "run-pipe",
|
2023-05-01 02:29:36 +02:00
|
|
|
Scoops: []config.Scoop{{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: 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"},
|
2023-05-01 02:29:36 +02:00
|
|
|
}},
|
2020-04-21 21:11:18 +02:00
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
)
|
|
|
|
|
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)
|
2023-05-01 02:29:36 +02:00
|
|
|
mf, err := dataFor(ctx, ctx.Config.Scoops[0], cl, []*artifact.Artifact{
|
2020-04-21 21:11:18 +02:00
|
|
|
{
|
2022-04-12 03:43:22 +02:00
|
|
|
Name: "foo_1.0.1_windows_amd64.tar.gz",
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-04-12 03:43:22 +02:00
|
|
|
Path: file,
|
2020-04-21 21:11:18 +02:00
|
|
|
Extra: map[string]interface{}{
|
2021-10-17 03:46:11 +02:00
|
|
|
artifact.ExtraWrappedIn: "foo_1.0.1_windows_amd64",
|
2023-05-01 02:29:36 +02:00
|
|
|
artifact.ExtraBinaries: []string{
|
|
|
|
"foo.exe",
|
|
|
|
"bar.exe",
|
2020-04-21 21:11:18 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
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
|
|
|
}
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
func TestSkip(t *testing.T) {
|
|
|
|
t.Run("skip", func(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
require.True(t, Pipe{}.Skip(testctx.New()))
|
2021-09-18 15:21:29 +02:00
|
|
|
})
|
2023-11-04 01:33:31 +02:00
|
|
|
t.Run("skip flag", func(t *testing.T) {
|
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
|
|
Scoop: config.Scoop{
|
|
|
|
Repository: config.RepoRef{
|
|
|
|
Name: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, testctx.Skip(skips.Scoop))
|
2023-11-04 02:34:18 +02:00
|
|
|
require.True(t, Pipe{}.Skip(ctx))
|
2023-11-04 01:33:31 +02:00
|
|
|
})
|
2021-09-18 15:21:29 +02:00
|
|
|
t.Run("dont skip", func(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-18 15:21:29 +02:00
|
|
|
Scoop: config.Scoop{
|
2023-06-14 05:13:21 +02:00
|
|
|
Repository: config.RepoRef{
|
2021-09-18 15:21:29 +02:00
|
|
|
Name: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.False(t, Pipe{}.Skip(ctx))
|
|
|
|
})
|
|
|
|
}
|