1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-11-06 09:09:29 +02:00

feat: Add support for custom publishers (#1481)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Radek Simko
2020-05-10 17:03:49 +01:00
committed by GitHub
parent 31fedc4e67
commit 8749030d3b
14 changed files with 710 additions and 3 deletions

View File

@@ -38,12 +38,13 @@ const (
timestamp = "Timestamp"
// artifact-only keys
os = "Os"
osKey = "Os"
arch = "Arch"
arm = "Arm"
mips = "Mips"
binary = "Binary"
artifactName = "ArtifactName"
artifactPath = "ArtifactPath"
// gitlab only
artifactUploadHash = "ArtifactUploadHash"
@@ -109,12 +110,13 @@ func (t *Template) WithArtifact(a *artifact.Artifact, replacements map[string]st
if bin == nil {
bin = t.fields[projectName]
}
t.fields[os] = replace(replacements, a.Goos)
t.fields[osKey] = replace(replacements, a.Goos)
t.fields[arch] = replace(replacements, a.Goarch)
t.fields[arm] = replace(replacements, a.Goarm)
t.fields[mips] = replace(replacements, a.Gomips)
t.fields[binary] = bin.(string)
t.fields[artifactName] = a.Name
t.fields[artifactPath] = a.Path
if val, ok := a.Extra["ArtifactUploadHash"]; ok {
t.fields[artifactUploadHash] = val
} else {
@@ -150,6 +152,7 @@ func (t *Template) Apply(s string) (string, error) {
"toupper": strings.ToUpper,
"trim": strings.TrimSpace,
"dir": filepath.Dir,
"abs": filepath.Abs,
}).
Parse(s)
if err != nil {

View File

@@ -1,12 +1,15 @@
package tmpl
import (
"os"
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWithArtifact(t *testing.T) {
@@ -152,6 +155,9 @@ func TestFuncMap(t *testing.T) {
var ctx = context.New(config.Project{
ProjectName: "proj",
})
wd, err := os.Getwd()
require.NoError(t, err)
ctx.Git.CurrentTag = "v1.2.4"
for _, tc := range []struct {
Template string
@@ -190,6 +196,11 @@ func TestFuncMap(t *testing.T) {
Name: "trim",
Expected: "test",
},
{
Template: `{{ abs "file" }}`,
Name: "abs",
Expected: filepath.Join(wd, "file"),
},
} {
out, err := New(ctx).Apply(tc.Template)
assert.NoError(t, err)