Skip to content

Commit

Permalink
feat(nfpm): add .Format tmpl var
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Jan 31, 2024
1 parent 765d534 commit b294759
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions internal/pipe/nfpm/nfpm.go
Expand Up @@ -218,6 +218,10 @@ func create(ctx *context.Context, fpm config.NFPM, format string, artifacts []*a

// We cannot use t.ApplyAll on the following fields as they are shared
// across multiple nfpms.
//
t = t.WithExtraFields(tmpl.Fields{
"Format": format,
})

debKeyFile, err := t.Apply(overridden.Deb.Signature.KeyFile)
if err != nil {
Expand Down
14 changes: 10 additions & 4 deletions internal/pipe/nfpm/nfpm_test.go
Expand Up @@ -108,7 +108,7 @@ func TestRunPipe(t *testing.T) {

}
libPrefix := `/usr/lib
{{- if eq .Arch "amd64" }}64{{- end -}}
{{- if eq .Arch "amd64" }}{{if eq .Format "rpm"}}_rpm{{end}}64{{- end -}}
`
ctx := testctx.NewWithCfg(config.Project{
ProjectName: "mybin",
Expand Down Expand Up @@ -439,9 +439,15 @@ func TestRunPipe(t *testing.T) {
carchive := "/usr/lib/c-archives"
cshared := "/usr/lib/c-shareds"
if pkg.Goarch == "amd64" {
header = "/usr/lib64/headers"
carchive = "/usr/lib64/c-archives"
cshared = "/usr/lib64/c-shareds"
if pkg.Format() == "rpm" {
header = "/usr/lib_rpm64/headers"
carchive = "/usr/lib_rpm64/c-archives"
cshared = "/usr/lib_rpm64/c-shareds"
} else {
header = "/usr/lib64/headers"
carchive = "/usr/lib64/c-archives"
cshared = "/usr/lib64/c-shareds"
}
}
if format == termuxFormat {
bin = filepath.Join("/data/data/com.termux/files", bin)
Expand Down
1 change: 1 addition & 0 deletions www/docs/customization/templates.md
Expand Up @@ -121,6 +121,7 @@ In the nFPM name template field, you can use those extra fields:
| `.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 |
| `.Format` | package format. Since v1.24 |

[^arm-names]:
Please beware: some OSs might have the same names for different
Expand Down

0 comments on commit b294759

Please sign in to comment.