mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
fix: better deprecation notices (#561)
* fix: better deprecation notices * test: covered deprecate with tests * docs: improved docs * docs: improved docs * chore: organize imports * style: code improve
This commit is contained in:
parent
42427782ac
commit
0694b46bcc
@ -3,3 +3,98 @@ title: Deprecation notices
|
||||
---
|
||||
|
||||
This page will be used to list deprecation notices accross GoReleaser.
|
||||
|
||||
<!--
|
||||
|
||||
Template for new deprecations:
|
||||
|
||||
## property
|
||||
|
||||
> since yyyy-mm-dd
|
||||
|
||||
Description.
|
||||
|
||||
Change this:
|
||||
|
||||
```yaml
|
||||
```
|
||||
|
||||
to this:
|
||||
|
||||
```yaml
|
||||
```
|
||||
|
||||
-->
|
||||
|
||||
## fpm
|
||||
|
||||
> since 2018-02-17
|
||||
|
||||
FPM is deprecated in favor of nfpm, which is a simpler alternative written
|
||||
in Go. The objective is to remove the ruby dependency thus simplify the
|
||||
CI/CD pipelines.
|
||||
|
||||
Just replace the `fpm` keyword by `nfpm` in your `goreleaser.yaml` file.
|
||||
|
||||
Change this:
|
||||
|
||||
```yaml
|
||||
fpm:
|
||||
# ...
|
||||
```
|
||||
|
||||
to this:
|
||||
|
||||
```yaml
|
||||
nfpm:
|
||||
# ...
|
||||
```
|
||||
|
||||
## docker.name_template
|
||||
|
||||
> since 2018-01-19
|
||||
|
||||
This property was deprecated in favor of the pluralized `name_templates`.
|
||||
The idea is to be able to define several tags instead of just one.
|
||||
|
||||
Change this:
|
||||
|
||||
```yaml
|
||||
dockers:
|
||||
- image: foo/bar
|
||||
name_template: '{{ .Tag }}'
|
||||
```
|
||||
|
||||
to this:
|
||||
|
||||
```yaml
|
||||
dockers:
|
||||
- image: foo/bar
|
||||
tag_templates:
|
||||
- '{{ .Tag }}'
|
||||
```
|
||||
|
||||
## docker.latest
|
||||
|
||||
> since 2018-01-19
|
||||
|
||||
The `latest` field in Docker config is deprecated in favor of the newer
|
||||
`tag_templates` field.
|
||||
|
||||
Change this:
|
||||
|
||||
```yaml
|
||||
dockers:
|
||||
- image: foo/bar
|
||||
latest: true
|
||||
```
|
||||
|
||||
to this:
|
||||
|
||||
```yaml
|
||||
dockers:
|
||||
- image: foo/bar
|
||||
tag_templates:
|
||||
- '{{ .Tag }}'
|
||||
- latest
|
||||
```
|
||||
|
27
internal/deprecate/deprecate.go
Normal file
27
internal/deprecate/deprecate.go
Normal file
@ -0,0 +1,27 @@
|
||||
// Package deprecate provides simple functions to standardize the output
|
||||
// of deprecation notices on goreleaser
|
||||
package deprecate
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/apex/log/handlers/cli"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
const baseURL = "https://goreleaser.com/#deprecation_notices."
|
||||
|
||||
// Notice warns the user about the deprecation of the given property
|
||||
func Notice(property string) {
|
||||
cli.Default.Padding += 3
|
||||
defer func() {
|
||||
cli.Default.Padding -= 3
|
||||
}()
|
||||
url := baseURL + strings.Replace(property, ".", "_", -1)
|
||||
log.Warn(color.New(color.Bold, color.FgHiYellow).Sprintf(
|
||||
"DEPRECATED: `%s` should not be used anymore, check %s for more info.",
|
||||
property,
|
||||
url,
|
||||
))
|
||||
}
|
24
internal/deprecate/deprecate_test.go
Normal file
24
internal/deprecate/deprecate_test.go
Normal file
@ -0,0 +1,24 @@
|
||||
package deprecate
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/apex/log/handlers/cli"
|
||||
)
|
||||
|
||||
func TestNotice(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
cli.Default.Writer = &out
|
||||
log.SetHandler(cli.Default)
|
||||
log.Info("first")
|
||||
Notice("foo.bar.whatever")
|
||||
log.Info("last")
|
||||
|
||||
assert.Contains(t, out.String(), " • first")
|
||||
assert.Contains(t, out.String(), " • DEPRECATED: `foo.bar.whatever` should not be used anymore, check https://goreleaser.com/#deprecation_notices.foo_bar_whatever for more info.")
|
||||
assert.Contains(t, out.String(), " • last")
|
||||
}
|
@ -3,10 +3,13 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/pkg/errors"
|
||||
@ -18,9 +21,6 @@ import (
|
||||
|
||||
// langs to init
|
||||
_ "github.com/goreleaser/goreleaser/internal/builders/golang"
|
||||
"time"
|
||||
"bytes"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
// Pipe for build
|
||||
|
@ -11,8 +11,6 @@ import (
|
||||
"text/template"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/apex/log/handlers/cli"
|
||||
"github.com/fatih/color"
|
||||
"github.com/masterminds/semver"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@ -20,6 +18,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/deprecate"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
)
|
||||
|
||||
@ -33,20 +32,12 @@ func (Pipe) String() string {
|
||||
return "creating Docker images"
|
||||
}
|
||||
|
||||
func deprecateWarn(format string, a ...interface{}) {
|
||||
cli.Default.Padding *= 2
|
||||
defer func() {
|
||||
cli.Default.Padding /= 2
|
||||
}()
|
||||
log.Warn(color.New(color.Bold, color.FgHiYellow).Sprintf(format, a...))
|
||||
}
|
||||
|
||||
// Default sets the pipe defaults
|
||||
func (Pipe) Default(ctx *context.Context) error {
|
||||
for i := range ctx.Config.Dockers {
|
||||
var docker = &ctx.Config.Dockers[i]
|
||||
if docker.OldTagTemplate != "" {
|
||||
deprecateWarn("`dockers[%d].tag_template` is deprecated. Please consider using `dockers[%d].tag_templates` instead", i, i)
|
||||
deprecate.Notice("docker.tag_template")
|
||||
docker.TagTemplates = append(docker.TagTemplates, docker.OldTagTemplate)
|
||||
}
|
||||
if len(docker.TagTemplates) == 0 {
|
||||
@ -59,7 +50,7 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
docker.Goarch = "amd64"
|
||||
}
|
||||
if docker.Latest {
|
||||
deprecateWarn("`dockers[%d].latest` is deprecated. Please consider adding a `latest` tag to the `dockers[%d].tag_templates` list instead", i, i)
|
||||
deprecate.Notice("docker.latest")
|
||||
docker.TagTemplates = append(docker.TagTemplates, "latest")
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/deprecate"
|
||||
"github.com/goreleaser/goreleaser/internal/filenametemplate"
|
||||
"github.com/goreleaser/goreleaser/internal/linux"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
@ -45,6 +46,9 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
if fpm.NameTemplate == "" {
|
||||
fpm.NameTemplate = defaultNameTemplate
|
||||
}
|
||||
if len(fpm.Formats) > 0 {
|
||||
deprecate.Notice("fpm")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user