1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

feat(scoop): allow to template description and homepage (#4057)

make `scoops.description` and `scoops.homepage` templateable as well.
This commit is contained in:
Carlos Alexandro Becker 2023-05-30 13:41:24 -03:00 committed by GitHub
parent 79a9315eff
commit 1d92a36340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 130 additions and 5 deletions

View File

@ -149,6 +149,18 @@ func doRun(ctx *context.Context, scoop config.Scoop, cl client.ReleaserURLTempla
}
scoop.Name = name
description, err := tmpl.New(ctx).Apply(scoop.Description)
if err != nil {
return err
}
scoop.Description = description
homepage, err := tmpl.New(ctx).Apply(scoop.Homepage)
if err != nil {
return err
}
scoop.Homepage = homepage
ref, err := client.TemplateRef(tmpl.New(ctx).Apply, scoop.Bucket)
if err != nil {
return err

View File

@ -566,6 +566,114 @@ func Test_doRun(t *testing.T) {
shouldNotErr,
noAssertions,
},
{
"invalid name tmpl",
args{
testctx.NewWithCfg(
config.Project{
ProjectName: "run-pipe",
Scoop: config.Scoop{
Bucket: config.RepoRef{
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{
Bucket: config.RepoRef{
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{
Bucket: config.RepoRef{
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{
Bucket: config.RepoRef{
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,
},
{
"invalid ref tmpl",
args{
@ -655,9 +763,9 @@ func TestRunPipePullRequest(t *testing.T) {
Dist: folder,
ProjectName: "foo",
Scoops: []config.Scoop{{
Name: "foo",
Homepage: "https://goreleaser.com",
Description: "Fake desc",
Name: "{{.Env.FOO}}",
Homepage: "https://{{.Env.FOO}}.com",
Description: "Fake desc for {{.ProjectName}}",
Bucket: config.RepoRef{
Owner: "foo",
Name: "bar",
@ -670,6 +778,7 @@ func TestRunPipePullRequest(t *testing.T) {
},
testctx.WithVersion("1.2.1"),
testctx.WithCurrentTag("v1.2.1"),
testctx.WithEnv(map[string]string{"FOO": "foobar"}),
)
path := filepath.Join(folder, "dist/foo_windows_amd64/foo.exe")
ctx.Artifacts.Add(&artifact.Artifact{

View File

@ -7,6 +7,6 @@
"hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
},
"homepage": "https://goreleaser.com",
"description": "Fake desc"
"homepage": "https://foobar.com",
"description": "Fake desc for foo"
}

View File

@ -124,9 +124,13 @@ scoops:
commit_msg_template: "Scoop update for {{ .ProjectName }} version {{ .Tag }}"
# Your app's homepage.
#
# Templates: allowed (since v1.19)
homepage: "https://example.com/"
# Your app's description.
#
# Templates: allowed (since v1.19)
description: "Software to create fast and easy drum rolls."
# Your app's license