Skip to content

Commit

Permalink
feat: remove deprecated nfpm (#1280)
Browse files Browse the repository at this point in the history
* clean: remove deprecated nfpm

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: test

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Dec 27, 2019
1 parent 05116ff commit 885a971
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 84 deletions.
18 changes: 6 additions & 12 deletions internal/pipe/nfpm/nfpm.go
Expand Up @@ -5,9 +5,14 @@ import (
"fmt"
"os"
"path/filepath"
"reflect"

"github.com/apex/log"
"github.com/goreleaser/nfpm"
_ "github.com/goreleaser/nfpm/deb" // blank import to register the format
_ "github.com/goreleaser/nfpm/rpm" // blank import to register the format
"github.com/imdario/mergo"
"github.com/pkg/errors"

"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/deprecate"
"github.com/goreleaser/goreleaser/internal/ids"
Expand All @@ -17,11 +22,6 @@ import (
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/goreleaser/nfpm"
_ "github.com/goreleaser/nfpm/deb" // blank import to register the format
_ "github.com/goreleaser/nfpm/rpm" // blank import to register the format
"github.com/imdario/mergo"
"github.com/pkg/errors"
)

const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
Expand All @@ -35,12 +35,6 @@ func (Pipe) String() string {

// Default sets the pipe defaults
func (Pipe) Default(ctx *context.Context) error {
if len(ctx.Config.NFPMs) == 0 {
ctx.Config.NFPMs = append(ctx.Config.NFPMs, ctx.Config.NFPM)
if !reflect.DeepEqual(ctx.Config.NFPM, config.NFPM{}) {
deprecate.Notice("nfpm")
}
}
var ids = ids.New("nfpms")
for i := range ctx.Config.NFPMs {
var fpm = &ctx.Config.NFPMs[i]
Expand Down
53 changes: 8 additions & 45 deletions internal/pipe/nfpm/nfpm_test.go
Expand Up @@ -24,7 +24,11 @@ func TestRunPipeNoFormats(t *testing.T) {
Git: context.GitInfo{
CurrentTag: "v1.0.0",
},
Config: config.Project{},
Config: config.Project{
NFPMs: []config.NFPM{
{},
},
},
Parallelism: runtime.NumCPU(),
}
require.NoError(t, Pipe{}.Default(ctx))
Expand Down Expand Up @@ -270,25 +274,8 @@ func TestDefault(t *testing.T) {
var ctx = &context.Context{
Config: config.Project{
ProjectName: "foobar",
NFPMs: []config.NFPM{},
Builds: []config.Build{
{ID: "foo"},
{ID: "bar"},
},
},
}
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "/usr/local/bin", ctx.Config.NFPMs[0].Bindir)
require.Equal(t, []string{"foo", "bar"}, ctx.Config.NFPMs[0].Builds)
require.Equal(t, defaultNameTemplate, ctx.Config.NFPMs[0].FileNameTemplate)
require.Equal(t, ctx.Config.ProjectName, ctx.Config.NFPMs[0].PackageName)
}

func TestDefaultDeprecate(t *testing.T) {
var ctx = &context.Context{
Config: config.Project{
NFPM: config.NFPM{
Formats: []string{"deb"},
NFPMs: []config.NFPM{
{},
},
Builds: []config.Build{
{ID: "foo"},
Expand All @@ -298,33 +285,9 @@ func TestDefaultDeprecate(t *testing.T) {
}
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "/usr/local/bin", ctx.Config.NFPMs[0].Bindir)
require.Equal(t, []string{"deb"}, ctx.Config.NFPMs[0].Formats)
require.Equal(t, []string{"foo", "bar"}, ctx.Config.NFPMs[0].Builds)
require.Equal(t, defaultNameTemplate, ctx.Config.NFPMs[0].FileNameTemplate)
}

func TestDefaultDeprecated(t *testing.T) {
var ctx = &context.Context{
Config: config.Project{
Builds: []config.Build{
{ID: "foo"},
{ID: "bar"},
},
NFPMs: []config.NFPM{
{
Builds: []string{"foo"},
Bindir: "/bin",
NFPMOverridables: config.NFPMOverridables{
NameTemplate: "foo",
},
},
},
},
}
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "/bin", ctx.Config.NFPMs[0].Bindir)
require.Equal(t, "foo", ctx.Config.NFPMs[0].FileNameTemplate)
require.Equal(t, []string{"foo"}, ctx.Config.NFPMs[0].Builds)
require.Equal(t, ctx.Config.ProjectName, ctx.Config.NFPMs[0].PackageName)
}

func TestDefaultSet(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion pkg/config/config.go
Expand Up @@ -360,7 +360,6 @@ type Project struct {
Builds []Build `yaml:",omitempty"`
Archive Archive `yaml:",omitempty"` // TODO: remove this
Archives []Archive `yaml:",omitempty"`
NFPM NFPM `yaml:",omitempty"` // TODO: remove this
NFPMs []NFPM `yaml:"nfpms,omitempty"`
Snapcraft Snapcraft `yaml:",omitempty"` // TODO: remove this
Snapcrafts []Snapcraft `yaml:",omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/config_test.go
Expand Up @@ -25,14 +25,14 @@ func TestEmptyRepoNameAndOwner(t *testing.T) {

func TestLoadReader(t *testing.T) {
var conf = `
nfpm:
homepage: http://goreleaser.github.io
nfpms:
- homepage: http://goreleaser.github.io
`
buf := strings.NewReader(conf)
prop, err := LoadReader(buf)

assert.NoError(t, err)
assert.Equal(t, "http://goreleaser.github.io", prop.NFPM.Homepage, "yaml did not load correctly")
assert.Equal(t, "http://goreleaser.github.io", prop.NFPMs[0].Homepage, "yaml did not load correctly")
}

type errorReader struct{}
Expand Down
46 changes: 23 additions & 23 deletions www/content/deprecations.md
Expand Up @@ -177,7 +177,7 @@ blobs:

### snapcraft

> since 2019-05-39
> since 2019-05-27
We now allow multiple Snapcraft configs, so the `snapcraft` statement will be removed.

Expand All @@ -198,54 +198,54 @@ snapcrafts:
# ...
```

### nfpm
### archive

> since 2019-05-07
> since 2019-04-16
We now allow multiple NFPM config, so the `nfpm` statement will be removed.
We now allow multiple archives, so the `archive` statement will be removed.

Change this:

```yaml
nfpm:
formats:
- deb
archive:
format: zip
```

to this:

```yaml
nfpms:
-
formats:
- deb
archives:
- id: foo
format: zip
```

### archive
## Expired deprecation notices

> since 2019-04-16
The following options were deprecated for ~6 months and are now fully removed.

We now allow multiple archives, so the `archive` statement will be removed.
### nfpm

> since 2019-05-07, removed 2019-12-27
We now allow multiple NFPM config, so the `nfpm` statement will be removed.

Change this:

```yaml
archive:
format: zip
nfpm:
formats:
- deb
```

to this:

```yaml
archives:
- id: foo
format: zip
nfpms:
-
formats:
- deb
```

## Expired deprecation notices

The following options were deprecated for ~6 months and are now fully removed.

### docker.binary

> since 2018-10-01, removed 2019-08-02
Expand Down

0 comments on commit 885a971

Please sign in to comment.