Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enforce packager defaults #372

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand Down
15 changes: 15 additions & 0 deletions deb/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 6 additions & 1 deletion www/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down