1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-04-11 11:42:15 +02:00

feat(nfpm): template homepage and description (#2272)

* feat(nfpm): template homepage and description

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* chore: fumpt

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker 2021-05-31 21:59:46 -03:00 committed by GitHub
parent 2375c93359
commit f4e79655a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 12 deletions

View File

@ -186,6 +186,16 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
return err
}
homepage, err := tmpl.Apply(fpm.Homepage)
if err != nil {
return err
}
description, err := tmpl.Apply(fpm.Description)
if err != nil {
return err
}
contents := files.Contents{}
for _, content := range overridden.Contents {
src, err := tmpl.Apply(content.Source)
@ -233,9 +243,9 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
Prerelease: fpm.Prerelease,
VersionMetadata: fpm.VersionMetadata,
Maintainer: fpm.Maintainer,
Description: fpm.Description,
Description: description,
Vendor: fpm.Vendor,
Homepage: fpm.Homepage,
Homepage: homepage,
License: fpm.License,
Overridables: nfpm.Overridables{
Conflicts: overridden.Conflicts,

View File

@ -84,6 +84,10 @@ func TestRunPipe(t *testing.T) {
ctx := context.New(config.Project{
ProjectName: "mybin",
Dist: dist,
Env: []string{
"PRO=pro",
"DESC=templates",
},
NFPMs: []config.NFPM{
{
ID: "someid",
@ -92,11 +96,11 @@ func TestRunPipe(t *testing.T) {
Formats: []string{"deb", "rpm", "apk"},
Section: "somesection",
Priority: "standard",
Description: "Some description",
Description: "Some description with {{ .Env.DESC }}",
License: "MIT",
Maintainer: "me@me",
Vendor: "asdf",
Homepage: "https://goreleaser.github.io",
Homepage: "https://goreleaser.com/{{ .Env.PRO }}",
NFPMOverridables: config.NFPMOverridables{
FileNameTemplate: defaultNameTemplate + "-{{ .Release }}-{{ .Epoch }}",
PackageName: "foo",
@ -215,7 +219,6 @@ func TestInvalidNameTemplate(t *testing.T) {
t.Run("filename_template", func(t *testing.T) {
ctx := makeCtx()
ctx.Config.NFPMs[0].NFPMOverridables = config.NFPMOverridables{
PackageName: "foo",
FileNameTemplate: "{{.Foo}",
}
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1: unexpected "}" in operand`)
@ -224,8 +227,6 @@ func TestInvalidNameTemplate(t *testing.T) {
t.Run("source", func(t *testing.T) {
ctx := makeCtx()
ctx.Config.NFPMs[0].NFPMOverridables = config.NFPMOverridables{
PackageName: "foo",
FileNameTemplate: "Foo",
Contents: files.Contents{
{
Source: "{{ .NOPE_SOURCE }}",
@ -239,8 +240,6 @@ func TestInvalidNameTemplate(t *testing.T) {
t.Run("target", func(t *testing.T) {
ctx := makeCtx()
ctx.Config.NFPMs[0].NFPMOverridables = config.NFPMOverridables{
PackageName: "foo",
FileNameTemplate: "Foo",
Contents: files.Contents{
{
Source: "./testdata/testfile.txt",
@ -250,6 +249,18 @@ func TestInvalidNameTemplate(t *testing.T) {
}
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_TARGET>: map has no entry for key "NOPE_TARGET"`)
})
t.Run("description", func(t *testing.T) {
ctx := makeCtx()
ctx.Config.NFPMs[0].Description = "{{ .NOPE_DESC }}"
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_DESC>: map has no entry for key "NOPE_DESC"`)
})
t.Run("homepage", func(t *testing.T) {
ctx := makeCtx()
ctx.Config.NFPMs[0].Homepage = "{{ .NOPE_HOMEPAGE }}"
require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_HOMEPAGE>: map has no entry for key "NOPE_HOMEPAGE"`)
})
}
func TestRunPipeInvalidContentsSourceTemplate(t *testing.T) {

View File

@ -81,7 +81,7 @@ brews:
# Default is empty.
homepage: "https://example.com/"
# Your app's description.
# Template of your app's description.
# Default is empty.
description: "Software to create fast and easy drum rolls."

View File

@ -43,7 +43,8 @@ nfpms:
# Your app's vendor.
# Default is empty.
vendor: Drum Roll Inc.
# Your app's homepage.
# Template to your app's homepage.
# Default is empty.
homepage: https://example.com/
@ -51,7 +52,7 @@ nfpms:
# Default is empty.
maintainer: Drummer <drum-roll@example.com>
# Your app's description.
# Template to your app's description.
# Default is empty.
description: Software to create fast and easy drum rolls.