From a31b4aa0ae72a39258e327898819029001f400a3 Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Mon, 1 Aug 2022 16:04:20 -0300 Subject: [PATCH] feat: ArtifactExt as a template field --- internal/tmpl/tmpl.go | 2 ++ internal/tmpl/tmpl_test.go | 5 +++++ www/docs/customization/templates.md | 1 + 3 files changed, 8 insertions(+) diff --git a/internal/tmpl/tmpl.go b/internal/tmpl/tmpl.go index 6000db4912c..62126e2eb08 100644 --- a/internal/tmpl/tmpl.go +++ b/internal/tmpl/tmpl.go @@ -63,6 +63,7 @@ const ( mips = "Mips" binary = "Binary" artifactName = "ArtifactName" + artifactExt = "ArtifactExt" artifactPath = "ArtifactPath" // build keys. @@ -146,6 +147,7 @@ func (t *Template) WithArtifact(a *artifact.Artifact, replacements map[string]st t.fields[amd64] = replace(replacements, a.Goamd64) t.fields[binary] = artifact.ExtraOr(*a, binary, t.fields[projectName].(string)) t.fields[artifactName] = a.Name + t.fields[artifactExt] = artifact.ExtraOr(*a, artifact.ExtraExt, "") t.fields[artifactPath] = a.Path return t } diff --git a/internal/tmpl/tmpl_test.go b/internal/tmpl/tmpl_test.go index 2384dda0e90..13ba4d796b0 100644 --- a/internal/tmpl/tmpl_test.go +++ b/internal/tmpl/tmpl_test.go @@ -69,6 +69,9 @@ func TestWithArtifact(t *testing.T) { "another line": "{{ .TagBody }}", "runtime: " + runtime.GOOS: "runtime: {{ .Runtime.Goos }}", "runtime: " + runtime.GOARCH: "runtime: {{ .Runtime.Goarch }}", + "artifact name: not-this-binary": "artifact name: {{ .ArtifactName }}", + "artifact ext: .exe": "artifact ext: {{ .ArtifactExt }}", + "artifact path: /tmp/foo.exe": "artifact path: {{ .ArtifactPath }}", "remove this": "{{ filter .Env.MULTILINE \".*remove.*\" }}", "something with\nmultiple lines\nto test things": "{{ reverseFilter .Env.MULTILINE \".*remove.*\" }}", @@ -80,6 +83,7 @@ func TestWithArtifact(t *testing.T) { result, err := New(ctx).WithArtifact( &artifact.Artifact{ Name: "not-this-binary", + Path: "/tmp/foo.exe", Goarch: "amd64", Goos: "linux", Goarm: "6", @@ -87,6 +91,7 @@ func TestWithArtifact(t *testing.T) { Goamd64: "v3", Extra: map[string]interface{}{ artifact.ExtraBinary: "binary", + artifact.ExtraExt: ".exe", }, }, map[string]string{"linux": "Linux"}, diff --git a/www/docs/customization/templates.md b/www/docs/customization/templates.md index cc775457352..80b95e91255 100644 --- a/www/docs/customization/templates.md +++ b/www/docs/customization/templates.md @@ -72,6 +72,7 @@ may have some extra fields: | `.Binary` | binary name | | `.ArtifactName` | archive name | | `.ArtifactPath` | absolute path to artifact | +| `.ArtifactExt` | binary extension (e.g. `.exe`) | [^8]: Might have been replaced by `archives.replacements`.