diff --git a/cmd/build.go b/cmd/build.go index 786aa6258..a42f6108e 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -173,6 +173,7 @@ func setupBuildContext(ctx *context.Context, options buildOpts) error { ctx.Clean = options.clean if options.singleTarget { + ctx.SingleTarget = true ctx.Partial = true } diff --git a/internal/tmpl/tmpl.go b/internal/tmpl/tmpl.go index 24f9fe4c0..fdf1c6691 100644 --- a/internal/tmpl/tmpl.go +++ b/internal/tmpl/tmpl.go @@ -53,6 +53,7 @@ const ( patch = "Patch" prerelease = "Prerelease" isSnapshot = "IsSnapshot" + isSingleTarget = "IsSingleTarget" isNightly = "IsNightly" isDraft = "IsDraft" env = "Env" @@ -118,6 +119,7 @@ func New(ctx *context.Context) *Template { patch: ctx.Semver.Patch, prerelease: ctx.Semver.Prerelease, isSnapshot: ctx.Snapshot, + isSingleTarget: ctx.SingleTarget, isNightly: false, isDraft: ctx.Config.Release.Draft, releaseNotes: ctx.ReleaseNotes, diff --git a/internal/tmpl/tmpl_test.go b/internal/tmpl/tmpl_test.go index d679d5047..9e8395fe2 100644 --- a/internal/tmpl/tmpl_test.go +++ b/internal/tmpl/tmpl_test.go @@ -48,6 +48,7 @@ func TestWithArtifact(t *testing.T) { ctx.ModulePath = "github.com/goreleaser/goreleaser/v2" ctx.ReleaseNotes = "test release notes" ctx.Date = time.Unix(1678327562, 0) + ctx.SingleTarget = true }, ) for expect, tmpl := range map[string]string{ @@ -89,6 +90,7 @@ func TestWithArtifact(t *testing.T) { "2023-03-09T02:06:02Z": `{{ .Date }}`, "1678327562": `{{ .Timestamp }}`, "snapshot true": `snapshot {{.IsSnapshot}}`, + "singletarget true": `singletarget {{.IsSingleTarget}}`, "nightly false": `nightly {{.IsNightly}}`, "draft true": `draft {{.IsDraft}}`, "dirty true": `dirty {{.IsGitDirty}}`, diff --git a/pkg/context/context.go b/pkg/context/context.go index 18141ca39..84fda8c39 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -102,6 +102,7 @@ type Context struct { Snapshot bool FailFast bool Partial bool + SingleTarget bool SkipTokenCheck bool Clean bool PreRelease bool diff --git a/www/docs/cmd/goreleaser_build.md b/www/docs/cmd/goreleaser_build.md index 53ebfbe9b..dace195da 100644 --- a/www/docs/cmd/goreleaser_build.md +++ b/www/docs/cmd/goreleaser_build.md @@ -10,7 +10,7 @@ Its intended usage is, for example, within Makefiles to avoid setting up ldflags It also allows you to generate a local build for your current machine only using the `--single-target` option, and specific build IDs using the `--id` option in case you have more than one. -When using `--single-target`, the `GOOS` and `GOARCH` environment variables are used to determine the target, defaulting to the current machine target if not set. +When using `--single-target`, the `GOOS`, `GOARCH`, `GOARM`, `GOAMD64`, and `GOMIPS` environment variables are used to determine the target, defaulting to the current machine target if not set. ``` diff --git a/www/docs/customization/templates.md b/www/docs/customization/templates.md index d79b082bc..119f4837f 100644 --- a/www/docs/customization/templates.md +++ b/www/docs/customization/templates.md @@ -37,6 +37,7 @@ In fields that support templates, these fields are always available: | `.IsDraft` | `true` if `release.draft` is set in the configuration, `false` otherwise | | `.IsSnapshot` | `true` if `--snapshot` is set, `false` otherwise | | `.IsNightly` | `true` if `--nightly` is set, `false` otherwise | +| `.IsSingleTarget` | `true` if `--single-target` is set, `false` otherwise | | `.Env` | a map with system's environment variables | | `.Date` | current UTC date in RFC 3339 format | | `.Now` | current UTC date as `time.Time` struct, allows all `time.Time` functions (e.g. `{{ .Now.Format "2006" }}`) |