Skip to content

Commit

Permalink
fix: nfpm deprecation on nfpm check (#3087)
Browse files Browse the repository at this point in the history
closes #3067

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed May 9, 2022
1 parent 4cf566b commit f812d1b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 40 deletions.
20 changes: 0 additions & 20 deletions internal/deprecate/deprecate.go
Expand Up @@ -4,9 +4,7 @@ package deprecate

import (
"bytes"
"io"
"strings"
"sync"
"text/template"

"github.com/apex/log"
Expand All @@ -17,24 +15,6 @@ import (

const baseURL = "https://goreleaser.com/deprecations#"

// NewWriter return a io.Writer that notices deprecations.
func NewWriter(ctx *context.Context) io.Writer {
return &writer{ctx: ctx}
}

type writer struct {
ctx *context.Context
once sync.Once
}

func (w *writer) Write(p []byte) (n int, err error) {
w.once.Do(func() {
w.ctx.Deprecated = true
})
log.Warn(color.New(color.Bold, color.FgHiYellow).Sprintf("DEPRECATED: " + strings.TrimSuffix(string(p), "\n")))
return len(p), nil
}

// Notice warns the user about the deprecation of the given property.
func Notice(ctx *context.Context, property string) {
NoticeCustom(ctx, property, "`{{ .Property }}` should not be used anymore, check {{ .URL }} for more info")
Expand Down
16 changes: 0 additions & 16 deletions internal/deprecate/deprecate_test.go
Expand Up @@ -42,19 +42,3 @@ func TestNoticeCustom(t *testing.T) {

golden.RequireEqualTxt(t, w.Bytes())
}

func TestWriter(t *testing.T) {
var w bytes.Buffer

color.NoColor = true
log.SetHandler(cli.New(&w))

log.Info("first")
ctx := context.New(config.Project{})
ww := NewWriter(ctx)
_, err := ww.Write([]byte("foo bar\n"))
require.NoError(t, err)
require.True(t, ctx.Deprecated)

golden.RequireEqualTxt(t, w.Bytes())
}
2 changes: 0 additions & 2 deletions internal/deprecate/testdata/TestWriter.txt.golden

This file was deleted.

9 changes: 8 additions & 1 deletion internal/pipe/nfpm/nfpm.go
Expand Up @@ -3,6 +3,7 @@ package nfpm

import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -54,10 +55,16 @@ func (Pipe) Default(ctx *context.Context) error {
if fpm.FileNameTemplate == "" {
fpm.FileNameTemplate = defaultNameTemplate
}
if len(fpm.EmptyFolders) > 0 {
deprecate.Notice(ctx, "nfpms.empty_folders")
}
if fpm.Maintainer == "" {
deprecate.Notice(ctx, "nfpms.maintainer")
}
ids.Inc(fpm.ID)
}

deprecation.Noticer = deprecate.NewWriter(ctx)
deprecation.Noticer = io.Discard
return ids.Validate()
}

Expand Down
21 changes: 20 additions & 1 deletion www/docs/deprecations.md
Expand Up @@ -36,6 +36,25 @@ Description.
-->

### nfpms.maintainer

> since 2022-05-07 (v1.9.0)
nFPM will soon make mandatory setting the maintainer field.

=== "Before"
```yaml
nfpms:
- maintainer: ''
```

=== "After"
```yaml
nfpms:
- maintainer: 'Name <email>'
```


### rigs

> since 2022-03-21 (v1.8.0)
Expand Down Expand Up @@ -74,7 +93,7 @@ On [GoReleaser PRO](/pro/) custom variables should now be prefixed with `.Var`.
some_template: 'lala-{{ .Var.foo }}'
```

### nfpm.empty_folders
### nfpms.empty_folders

> since 2021-11-14 (v1.0.0)
Expand Down

0 comments on commit f812d1b

Please sign in to comment.