mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
feat: improve output (#4206)
- improves deprecation warning styles a bit so they caught the readers eye faster and are easier to read - warns if the user uses `builds.target` in conjunction with other options which are ignored in that case - improved env output - improved no configuration found warning some of the changes: <img width="1263" alt="CleanShot 2023-07-24 at 21 38 41@2x" src="https://github.com/goreleaser/goreleaser/assets/245435/40465853-7177-44d6-b07b-61b67590669a"> --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
3dd77f6f3d
commit
4266634752
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/caarlos0/log"
|
||||
"github.com/goreleaser/goreleaser/internal/logext"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
)
|
||||
|
||||
@ -38,6 +39,6 @@ func loadConfigCheck(path string) (config.Project, string, error) {
|
||||
}
|
||||
// the user didn't specify a config file and the known possible file names
|
||||
// don't exist, so, return an empty config and a nil err.
|
||||
log.Warn("could not find a configuration file, using defaults...")
|
||||
log.Warn(logext.Warning("could not find a configuration file, using defaults..."))
|
||||
return config.Project{}, "", nil
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/builders/buildtarget"
|
||||
"github.com/goreleaser/goreleaser/internal/gio"
|
||||
"github.com/goreleaser/goreleaser/internal/logext"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
api "github.com/goreleaser/goreleaser/pkg/build"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
@ -50,6 +51,8 @@ func (*Builder) WithDefaults(build config.Build) (config.Build, error) {
|
||||
if len(build.Ldflags) == 0 {
|
||||
build.Ldflags = []string{"-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser"}
|
||||
}
|
||||
|
||||
_ = warnIfTargetsAndOtherOptionTogether(build)
|
||||
if len(build.Targets) == 0 {
|
||||
if len(build.Goos) == 0 {
|
||||
build.Goos = []string{"linux", "darwin", "windows"}
|
||||
@ -103,6 +106,29 @@ func (*Builder) WithDefaults(build config.Build) (config.Build, error) {
|
||||
return build, nil
|
||||
}
|
||||
|
||||
func warnIfTargetsAndOtherOptionTogether(build config.Build) bool {
|
||||
if len(build.Targets) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
res := false
|
||||
for k, v := range map[string]int{
|
||||
"goos": len(build.Goos),
|
||||
"goarch": len(build.Goarch),
|
||||
"goarm": len(build.Goarm),
|
||||
"gomips": len(build.Gomips),
|
||||
"goamd64": len(build.Goamd64),
|
||||
"ignore": len(build.Ignore),
|
||||
} {
|
||||
if v == 0 {
|
||||
continue
|
||||
}
|
||||
log.Warnf(logext.Keyword("builds."+k) + " is ignored when " + logext.Keyword("builds.targets") + " is set")
|
||||
res = true
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func keys(m map[string]bool) []string {
|
||||
result := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
|
@ -1373,6 +1373,34 @@ func TestOverrides(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestWarnIfTargetsAndOtherOptionsTogether(t *testing.T) {
|
||||
nonEmpty := []string{"foo", "bar"}
|
||||
for name, fn := range map[string]func(*config.Build){
|
||||
"goos": func(b *config.Build) { b.Goos = nonEmpty },
|
||||
"goarch": func(b *config.Build) { b.Goarch = nonEmpty },
|
||||
"goarm": func(b *config.Build) { b.Goarm = nonEmpty },
|
||||
"gomips": func(b *config.Build) { b.Gomips = nonEmpty },
|
||||
"goamd64": func(b *config.Build) { b.Goamd64 = nonEmpty },
|
||||
"ignores": func(b *config.Build) { b.Ignore = []config.IgnoredBuild{{Goos: "linux"}} },
|
||||
"multiple": func(b *config.Build) {
|
||||
b.Goos = nonEmpty
|
||||
b.Goarch = nonEmpty
|
||||
b.Goarm = nonEmpty
|
||||
b.Gomips = nonEmpty
|
||||
b.Goamd64 = nonEmpty
|
||||
b.Ignore = []config.IgnoredBuild{{Goos: "linux"}}
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
b := config.Build{
|
||||
Targets: nonEmpty,
|
||||
}
|
||||
fn(&b)
|
||||
require.True(t, warnIfTargetsAndOtherOptionTogether(b))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Helpers
|
||||
//
|
||||
|
@ -8,24 +8,19 @@ import (
|
||||
"text/template"
|
||||
|
||||
"github.com/caarlos0/log"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/goreleaser/goreleaser/internal/logext"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
)
|
||||
|
||||
const baseURL = "https://goreleaser.com/deprecations#"
|
||||
|
||||
var warnStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("11")).Bold(true)
|
||||
|
||||
// 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")
|
||||
NoticeCustom(ctx, property, "{{ .Property }} should not be used anymore, check {{ .URL }} for more info")
|
||||
}
|
||||
|
||||
// NoticeCustom warns the user about the deprecation of the given property.
|
||||
func NoticeCustom(ctx *context.Context, property, tmpl string) {
|
||||
log.IncreasePadding()
|
||||
defer log.DecreasePadding()
|
||||
|
||||
// replaces . and _ with -
|
||||
url := baseURL + strings.NewReplacer(
|
||||
".", "",
|
||||
@ -37,14 +32,14 @@ func NoticeCustom(ctx *context.Context, property, tmpl string) {
|
||||
if err := template.
|
||||
Must(template.New("deprecation").Parse("DEPRECATED: "+tmpl)).
|
||||
Execute(&out, templateData{
|
||||
URL: url,
|
||||
Property: property,
|
||||
URL: logext.URL(url),
|
||||
Property: logext.Keyword(property),
|
||||
}); err != nil {
|
||||
panic(err) // this should never happen
|
||||
}
|
||||
|
||||
ctx.Deprecated = true
|
||||
log.Warn(warnStyle.Render(out.String()))
|
||||
log.Warn(logext.Warning(out.String()))
|
||||
}
|
||||
|
||||
type templateData struct {
|
||||
|
@ -1,3 +1,3 @@
|
||||
• first
|
||||
• DEPRECATED: `foo.bar.whatever: foobar` should not be used anymore, check https://goreleaser.com/deprecations#foobarwhatever-foobar for more info
|
||||
• DEPRECATED: foo.bar.whatever: foobar should not be used anymore, check https://goreleaser.com/deprecations#foobarwhatever-foobar for more info
|
||||
• last
|
||||
|
@ -1,3 +1,3 @@
|
||||
• first
|
||||
• DEPRECATED: some custom template with a url https://goreleaser.com/deprecations#something-else
|
||||
• DEPRECATED: some custom template with a url https://goreleaser.com/deprecations#something-else
|
||||
• last
|
||||
|
18
internal/logext/styles.go
Normal file
18
internal/logext/styles.go
Normal file
@ -0,0 +1,18 @@
|
||||
package logext
|
||||
|
||||
import "github.com/charmbracelet/lipgloss"
|
||||
|
||||
// Keyword should be used to highlight code.
|
||||
var Keyword = lipgloss.NewStyle().
|
||||
Padding(0, 1).
|
||||
Foreground(lipgloss.AdaptiveColor{Light: "#FF4672", Dark: "#ED567A"}).
|
||||
Background(lipgloss.AdaptiveColor{Light: "#DDDADA", Dark: "#242424"}).
|
||||
Render
|
||||
|
||||
var (
|
||||
// URL is used to style URLs.
|
||||
URL = lipgloss.NewStyle().Foreground(lipgloss.Color("3")).Render
|
||||
|
||||
// Warning is used to style warnings for the user.
|
||||
Warning = lipgloss.NewStyle().Foreground(lipgloss.Color("11")).Bold(true).Render
|
||||
)
|
5
internal/pipe/env/env.go
vendored
5
internal/pipe/env/env.go
vendored
@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/caarlos0/log"
|
||||
"github.com/goreleaser/goreleaser/internal/logext"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
@ -159,7 +160,7 @@ func checkErrors(ctx *context.Context, noTokens, noTokenErrs bool, gitlabTokenEr
|
||||
func loadEnv(env, path string) (string, error) {
|
||||
val := os.Getenv(env)
|
||||
if val != "" {
|
||||
log.Infof("using token from %q", "$"+env)
|
||||
log.Infof("using token from %q", logext.Keyword("$"+env))
|
||||
return val, nil
|
||||
}
|
||||
path, err := homedir.Expand(path)
|
||||
@ -174,7 +175,7 @@ func loadEnv(env, path string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
log.Infof("using token from %q", path)
|
||||
log.Infof("using token from %q", logext.Keyword(path))
|
||||
bts, _, err := bufio.NewReader(f).ReadLine()
|
||||
return string(bts), err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user