mirror of
https://github.com/goreleaser/nfpm
synced 2024-05-04 15:06:19 +02:00
feat: hard fail on missing maintainer
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
a72ecd200b
commit
f82f4edaba
15
deb/deb.go
15
deb/deb.go
|
@ -19,7 +19,6 @@ import (
|
|||
"github.com/blakesmith/ar"
|
||||
"github.com/goreleaser/chglog"
|
||||
"github.com/goreleaser/nfpm/v2"
|
||||
"github.com/goreleaser/nfpm/v2/deprecation"
|
||||
"github.com/goreleaser/nfpm/v2/files"
|
||||
"github.com/goreleaser/nfpm/v2/internal/sign"
|
||||
"github.com/klauspost/compress/zstd"
|
||||
|
@ -105,7 +104,9 @@ func (d *Deb) Package(info *nfpm.Info, deb io.Writer) (err error) { // nolint: f
|
|||
}
|
||||
|
||||
// Set up some deb specific defaults
|
||||
d.SetPackagerDefaults(info)
|
||||
if err := d.setPackagerDefaults(info); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dataTarball, md5sums, instSize, dataTarballName, err := createDataTarball(info)
|
||||
if err != nil {
|
||||
|
@ -260,7 +261,7 @@ func readDpkgSigData(info *nfpm.Info, debianBinary, controlTarGz, dataTarball []
|
|||
return buf, nil
|
||||
}
|
||||
|
||||
func (*Deb) SetPackagerDefaults(info *nfpm.Info) {
|
||||
func (*Deb) setPackagerDefaults(info *nfpm.Info) error {
|
||||
// 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
|
||||
|
@ -268,14 +269,10 @@ func (*Deb) SetPackagerDefaults(info *nfpm.Info) {
|
|||
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 == "" {
|
||||
deprecation.Println("Leaving the 'maintainer' field unset will not be allowed in a future version")
|
||||
info.Maintainer = "Unset Maintainer <unset@localhost>"
|
||||
return fmt.Errorf("maintainer is required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addArFile(w *ar.Writer, name string, body []byte) error {
|
||||
|
|
|
@ -1353,19 +1353,27 @@ func extractFileFromAr(tb testing.TB, arFile []byte, filename string) []byte {
|
|||
return nil
|
||||
}
|
||||
|
||||
func TestEmptyButRequiredDebFieldsWithDefaults(t *testing.T) {
|
||||
item := nfpm.WithDefaults(&nfpm.Info{
|
||||
Name: "foo",
|
||||
Version: "v1.0.0",
|
||||
Maintainer: "foo@bar",
|
||||
})
|
||||
Default.setPackagerDefaults(item)
|
||||
|
||||
require.Equal(t, "optional", item.Priority)
|
||||
|
||||
var deb bytes.Buffer
|
||||
err := Default.Package(item, &deb)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
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)
|
||||
require.EqualError(t, Default.setPackagerDefaults(item), "maintainer is required")
|
||||
}
|
||||
|
||||
func TestArches(t *testing.T) {
|
||||
|
|
2
nfpm.go
2
nfpm.go
|
@ -250,7 +250,7 @@ type Info struct {
|
|||
VersionMetadata string `yaml:"version_metadata,omitempty" json:"version_metadata,omitempty" jsonschema:"title=version metadata,example=git"`
|
||||
Section string `yaml:"section,omitempty" json:"section,omitempty" jsonschema:"title=package section,example=default"`
|
||||
Priority string `yaml:"priority,omitempty" json:"priority,omitempty" jsonschema:"title=package priority,example=extra"`
|
||||
Maintainer string `yaml:"maintainer,omitempty" json:"maintainer,omitempty" jsonschema:"title=package maintainer,example=me@example.com"`
|
||||
Maintainer string `yaml:"maintainer" json:"maintainer" jsonschema:"title=package maintainer,example=me@example.com"`
|
||||
Description string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=package description"`
|
||||
Vendor string `yaml:"vendor,omitempty" json:"vendor,omitempty" jsonschema:"title=package vendor,example=MyCorp"`
|
||||
Homepage string `yaml:"homepage,omitempty" json:"homepage,omitempty" jsonschema:"title=package homepage,example=https://example.com"`
|
||||
|
|
Loading…
Reference in New Issue