mirror of
https://github.com/goreleaser/nfpm
synced 2024-05-04 02:36:04 +02:00
feat: add support for additional fields in Debian control files (#491)
Debian control files (DCF) have a number of optional fields [0] -- including "Bugs" and "Tags" -- that are used by many existing packages. The original fpm supports adding arbitrary fields to DCFs with the --deb-field flag [1], but until now it was not possible to do so with nfpm. This commit introduces a new deb-specific override, "fields", that simply translates key-value pairs from a map directly into the DCF. Given the following nfpm config file entry: deb: fields: Bugs: https://github.com/goreleaser/nfpm/issues The resulting DCF would contain the entry Bugs: https://github.com/goreleaser/nfpm/issues To avoid generating malformed DCFs, we simply ignore empty entries. This commit includes unit tests and updates to the website documentation. Closes #490. [0]: https://man7.org/linux/man-pages/man5/deb-control.5.html [1]: https://fpm.readthedocs.io/en/latest/packages/deb.html?highlight=changelog#deb-specific-command-line-flags Signed-off-by: Aaron Jacobs <aaron.jacobs@rstudio.com>
This commit is contained in:
parent
4a6d81ca8b
commit
98a59ec16d
|
@ -718,6 +718,11 @@ Homepage: {{.Info.Homepage}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- /* Mandatory fields */}}
|
{{- /* Mandatory fields */}}
|
||||||
Description: {{multiline .Info.Description}}
|
Description: {{multiline .Info.Description}}
|
||||||
|
{{- range $key, $value := .Info.Deb.Fields }}
|
||||||
|
{{- if $value }}
|
||||||
|
{{$key}}: {{$value}}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
`
|
`
|
||||||
|
|
||||||
type controlData struct {
|
type controlData struct {
|
||||||
|
|
|
@ -1267,3 +1267,34 @@ func TestArches(t *testing.T) {
|
||||||
require.Equal(t, "foo64", info.Arch)
|
require.Equal(t, "foo64", info.Arch)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFields(t *testing.T) {
|
||||||
|
var w bytes.Buffer
|
||||||
|
require.NoError(t, writeControl(&w, controlData{
|
||||||
|
Info: nfpm.WithDefaults(&nfpm.Info{
|
||||||
|
Name: "foo",
|
||||||
|
Description: "Foo does things",
|
||||||
|
Priority: "extra",
|
||||||
|
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
|
||||||
|
Version: "v1.0.0",
|
||||||
|
Section: "default",
|
||||||
|
Homepage: "http://carlosbecker.com",
|
||||||
|
Overridables: nfpm.Overridables{
|
||||||
|
Deb: nfpm.Deb{
|
||||||
|
Fields: map[string]string{
|
||||||
|
"Bugs": "https://github.com/goreleaser/nfpm/issues",
|
||||||
|
"Empty": "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
InstalledSize: 10,
|
||||||
|
}))
|
||||||
|
golden := "testdata/control3.golden"
|
||||||
|
if *update {
|
||||||
|
require.NoError(t, ioutil.WriteFile(golden, w.Bytes(), 0o600))
|
||||||
|
}
|
||||||
|
bts, err := ioutil.ReadFile(golden) //nolint:gosec
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, string(bts), w.String())
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
Package: foo
|
||||||
|
Version: 1.0.0
|
||||||
|
Section: default
|
||||||
|
Priority: extra
|
||||||
|
Architecture: amd64
|
||||||
|
Maintainer: Carlos A Becker <pkg@carlosbecker.com>
|
||||||
|
Installed-Size: 10
|
||||||
|
Homepage: http://carlosbecker.com
|
||||||
|
Description: Foo does things
|
||||||
|
Bugs: https://github.com/goreleaser/nfpm/issues
|
13
nfpm.go
13
nfpm.go
|
@ -321,12 +321,13 @@ type APKScripts struct {
|
||||||
|
|
||||||
// Deb is custom configs that are only available on deb packages.
|
// Deb is custom configs that are only available on deb packages.
|
||||||
type Deb struct {
|
type Deb struct {
|
||||||
Arch string `yaml:"arch,omitempty" jsonschema:"title=architecture in deb nomenclature"`
|
Arch string `yaml:"arch,omitempty" jsonschema:"title=architecture in deb nomenclature"`
|
||||||
Scripts DebScripts `yaml:"scripts,omitempty" jsonschema:"title=scripts"`
|
Scripts DebScripts `yaml:"scripts,omitempty" jsonschema:"title=scripts"`
|
||||||
Triggers DebTriggers `yaml:"triggers,omitempty" jsonschema:"title=triggers"`
|
Triggers DebTriggers `yaml:"triggers,omitempty" jsonschema:"title=triggers"`
|
||||||
Breaks []string `yaml:"breaks,omitempty" jsonschema:"title=breaks"`
|
Breaks []string `yaml:"breaks,omitempty" jsonschema:"title=breaks"`
|
||||||
Signature DebSignature `yaml:"signature,omitempty" jsonschema:"title=signature"`
|
Signature DebSignature `yaml:"signature,omitempty" jsonschema:"title=signature"`
|
||||||
Compression string `yaml:"compression,omitempty" jsonschema:"title=compression algorithm to be used,enum=gzip,enum=xz,enum=none,default=gzip"`
|
Compression string `yaml:"compression,omitempty" jsonschema:"title=compression algorithm to be used,enum=gzip,enum=xz,enum=none,default=gzip"`
|
||||||
|
Fields map[string]string `yaml:"fields,omitempty" jsonschema:"title=fields"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DebSignature struct {
|
type DebSignature struct {
|
||||||
|
|
|
@ -305,6 +305,10 @@ deb:
|
||||||
# This will expand any env var you set in the field, eg key_id: ${DEB_SIGNING_KEY_ID}
|
# This will expand any env var you set in the field, eg key_id: ${DEB_SIGNING_KEY_ID}
|
||||||
key_id: bc8acdd415bd80b3
|
key_id: bc8acdd415bd80b3
|
||||||
|
|
||||||
|
# Additional fields for the control file. Empty fields are ignored.
|
||||||
|
fields:
|
||||||
|
Bugs: https://github.com/goreleaser/nfpm/issues
|
||||||
|
|
||||||
apk:
|
apk:
|
||||||
# apk specific architecture name that overrides "arch" without performing any replacements.
|
# apk specific architecture name that overrides "arch" without performing any replacements.
|
||||||
apk_arch: armhf
|
apk_arch: armhf
|
||||||
|
|
Loading…
Reference in New Issue