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

feat: ConventionalExtension on nFPM (#3822)

closes  #3799

---------

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2023-03-02 14:35:55 -03:00 committed by GitHub
parent 3e6aa965e3
commit d5151a6eb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 12 deletions

View File

@ -396,14 +396,6 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar
return err
}
info = nfpm.WithDefaults(info)
name, err := t.WithExtraFields(tmpl.Fields{
"ConventionalFileName": packager.ConventionalFileName(info),
}).Apply(overridden.FileNameTemplate)
if err != nil {
return err
}
ext := "." + format
if packager, ok := packager.(nfpm.PackagerWithExtension); ok {
if format != "termux.deb" {
@ -411,6 +403,15 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar
}
}
info = nfpm.WithDefaults(info)
name, err := t.WithExtraFields(tmpl.Fields{
"ConventionalFileName": packager.ConventionalFileName(info),
"ConventionalExtension": ext,
}).Apply(overridden.FileNameTemplate)
if err != nil {
return err
}
if !strings.HasSuffix(name, ext) {
name = name + ext
}

View File

@ -1429,6 +1429,49 @@ func TestSkip(t *testing.T) {
})
}
func TestTemplateExt(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: t.TempDir(),
NFPMs: []config.NFPM{
{
NFPMOverridables: config.NFPMOverridables{
FileNameTemplate: "a_{{ .ConventionalExtension }}_b",
PackageName: "foo",
},
Meta: true,
Maintainer: "foo@bar",
Formats: []string{"deb", "rpm", "termux.deb", "apk", "archlinux"},
Builds: []string{"default"},
},
},
})
ctx.Artifacts.Add(&artifact.Artifact{
Name: "mybin",
Goos: "linux",
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
artifact.ExtraID: "default",
},
})
require.NoError(t, Pipe{}.Run(ctx))
packages := ctx.Artifacts.Filter(artifact.ByType(artifact.LinuxPackage)).List()
require.Len(t, packages, 5)
names := make([]string, 0, 5)
for _, p := range packages {
names = append(names, p.Name)
}
require.ElementsMatch(t, []string{
"a_.apk_b.apk",
"a_.deb_b.deb",
"a_.rpm_b.rpm",
"a_.termux.deb_b.termux.deb",
"a_.pkg.tar.zst_b.pkg.tar.zst",
}, names)
}
func sources(contents files.Contents) []string {
result := make([]string, 0, len(contents))
for _, f := range contents {

View File

@ -109,10 +109,11 @@ On the nFPM name template field, you can use those extra fields as well:
Key |Description
-----------------------|--------------------------------------------------------------
`.Release` |release from the nfpm config
`.Epoch` |epoch from the nfpm config
`.PackageName` |package the name. Same as `ProjectName` if not overridden.
`.ConventionalFileName`|conventional package file name as provided by nFPM[^arm-names]
`.Release` |release from the nfpm config
`.Epoch` |epoch from the nfpm config
`.PackageName` |package the name. Same as `ProjectName` if not overridden.
`.ConventionalFileName` |conventional package file name as provided by nFPM.[^arm-names]
`.ConventionalExtension`|conventional package extension as provided by nFPM. Since v1.16.
[^arm-names]: Please beware: some OSs might have the same names for different
ARM versions, for example, for Debian both ARMv6 and ARMv7 are called `armhf`.