Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: ArtifactExt as a template field
  • Loading branch information
caarlos0 committed Aug 1, 2022
1 parent a05b776 commit a31b4aa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/tmpl/tmpl.go
Expand Up @@ -63,6 +63,7 @@ const (
mips = "Mips"
binary = "Binary"
artifactName = "ArtifactName"
artifactExt = "ArtifactExt"
artifactPath = "ArtifactPath"

// build keys.
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions internal/tmpl/tmpl_test.go
Expand Up @@ -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.*\" }}",
Expand All @@ -80,13 +83,15 @@ 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",
Gomips: "softfloat",
Goamd64: "v3",
Extra: map[string]interface{}{
artifact.ExtraBinary: "binary",
artifact.ExtraExt: ".exe",
},
},
map[string]string{"linux": "Linux"},
Expand Down
1 change: 1 addition & 0 deletions www/docs/customization/templates.md
Expand Up @@ -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`.

Expand Down

0 comments on commit a31b4aa

Please sign in to comment.