Repository: goreleaser/goreleaser (Go)

Issue:
Make build.skip template-able
### Is your feature request related to a problem? Please describe.

I have a goreleaser setup that build for regular crypto and another build for fips crypto.
We are doing multi-arch multi os build.
I would like to skip the build of fips crypto unless it's a tagged version (ie: a release)

### Describe the solution you'd like

I would like to be able to use `build.skip` with conditionals like for instance `skip: {{ empty .Tag }}` 

Like it [has been done](https://github.com/goreleaser/goreleaser/issues/3828) for `changelog.skip`, for instance.

### Describe alternatives you've considered

FTM, I need to build using other mean (like GH action) in order to avoid dual build

### Search

- [X] I did search for other open and closed issues before opening this

### Supporter

- [ ] I am a [sponsor](https://github.com/sponsors/caarlos0/) or a [Pro](https://goreleaser.com/pro) customer

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

### Additional context

_No response_


Discussion:

Patch:
diff --git a/internal/pipe/build/build.go b/internal/pipe/build/build.go
index da262083205..04635f37432 100644
--- a/internal/pipe/build/build.go
+++ b/internal/pipe/build/build.go
@@ -34,7 +34,11 @@ func (Pipe) String() string {
 func (Pipe) Run(ctx *context.Context) error {
 	g := semerrgroup.New(ctx.Parallelism)
 	for _, build := range ctx.Config.Builds {
-		if build.Skip {
+		skip, err := tmpl.New(ctx).Bool(build.Skip)
+		if err != nil {
+			return err
+		}
+		if skip {
 			log.WithField("id", build.ID).Info("skip is set")
 			continue
 		}
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 6af843ddf5d..b4bb776d2cc 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -501,7 +501,7 @@ type Build struct {
 	Hooks           BuildHookConfig `yaml:"hooks,omitempty" json:"hooks,omitempty"`
 	Builder         string          `yaml:"builder,omitempty" json:"builder,omitempty"`
 	ModTimestamp    string          `yaml:"mod_timestamp,omitempty" json:"mod_timestamp,omitempty"`
-	Skip            bool            `yaml:"skip,omitempty" json:"skip,omitempty"`
+	Skip            string          `yaml:"skip,omitempty" json:"skip,omitempty" jsonschema:"oneof_type=string;boolean"`
 	GoBinary        string          `yaml:"gobinary,omitempty" json:"gobinary,omitempty"`
 	Command         string          `yaml:"command,omitempty" json:"command,omitempty"`
 	NoUniqueDistDir bool            `yaml:"no_unique_dist_dir,omitempty" json:"no_unique_dist_dir,omitempty"`
diff --git a/www/docs/customization/builds.md b/www/docs/customization/builds.md
index 6941441ddcb..8d496ddc592 100644
--- a/www/docs/customization/builds.md
+++ b/www/docs/customization/builds.md
@@ -194,6 +194,8 @@ builds:
 
     # If true, skip the build.
     # Useful for library projects.
+    #
+    # Templates: allowed (since v2.3).
     skip: false
 
     # By default, GoReleaser will create your binaries inside


Test patch:
diff --git a/internal/pipe/build/build_test.go b/internal/pipe/build/build_test.go
index df71b6dfbee..208024f3c30 100644
--- a/internal/pipe/build/build_test.go
+++ b/internal/pipe/build/build_test.go
@@ -405,7 +405,23 @@ func TestSkipBuild(t *testing.T) {
 		Dist: folder,
 		Builds: []config.Build{
 			{
-				Skip: true,
+				Skip: "true",
+			},
+		},
+	}
+	ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("2.4.5"))
+	require.NoError(t, Pipe{}.Run(ctx))
+	require.Empty(t, ctx.Artifacts.List())
+}
+
+func TestSkipBuildTmpl(t *testing.T) {
+	folder := testlib.Mktmp(t)
+	config := config.Project{
+		Dist: folder,
+		Env:  []string{"FOO=bar"},
+		Builds: []config.Build{
+			{
+				Skip: "{{ eq .Env.FOO \"bar\" }}",
 			},
 		},
 	}