Repository: goreleaser/goreleaser
Pull request #4206 (2023-07-25 00:38:13)

feat: improve output
- 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">


cloudflare-pages[bot]: ## Deploying with &nbsp;<a href="https://pages.dev"><img alt="Cloudflare Pages" src="https://user-images.githubusercontent.com/23264/106598434-9e719e00-654f-11eb-9e59-6167043cfa01.png" width="16"></a> &nbsp;Cloudflare Pages

<table><tr><td><strong>Latest commit:</strong> </td><td>
<code>1d45250</code>
</td></tr>
<tr><td><strong>Status:</strong></td><td>&nbsp;✅&nbsp; Deploy successful!</td></tr>
<tr><td><strong>Preview URL:</strong></td><td>
<a href='https://f7a9c96b.goreleaser.pages.dev'>https://f7a9c96b.goreleaser.pages.dev</a>
</td></tr>
<tr><td><strong>Branch Preview URL:</strong></td><td>
<a href='https://warn-builds.goreleaser.pages.dev'>https://warn-builds.goreleaser.pages.dev</a>
</td></tr>
</table>

[View logs](https://dash.cloudflare.com/?to=/:account/pages/view/goreleaser/f7a9c96b-814f-49f0-81ab-d07d82fa1a67)


Patch:
diff --git a/cmd/config.go b/cmd/config.go
index 003541c7..4adff636 100644
--- a/cmd/config.go
+++ b/cmd/config.go
@@ -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
 }
diff --git a/internal/builders/golang/build.go b/internal/builders/golang/build.go
index 4cb247f3..adc3fac4 100644
--- a/internal/builders/golang/build.go
+++ b/internal/builders/golang/build.go
@@ -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 {
diff --git a/internal/deprecate/deprecate.go b/internal/deprecate/deprecate.go
index 70992118..5f6dcfea 100644
--- a/internal/deprecate/deprecate.go
+++ b/internal/deprecate/deprecate.go
@@ -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 {
diff --git a/internal/logext/styles.go b/internal/logext/styles.go
new file mode 100644
index 00000000..5516a9fc
--- /dev/null
+++ b/internal/logext/styles.go
@@ -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
+)
diff --git a/internal/pipe/env/env.go b/internal/pipe/env/env.go
index 19dc5820..fae25d25 100644
--- a/internal/pipe/env/env.go
+++ b/internal/pipe/env/env.go
@@ -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
 }
diff --git a/www/docs/customization/builds.md b/www/docs/customization/builds.md
index 9664a6f0..472f70a9 100644
--- a/www/docs/customization/builds.md
+++ b/www/docs/customization/builds.md
@@ -597,14 +597,14 @@ Builds environment variables accept templates.
 You can leverage that to have a single build configuration with different
 environment variables for each platform, for example.
 
-A common example of this is the variables `CC` and `CCX`.
+A common example of this is the variables `CC` and `CXX`.
 
 Here are two different examples:
 
 ### Using multiple envs
 
-This example creates once `CC_` and `CCX_` variable for each platform, and then
-set `CC` and `CCX` to the right one:
+This example creates once `CC_` and `CXX_` variable for each platform, and then
+set `CC` and `CXX` to the right one:
 
 ```yaml
 # .goreleaser.yml
@@ -622,18 +622,18 @@ builds:
     env:
       - CGO_ENABLED=0
       - CC_darwin_amd64=o64-clang
-      - CCX_darwin_amd64=o64-clang+
+      - CXX_darwin_amd64=o64-clang+
       - CC_darwin_arm64=aarch64-apple-darwin20.2-clang
-      - CCX_darwin_arm64=aarch64-apple-darwin20.2-clang++
+      - CXX_darwin_arm64=aarch64-apple-darwin20.2-clang++
       - CC_windows_amd64=x86_64-w64-mingw32-gc
-      - CCX_windows_amd64=x86_64-w64-mingw32-g++
+      - CXX_windows_amd64=x86_64-w64-mingw32-g++
       - 'CC={{ index .Env (print "CC_" .Os "_" .Arch) }}'
-      - 'CCX={{ index .Env (print "CCX_" .Os "_" .Arch) }}'
+      - 'CXX={{ index .Env (print "CXX_" .Os "_" .Arch) }}'
 ```
 
 ### Using `if` statements
 
-This example uses `if` statements to set `CC` and `CCX`:
+This example uses `if` statements to set `CC` and `CXX`:
 
 ```yaml
 # .goreleaser.yml
diff --git a/www/docs/deprecations.md b/www/docs/deprecations.md
index 132d85f6..440e2784 100644
--- a/www/docs/deprecations.md
+++ b/www/docs/deprecations.md
@@ -41,7 +41,7 @@ Description.
 
 > since 2023-06-13 (v1.19.0)
 
-Replace `index` with `repository`.
+Replace `bucket` with `repository`.
 
 === "Before"
 


Test patch:
diff --git a/internal/builders/golang/build_test.go b/internal/builders/golang/build_test.go
index dc77f1b0..c974ff94 100644
--- a/internal/builders/golang/build_test.go
+++ b/internal/builders/golang/build_test.go
@@ -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
 //
diff --git a/internal/deprecate/testdata/TestNotice.txt.golden b/internal/deprecate/testdata/TestNotice.txt.golden
index 18819a9d..b0d40f76 100644
--- a/internal/deprecate/testdata/TestNotice.txt.golden
+++ b/internal/deprecate/testdata/TestNotice.txt.golden
@@ -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
diff --git a/internal/deprecate/testdata/TestNoticeCustom.txt.golden b/internal/deprecate/testdata/TestNoticeCustom.txt.golden
index c07b7c64..a4633586 100644
--- a/internal/deprecate/testdata/TestNoticeCustom.txt.golden
+++ b/internal/deprecate/testdata/TestNoticeCustom.txt.golden
@@ -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