mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-04-13 11:50:34 +02:00
feat: tmpl snap fields (#3003)
* feat: tmpl snap fields Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * added tests Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: broken test Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
parent
3df29b67ab
commit
37f0f37bc0
@ -140,6 +140,17 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
func doRun(ctx *context.Context, snap config.Snapcraft) error {
|
||||
tpl := tmpl.New(ctx)
|
||||
summary, err := tpl.Apply(snap.Summary)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
description, err := tpl.Apply(snap.Description)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
snap.Summary = summary
|
||||
snap.Description = description
|
||||
if snap.Summary == "" && snap.Description == "" {
|
||||
return pipe.Skip("no summary nor description were provided")
|
||||
}
|
||||
@ -149,7 +160,7 @@ func doRun(ctx *context.Context, snap config.Snapcraft) error {
|
||||
if snap.Description == "" {
|
||||
return ErrNoDescription
|
||||
}
|
||||
_, err := exec.LookPath("snapcraft")
|
||||
_, err = exec.LookPath("snapcraft")
|
||||
if err != nil {
|
||||
return ErrNoSnapcraft
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ func TestRunPipe(t *testing.T) {
|
||||
Snapcrafts: []config.Snapcraft{
|
||||
{
|
||||
NameTemplate: "foo_{{.Arch}}",
|
||||
Summary: "test summary",
|
||||
Description: "test description",
|
||||
Summary: "test summary {{.ProjectName}}",
|
||||
Description: "test description {{.ProjectName}}",
|
||||
Publish: true,
|
||||
Builds: []string{"foo"},
|
||||
ChannelTemplates: []string{"stable"},
|
||||
@ -87,6 +87,40 @@ func TestRunPipe(t *testing.T) {
|
||||
require.Len(t, list, 9)
|
||||
}
|
||||
|
||||
func TestBadTemolate(t *testing.T) {
|
||||
testlib.CheckPath(t, "snapcraft")
|
||||
folder := t.TempDir()
|
||||
dist := filepath.Join(folder, "dist")
|
||||
require.NoError(t, os.Mkdir(dist, 0o755))
|
||||
ctx := context.New(config.Project{
|
||||
ProjectName: "mybin",
|
||||
Dist: dist,
|
||||
Snapcrafts: []config.Snapcraft{
|
||||
{
|
||||
NameTemplate: "foo_{{.Arch}}",
|
||||
Publish: true,
|
||||
Builds: []string{"foo"},
|
||||
ChannelTemplates: []string{"stable"},
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.Git.CurrentTag = "v1.2.3"
|
||||
ctx.Version = "1.2.3"
|
||||
addBinaries(t, ctx, "foo", filepath.Join(dist, "foo"))
|
||||
|
||||
t.Run("description", func(t *testing.T) {
|
||||
ctx.Config.Snapcrafts[0].Description = "{{.Bad}}"
|
||||
ctx.Config.Snapcrafts[0].Summary = "summary"
|
||||
require.Error(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
|
||||
t.Run("summary", func(t *testing.T) {
|
||||
ctx.Config.Snapcrafts[0].Description = "description"
|
||||
ctx.Config.Snapcrafts[0].Summary = "{{.Bad}}"
|
||||
require.Error(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunPipeInvalidNameTemplate(t *testing.T) {
|
||||
testlib.CheckPath(t, "snapcraft")
|
||||
folder := t.TempDir()
|
||||
|
Loading…
x
Reference in New Issue
Block a user