mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-18 03:56:52 +02:00
feat(nfpm): allow to change package name (#1244)
* feat: allow to change package name Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: typo Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
parent
1cf86b86f6
commit
0953c2f4f7
@ -50,8 +50,15 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
if fpm.Bindir == "" {
|
||||
fpm.Bindir = "/usr/local/bin"
|
||||
}
|
||||
if fpm.NameTemplate == "" {
|
||||
fpm.NameTemplate = defaultNameTemplate
|
||||
if fpm.PackageName == "" {
|
||||
fpm.PackageName = ctx.Config.ProjectName
|
||||
}
|
||||
if fpm.NameTemplate != "" && fpm.FileNameTemplate == "" {
|
||||
deprecate.Notice("nfpms.name_template")
|
||||
fpm.FileNameTemplate = fpm.NameTemplate
|
||||
}
|
||||
if fpm.FileNameTemplate == "" {
|
||||
fpm.FileNameTemplate = defaultNameTemplate
|
||||
}
|
||||
if fpm.Files == nil {
|
||||
fpm.Files = map[string]string{}
|
||||
@ -125,7 +132,7 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
|
||||
}
|
||||
name, err := tmpl.New(ctx).
|
||||
WithArtifact(binaries[0], overridden.Replacements).
|
||||
Apply(overridden.NameTemplate)
|
||||
Apply(overridden.FileNameTemplate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -145,7 +152,7 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
|
||||
var info = &nfpm.Info{
|
||||
Arch: arch,
|
||||
Platform: "linux",
|
||||
Name: ctx.Config.ProjectName,
|
||||
Name: fpm.PackageName,
|
||||
Version: ctx.Version,
|
||||
Section: "",
|
||||
Priority: "",
|
||||
|
@ -40,8 +40,9 @@ func TestRunPipeInvalidFormat(t *testing.T) {
|
||||
Formats: []string{"nope"},
|
||||
Builds: []string{"foo"},
|
||||
NFPMOverridables: config.NFPMOverridables{
|
||||
NameTemplate: defaultNameTemplate,
|
||||
Files: map[string]string{},
|
||||
PackageName: "foo",
|
||||
FileNameTemplate: defaultNameTemplate,
|
||||
Files: map[string]string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -90,12 +91,13 @@ func TestRunPipe(t *testing.T) {
|
||||
Vendor: "asdf",
|
||||
Homepage: "https://goreleaser.github.io",
|
||||
NFPMOverridables: config.NFPMOverridables{
|
||||
NameTemplate: defaultNameTemplate,
|
||||
Dependencies: []string{"make"},
|
||||
Recommends: []string{"svn"},
|
||||
Suggests: []string{"bzr"},
|
||||
Conflicts: []string{"git"},
|
||||
EmptyFolders: []string{"/var/log/foobar"},
|
||||
FileNameTemplate: defaultNameTemplate,
|
||||
PackageName: "foo",
|
||||
Dependencies: []string{"make"},
|
||||
Recommends: []string{"svn"},
|
||||
Suggests: []string{"bzr"},
|
||||
Conflicts: []string{"git"},
|
||||
EmptyFolders: []string{"/var/log/foobar"},
|
||||
Files: map[string]string{
|
||||
"./testdata/testfile.txt": "/usr/share/testfile.txt",
|
||||
},
|
||||
@ -148,9 +150,12 @@ func TestInvalidNameTemplate(t *testing.T) {
|
||||
Config: config.Project{
|
||||
NFPMs: []config.NFPM{
|
||||
{
|
||||
NFPMOverridables: config.NFPMOverridables{NameTemplate: "{{.Foo}"},
|
||||
Formats: []string{"deb"},
|
||||
Builds: []string{"default"},
|
||||
NFPMOverridables: config.NFPMOverridables{
|
||||
PackageName: "foo",
|
||||
FileNameTemplate: "{{.Foo}",
|
||||
},
|
||||
Formats: []string{"deb"},
|
||||
Builds: []string{"default"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -206,6 +211,7 @@ func TestCreateFileDoesntExist(t *testing.T) {
|
||||
Formats: []string{"deb", "rpm"},
|
||||
Builds: []string{"default"},
|
||||
NFPMOverridables: config.NFPMOverridables{
|
||||
PackageName: "foo",
|
||||
Files: map[string]string{
|
||||
"testdata/testfile.txt": "/var/lib/test/testfile.txt",
|
||||
},
|
||||
@ -263,7 +269,8 @@ func TestInvalidConfig(t *testing.T) {
|
||||
func TestDefault(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
NFPMs: []config.NFPM{},
|
||||
ProjectName: "foobar",
|
||||
NFPMs: []config.NFPM{},
|
||||
Builds: []config.Build{
|
||||
{ID: "foo"},
|
||||
{ID: "bar"},
|
||||
@ -273,7 +280,8 @@ func TestDefault(t *testing.T) {
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.Equal(t, "/usr/local/bin", ctx.Config.NFPMs[0].Bindir)
|
||||
require.Equal(t, []string{"foo", "bar"}, ctx.Config.NFPMs[0].Builds)
|
||||
require.Equal(t, defaultNameTemplate, ctx.Config.NFPMs[0].NameTemplate)
|
||||
require.Equal(t, defaultNameTemplate, ctx.Config.NFPMs[0].FileNameTemplate)
|
||||
require.Equal(t, ctx.Config.ProjectName, ctx.Config.NFPMs[0].PackageName)
|
||||
}
|
||||
|
||||
func TestDefaultDeprecate(t *testing.T) {
|
||||
@ -292,10 +300,10 @@ func TestDefaultDeprecate(t *testing.T) {
|
||||
require.Equal(t, "/usr/local/bin", ctx.Config.NFPMs[0].Bindir)
|
||||
require.Equal(t, []string{"deb"}, ctx.Config.NFPMs[0].Formats)
|
||||
require.Equal(t, []string{"foo", "bar"}, ctx.Config.NFPMs[0].Builds)
|
||||
require.Equal(t, defaultNameTemplate, ctx.Config.NFPMs[0].NameTemplate)
|
||||
require.Equal(t, defaultNameTemplate, ctx.Config.NFPMs[0].FileNameTemplate)
|
||||
}
|
||||
|
||||
func TestDefaultSet(t *testing.T) {
|
||||
func TestDefaultDeprecated(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Builds: []config.Build{
|
||||
@ -315,7 +323,31 @@ func TestDefaultSet(t *testing.T) {
|
||||
}
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.Equal(t, "/bin", ctx.Config.NFPMs[0].Bindir)
|
||||
require.Equal(t, "foo", ctx.Config.NFPMs[0].NameTemplate)
|
||||
require.Equal(t, "foo", ctx.Config.NFPMs[0].FileNameTemplate)
|
||||
require.Equal(t, []string{"foo"}, ctx.Config.NFPMs[0].Builds)
|
||||
}
|
||||
|
||||
func TestDefaultSet(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Builds: []config.Build{
|
||||
{ID: "foo"},
|
||||
{ID: "bar"},
|
||||
},
|
||||
NFPMs: []config.NFPM{
|
||||
{
|
||||
Builds: []string{"foo"},
|
||||
Bindir: "/bin",
|
||||
NFPMOverridables: config.NFPMOverridables{
|
||||
FileNameTemplate: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.Equal(t, "/bin", ctx.Config.NFPMs[0].Bindir)
|
||||
require.Equal(t, "foo", ctx.Config.NFPMs[0].FileNameTemplate)
|
||||
require.Equal(t, []string{"foo"}, ctx.Config.NFPMs[0].Builds)
|
||||
}
|
||||
|
||||
|
@ -211,17 +211,19 @@ type NFPMScripts struct {
|
||||
|
||||
// NFPMOverridables is used to specify per package format settings
|
||||
type NFPMOverridables struct {
|
||||
NameTemplate string `yaml:"name_template,omitempty"`
|
||||
Epoch string `yaml:"epoch,omitempty"`
|
||||
Replacements map[string]string `yaml:",omitempty"`
|
||||
Dependencies []string `yaml:",omitempty"`
|
||||
Recommends []string `yaml:",omitempty"`
|
||||
Suggests []string `yaml:",omitempty"`
|
||||
Conflicts []string `yaml:",omitempty"`
|
||||
EmptyFolders []string `yaml:"empty_folders,omitempty"`
|
||||
Files map[string]string `yaml:",omitempty"`
|
||||
ConfigFiles map[string]string `yaml:"config_files,omitempty"`
|
||||
Scripts NFPMScripts `yaml:"scripts,omitempty"`
|
||||
FileNameTemplate string `yaml:"file_name_template,omitempty"`
|
||||
PackageName string `yaml:"package_name,omitempty"`
|
||||
NameTemplate string `yaml:"name_template,omitempty"` // deprecated
|
||||
Epoch string `yaml:"epoch,omitempty"`
|
||||
Replacements map[string]string `yaml:",omitempty"`
|
||||
Dependencies []string `yaml:",omitempty"`
|
||||
Recommends []string `yaml:",omitempty"`
|
||||
Suggests []string `yaml:",omitempty"`
|
||||
Conflicts []string `yaml:",omitempty"`
|
||||
EmptyFolders []string `yaml:"empty_folders,omitempty"`
|
||||
Files map[string]string `yaml:",omitempty"`
|
||||
ConfigFiles map[string]string `yaml:"config_files,omitempty"`
|
||||
Scripts NFPMScripts `yaml:"scripts,omitempty"`
|
||||
}
|
||||
|
||||
// Sign config
|
||||
|
@ -39,6 +39,27 @@ to this:
|
||||
|
||||
-->
|
||||
|
||||
### nfpms.name_template
|
||||
|
||||
> since 2019-11-15
|
||||
|
||||
The `name_template` field was deprecated in favor of a more clear one,
|
||||
`file_name_template`.
|
||||
|
||||
Change this:
|
||||
|
||||
```yaml
|
||||
nfpms:
|
||||
- name_template: foo
|
||||
```
|
||||
|
||||
to this:
|
||||
|
||||
```yaml
|
||||
nfpms:
|
||||
- file_name_template: foo
|
||||
```
|
||||
|
||||
|
||||
### blob
|
||||
|
||||
|
@ -18,9 +18,14 @@ nfpms:
|
||||
# ID of the nfpm config, must be unique.
|
||||
# Defaults to "default".
|
||||
id: foo
|
||||
# You can change the name of the package.
|
||||
|
||||
# Name of the package.
|
||||
# Defaults to `ProjectName`.
|
||||
package_name: foo
|
||||
|
||||
# You can change the file name of the package.
|
||||
# Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}`
|
||||
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
|
||||
file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
|
||||
|
||||
# Build IDs for the builds you want to create NFPM packages for.
|
||||
# Defaults to all builds.
|
||||
|
Loading…
x
Reference in New Issue
Block a user