mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-03 13:11:48 +02:00
fix(nix): description, path and homepage should allow templates (#4156)
- nix.description, nix.path, and nix.homepage should allow templates - nix.path was defaulting to wrong value, fixed --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
f883131e73
commit
5f7be841d8
@ -130,30 +130,42 @@ func (p Pipe) doRun(ctx *context.Context, nix config.Nix, cl client.ReleaserURLT
|
||||
return errNoRepoName
|
||||
}
|
||||
|
||||
name, err := tmpl.New(ctx).Apply(nix.Name)
|
||||
var err error
|
||||
|
||||
nix.Name, err = tmpl.New(ctx).Apply(nix.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nix.Name = name
|
||||
|
||||
ref, err := client.TemplateRef(tmpl.New(ctx).Apply, nix.Repository)
|
||||
nix.Repository, err = client.TemplateRef(tmpl.New(ctx).Apply, nix.Repository)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nix.Repository = ref
|
||||
|
||||
skipUpload, err := tmpl.New(ctx).Apply(nix.SkipUpload)
|
||||
nix.SkipUpload, err = tmpl.New(ctx).Apply(nix.SkipUpload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nix.SkipUpload = skipUpload
|
||||
|
||||
nix.Homepage, err = tmpl.New(ctx).Apply(nix.Homepage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nix.Description, err = tmpl.New(ctx).Apply(nix.Description)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nix.Path, err = tmpl.New(ctx).Apply(nix.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if nix.Path == "" {
|
||||
nix.Path = nix.Name + ".nix"
|
||||
nix.Path = path.Join("pkgs", nix.Name, "default.nix")
|
||||
}
|
||||
|
||||
path := filepath.Join(ctx.Config.Dist, "nix", nix.Path)
|
||||
filename := filepath.Base(path)
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -169,7 +181,7 @@ func (p Pipe) doRun(ctx *context.Context, nix config.Nix, cl client.ReleaserURLT
|
||||
}
|
||||
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
Name: filename,
|
||||
Name: filepath.Base(path),
|
||||
Path: path,
|
||||
Type: artifact.Nixpkg,
|
||||
Extra: map[string]interface{}{
|
||||
@ -328,9 +340,6 @@ func doPublish(ctx *context.Context, prefetcher shaPrefetcher, cl client.Client,
|
||||
repo := client.RepoFromRef(nix.Repository)
|
||||
|
||||
gpath := nix.Path
|
||||
if gpath == "" {
|
||||
gpath = path.Join("pkgs", nix.Name, "default.nix")
|
||||
}
|
||||
|
||||
msg, err := tmpl.New(ctx).Apply(nix.CommitMessageTemplate)
|
||||
if err != nil {
|
||||
|
@ -209,6 +209,28 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "bad-description-tmpl",
|
||||
expectRunErrorIs: &template.Error{},
|
||||
nix: config.Nix{
|
||||
Description: "{{ .Nope }}",
|
||||
Repository: config.RepoRef{
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "bad-homepage-tmpl",
|
||||
expectRunErrorIs: &template.Error{},
|
||||
nix: config.Nix{
|
||||
Homepage: "{{ .Nope }}",
|
||||
Repository: config.RepoRef{
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "bad-repo-tmpl",
|
||||
expectRunErrorIs: &template.Error{},
|
||||
@ -256,6 +278,18 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "bad-path-tmpl",
|
||||
expectRunErrorIs: &template.Error{},
|
||||
nix: config.Nix{
|
||||
Name: "foo",
|
||||
Path: `{{.Foo}}/bar/foo.nix`,
|
||||
Repository: config.RepoRef{
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "bad-release-url-tmpl",
|
||||
expectRunErrorIs: &template.Error{},
|
||||
@ -406,6 +440,11 @@ func TestRunPipe(t *testing.T) {
|
||||
}
|
||||
if tt.nix.Path != "" {
|
||||
require.Equal(t, tt.nix.Path, client.Path)
|
||||
} else {
|
||||
if tt.nix.Name == "" {
|
||||
tt.nix.Name = "foo"
|
||||
}
|
||||
require.Equal(t, "pkgs/"+tt.nix.Name+"/default.nix", client.Path)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -48,9 +48,12 @@ nix:
|
||||
# Path for the file inside the repository.
|
||||
#
|
||||
# Default: pkgs/<name>/default.nix
|
||||
# Templates: allowed
|
||||
path: pkgs/foo.nix
|
||||
|
||||
# Your app's homepage.
|
||||
#
|
||||
# Templates: allowed
|
||||
homepage: "https://example.com/"
|
||||
|
||||
# Your app's description.
|
||||
|
Loading…
x
Reference in New Issue
Block a user