1
1
mirror of https://github.com/goreleaser/nfpm synced 2024-11-18 23:14:12 +01:00

feat: enforce packager defaults (#372)

* feat: apply defaults to required deb values

* feat: Adding default info to config documentation

* fix: cleanup comments

* refactor: implementing refactor from PR discussion

* fix: making deprecation warning more clear
This commit is contained in:
Drew Stinnett 2021-10-11 08:50:43 -04:00 committed by GitHub
parent 1a515b4d32
commit 56c46c6d50
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 2 deletions

@ -82,7 +82,7 @@ func (*Deb) ConventionalFileName(info *nfpm.Info) string {
var ErrInvalidSignatureType = errors.New("invalid signature type")
// Package writes a new deb package to the given writer using the given info.
func (*Deb) Package(info *nfpm.Info, deb io.Writer) (err error) { // nolint: funlen
func (d *Deb) Package(info *nfpm.Info, deb io.Writer) (err error) { // nolint: funlen
arch, ok := archToDebian[info.Arch]
if ok {
info.Arch = arch
@ -91,6 +91,9 @@ func (*Deb) Package(info *nfpm.Info, deb io.Writer) (err error) { // nolint: fun
return err
}
// Set up some deb specific defaults
d.SetPackagerDefaults(info)
dataTarball, md5sums, instSize, dataTarballName, err := createDataTarball(info)
if err != nil {
return err
@ -151,6 +154,24 @@ func (*Deb) Package(info *nfpm.Info, deb io.Writer) (err error) { // nolint: fun
return nil
}
func (*Deb) SetPackagerDefaults(info *nfpm.Info) {
// Priority should be set on all packages per:
// https://www.debian.org/doc/debian-policy/ch-archive.html#priorities
// "optional" seems to be the safe/sane default here
if info.Priority == "" {
info.Priority = "optional"
}
// The safe thing here feels like defaulting to something like below.
// That will prevent existing configs from breaking anyway... Wondering
// if in the long run we should be more strict about this and error when
// not set?
if info.Maintainer == "" {
log.Println("DEPRECATION WARNING: Leaving the 'maintainer' field unset will not be allowed in a future version")
info.Maintainer = "Unset Maintainer <unset@localhost>"
}
}
func addArFile(w *ar.Writer, name string, body []byte) error {
header := ar.Header{
Name: files.ToNixPath(name),

@ -1071,3 +1071,18 @@ func extractFileFromAr(tb testing.TB, arFile []byte, filename string) []byte {
return nil
}
func TestEmptyButRequiredDebFields(t *testing.T) {
item := nfpm.WithDefaults(&nfpm.Info{
Name: "foo",
Version: "v1.0.0",
})
Default.SetPackagerDefaults(item)
require.Equal(t, "optional", item.Priority)
require.Equal(t, "Unset Maintainer <unset@localhost>", item.Maintainer)
var deb bytes.Buffer
err := Default.Package(item, &deb)
require.NoError(t, err)
}

@ -46,9 +46,14 @@ release: 1
section: default
# Priority.
# Defaults to `optional` on deb
# Defaults to empty on rpm and apk
priority: extra
# Maintaner.
# Maintainer.
# Defaults to empty on rpm and apk
# Leaving this field empty on 'deb' packages is deprecated, and will be removed
# in a future release
maintainer: Carlos Alexandro Becker <root@carlosbecker.com>
# Description.