1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-16 03:52:12 +02:00

refactor: put common extra keys in the artifact package (#2580)

* refactor: put common extra keys in the artifact package

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* refactor: common extra fields have their own funcs

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* refactor: 2 more

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: review

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker 2021-10-16 22:46:11 -03:00 committed by GitHub
parent 160d97af40
commit df2f00fc8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 262 additions and 239 deletions

View File

@ -91,6 +91,16 @@ func (t Type) String() string {
}
}
const (
ExtraID = "ID"
ExtraBinary = "Binary"
ExtraExt = "Ext"
ExtraBuilds = "Builds"
ExtraFormat = "Format"
ExtraWrappedIn = "WrappedIn"
ExtraBinaries = "Binaries"
)
// Artifact represents an artifact and its relevant info.
type Artifact struct {
Name string
@ -147,6 +157,16 @@ func (a Artifact) Checksum(algorithm string) (string, error) {
return hex.EncodeToString(h.Sum(nil)), nil
}
// ID returns the artifact ID if it exists, empty otherwise.
func (a Artifact) ID() string {
return a.ExtraOr(ExtraID, "").(string)
}
// Format returns the artifact Format if it exists, empty otherwise.
func (a Artifact) Format() string {
return a.ExtraOr(ExtraFormat, "").(string)
}
// Artifacts is a list of artifacts.
type Artifacts struct {
items []*Artifact
@ -252,7 +272,7 @@ func ByFormats(formats ...string) Filter {
for _, format := range formats {
format := format
filters = append(filters, func(a *Artifact) bool {
return a.ExtraOr("Format", "") == format
return a.Format() == format
})
}
return Or(filters...)
@ -267,7 +287,7 @@ func ByIDs(ids ...string) Filter {
// checksum and source archive are always for all artifacts, so return always true.
return a.Type == Checksum ||
a.Type == UploadableSourceArchive ||
a.ExtraOr("ID", "") == id
a.ID() == id
})
}
return Or(filters...)

View File

@ -271,25 +271,25 @@ func TestByIDs(t *testing.T) {
{
Name: "foo",
Extra: map[string]interface{}{
"ID": "foo",
ExtraID: "foo",
},
},
{
Name: "bar",
Extra: map[string]interface{}{
"ID": "bar",
ExtraID: "bar",
},
},
{
Name: "foobar",
Extra: map[string]interface{}{
"ID": "foo",
ExtraID: "foo",
},
},
{
Name: "check",
Extra: map[string]interface{}{
"ID": "check",
ExtraID: "check",
},
},
{
@ -312,25 +312,25 @@ func TestByFormats(t *testing.T) {
{
Name: "foo",
Extra: map[string]interface{}{
"Format": "zip",
ExtraFormat: "zip",
},
},
{
Name: "bar",
Extra: map[string]interface{}{
"Format": "tar.gz",
ExtraFormat: "tar.gz",
},
},
{
Name: "foobar",
Extra: map[string]interface{}{
"Format": "zip",
ExtraFormat: "zip",
},
},
{
Name: "bin",
Extra: map[string]interface{}{
"Format": "binary",
ExtraFormat: "binary",
},
},
}

View File

@ -84,9 +84,9 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti
Goarm: options.Goarm,
Gomips: options.Gomips,
Extra: map[string]interface{}{
"Binary": strings.TrimSuffix(filepath.Base(options.Path), options.Ext),
"Ext": options.Ext,
"ID": build.ID,
artifact.ExtraBinary: strings.TrimSuffix(filepath.Base(options.Path), options.Ext),
artifact.ExtraExt: options.Ext,
artifact.ExtraID: build.ID,
},
}

View File

@ -285,9 +285,9 @@ func TestBuild(t *testing.T) {
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo-v5.6.7",
"ID": "foo",
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
},
},
{
@ -298,9 +298,9 @@ func TestBuild(t *testing.T) {
Gomips: "softfloat",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo-v5.6.7",
"ID": "foo",
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
},
},
{
@ -311,9 +311,9 @@ func TestBuild(t *testing.T) {
Gomips: "softfloat",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo-v5.6.7",
"ID": "foo",
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
},
},
{
@ -323,9 +323,9 @@ func TestBuild(t *testing.T) {
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo-v5.6.7",
"ID": "foo",
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
},
},
{
@ -336,9 +336,9 @@ func TestBuild(t *testing.T) {
Goarm: "6",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo-v5.6.7",
"ID": "foo",
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
},
},
{
@ -348,9 +348,9 @@ func TestBuild(t *testing.T) {
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": ".exe",
"Binary": "foo-v5.6.7",
"ID": "foo",
artifact.ExtraExt: ".exe",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
},
},
{
@ -360,9 +360,9 @@ func TestBuild(t *testing.T) {
Goarch: "wasm",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": ".wasm",
"Binary": "foo-v5.6.7",
"ID": "foo",
artifact.ExtraExt: ".wasm",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
},
},
})
@ -766,7 +766,7 @@ func TestProcessFlags(t *testing.T) {
Goarch: "amd64",
Goarm: "7",
Extra: map[string]interface{}{
"Binary": "binary",
artifact.ExtraBinary: "binary",
},
}

View File

@ -51,7 +51,7 @@ func TestExecute(t *testing.T) {
Path: file,
Type: a.typ,
Extra: map[string]interface{}{
"ID": a.id,
artifact.ExtraID: a.id,
},
})
}
@ -63,7 +63,7 @@ func TestExecute(t *testing.T) {
Path: "foo/bar:amd64",
Type: artifact.DockerImage,
Extra: map[string]interface{}{
"ID": "img",
artifact.ExtraID: "img",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -71,7 +71,7 @@ func TestExecute(t *testing.T) {
Path: "foo/bar",
Type: artifact.DockerManifest,
Extra: map[string]interface{}{
"ID": "mnf",
artifact.ExtraID: "mnf",
},
})

View File

@ -259,7 +259,7 @@ func TestUpload(t *testing.T) {
Path: file,
Type: a.typ,
Extra: map[string]interface{}{
"ID": "foo",
artifact.ExtraID: "foo",
},
})
}

View File

@ -193,11 +193,11 @@ func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Arti
Goarm: binaries[0].Goarm,
Gomips: binaries[0].Gomips,
Extra: map[string]interface{}{
"Builds": binaries,
"ID": arch.ID,
"Format": arch.Format,
"WrappedIn": wrap,
"Binaries": bins,
artifact.ExtraBuilds: binaries,
artifact.ExtraID: arch.ID,
artifact.ExtraFormat: arch.Format,
artifact.ExtraWrappedIn: wrap,
artifact.ExtraBinaries: bins,
},
})
return nil
@ -222,7 +222,7 @@ func skip(ctx *context.Context, archive config.Archive, binaries []*artifact.Art
if err != nil {
return err
}
finalName := name + binary.ExtraOr("Ext", "").(string)
finalName := name + binary.ExtraOr(artifact.ExtraExt, "").(string)
log.
WithField("binary", binary.Name).
WithField("name", finalName).
@ -236,10 +236,10 @@ func skip(ctx *context.Context, archive config.Archive, binaries []*artifact.Art
Goarm: binary.Goarm,
Gomips: binary.Gomips,
Extra: map[string]interface{}{
"Builds": []*artifact.Artifact{binary},
"ID": archive.ID,
"Format": archive.Format,
"Binaries": []string{binary.Name},
artifact.ExtraBuilds: []*artifact.Artifact{binary},
artifact.ExtraID: archive.ID,
artifact.ExtraFormat: archive.Format,
artifact.ExtraBinaries: []string{binary.Name},
},
})
}

View File

@ -83,8 +83,8 @@ func TestRunPipe(t *testing.T) {
Path: filepath.Join(dist, "darwinall", "bin", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "bin/mybin",
"ID": "default",
artifact.ExtraBinary: "bin/mybin",
artifact.ExtraID: "default",
},
}
darwinBuild := &artifact.Artifact{
@ -94,8 +94,8 @@ func TestRunPipe(t *testing.T) {
Path: filepath.Join(dist, "darwinamd64", "bin", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "bin/mybin",
"ID": "default",
artifact.ExtraBinary: "bin/mybin",
artifact.ExtraID: "default",
},
}
linux386Build := &artifact.Artifact{
@ -105,8 +105,8 @@ func TestRunPipe(t *testing.T) {
Path: filepath.Join(dist, "linux386", "bin", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "bin/mybin",
"ID": "default",
artifact.ExtraBinary: "bin/mybin",
artifact.ExtraID: "default",
},
}
linuxArmBuild := &artifact.Artifact{
@ -117,8 +117,8 @@ func TestRunPipe(t *testing.T) {
Path: filepath.Join(dist, "linuxarm7", "bin", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "bin/mybin",
"ID": "default",
artifact.ExtraBinary: "bin/mybin",
artifact.ExtraID: "default",
},
}
linuxMipsBuild := &artifact.Artifact{
@ -129,8 +129,8 @@ func TestRunPipe(t *testing.T) {
Path: filepath.Join(dist, "linuxmipssoftfloat", "bin", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraID: "default",
},
}
windowsBuild := &artifact.Artifact{
@ -140,9 +140,9 @@ func TestRunPipe(t *testing.T) {
Path: filepath.Join(dist, "windowsamd64", "bin", "mybin.exe"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"Extension": ".exe",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraExt: ".exe",
artifact.ExtraID: "default",
},
}
ctx.Artifacts.Add(darwinBuild)
@ -157,8 +157,8 @@ func TestRunPipe(t *testing.T) {
require.NoError(t, Pipe{}.Run(ctx))
archives := ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List()
for _, arch := range archives {
require.Equal(t, "myid", arch.Extra["ID"].(string), "all archives must have the archive ID set")
require.NotEmpty(t, arch.ExtraOr("Binaries", []string{}).([]string), "all archives must have the binary names they contain set")
require.Equal(t, "myid", arch.ID(), "all archives must have the archive ID set")
require.NotEmpty(t, arch.ExtraOr(artifact.ExtraBinaries, []string{}).([]string), "all archives must have the binary names they contain set")
}
require.Len(t, archives, 6)
// TODO: should verify the artifact fields here too
@ -225,8 +225,8 @@ func TestRunPipeDifferentBinaryCount(t *testing.T) {
Path: filepath.Join(dist, "darwinamd64", "bin", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "bin/mybin",
"ID": "default",
artifact.ExtraBinary: "bin/mybin",
artifact.ExtraID: "default",
},
}
darwinBuild2 := &artifact.Artifact{
@ -236,8 +236,8 @@ func TestRunPipeDifferentBinaryCount(t *testing.T) {
Path: filepath.Join(dist, "darwinamd64", "bin", "foobar"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "bin/foobar",
"ID": "foobar",
artifact.ExtraBinary: "bin/foobar",
artifact.ExtraID: "foobar",
},
}
linuxArmBuild := &artifact.Artifact{
@ -247,8 +247,8 @@ func TestRunPipeDifferentBinaryCount(t *testing.T) {
Path: filepath.Join(dist, "linuxamd64", "bin", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "bin/mybin",
"ID": "default",
artifact.ExtraBinary: "bin/mybin",
artifact.ExtraID: "default",
},
}
@ -355,8 +355,8 @@ func TestRunPipeBinary(t *testing.T) {
Path: filepath.Join(dist, "darwinamd64", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraID: "default",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -366,8 +366,8 @@ func TestRunPipeBinary(t *testing.T) {
Path: filepath.Join(dist, "darwinamd64", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "myunibin",
"ID": "default",
artifact.ExtraBinary: "myunibin",
artifact.ExtraID: "default",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -377,9 +377,9 @@ func TestRunPipeBinary(t *testing.T) {
Path: filepath.Join(dist, "windowsamd64", "mybin.exe"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"Ext": ".exe",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraExt: ".exe",
artifact.ExtraID: "default",
},
})
require.NoError(t, Pipe{}.Run(ctx))
@ -420,9 +420,9 @@ func TestRunPipeDistRemoved(t *testing.T) {
Path: filepath.Join("/tmp/path/to/nope", "windowsamd64", "mybin.exe"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"Extension": ".exe",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraExt: ".exe",
artifact.ExtraID: "default",
},
})
// not checking on error msg because it may change depending on OS/version
@ -460,8 +460,8 @@ func TestRunPipeInvalidGlob(t *testing.T) {
Path: filepath.Join("dist", "darwinamd64", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraID: "default",
},
})
require.EqualError(t, Pipe{}.Run(ctx), `failed to find files to archive: globbing failed for pattern [x-]: compile glob pattern: unexpected end of input`)
@ -495,8 +495,8 @@ func TestRunPipeInvalidNameTemplate(t *testing.T) {
Path: filepath.Join("dist", "darwinamd64", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraID: "default",
},
})
require.EqualError(t, Pipe{}.Run(ctx), `template: tmpl:1: unexpected "}" in operand`)
@ -533,8 +533,8 @@ func TestRunPipeInvalidFilesNameTemplate(t *testing.T) {
Path: filepath.Join("dist", "darwinamd64", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraID: "default",
},
})
require.EqualError(t, Pipe{}.Run(ctx), `failed to find files to archive: failed to apply template {{.asdsd}: template: tmpl:1: unexpected "}" in operand`)
@ -569,8 +569,8 @@ func TestRunPipeInvalidWrapInDirectoryTemplate(t *testing.T) {
Path: filepath.Join("dist", "darwinamd64", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraID: "default",
},
})
require.EqualError(t, Pipe{}.Run(ctx), `template: tmpl:1: unexpected "}" in operand`)
@ -614,15 +614,15 @@ func TestRunPipeWrap(t *testing.T) {
Path: filepath.Join("dist", "darwinamd64", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraID: "default",
},
})
require.NoError(t, Pipe{}.Run(ctx))
archives := ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List()
require.Len(t, archives, 1)
require.Equal(t, "foo_macOS", archives[0].ExtraOr("WrappedIn", ""))
require.Equal(t, "foo_macOS", archives[0].ExtraOr(artifact.ExtraWrappedIn, ""))
// Check archive contents
f, err = os.Open(filepath.Join(dist, "foo.tar.gz"))
@ -756,8 +756,8 @@ func TestBinaryOverride(t *testing.T) {
Path: filepath.Join(dist, "darwinamd64", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraID: "default",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -767,9 +767,9 @@ func TestBinaryOverride(t *testing.T) {
Path: filepath.Join(dist, "windowsamd64", "mybin.exe"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"Ext": ".exe",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraExt: ".exe",
artifact.ExtraID: "default",
},
})
ctx.Version = "0.0.1"
@ -779,13 +779,13 @@ func TestBinaryOverride(t *testing.T) {
archives := ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive))
darwin := archives.Filter(artifact.ByGoos("darwin")).List()[0]
require.Equal(t, "foobar_0.0.1_darwin_amd64."+format, darwin.Name)
require.Equal(t, format, darwin.ExtraOr("Format", ""))
require.Empty(t, darwin.ExtraOr("WrappedIn", ""))
require.Equal(t, format, darwin.Format())
require.Empty(t, darwin.ExtraOr(artifact.ExtraWrappedIn, ""))
archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableBinary))
windows := archives.Filter(artifact.ByGoos("windows")).List()[0]
require.Equal(t, "foobar_0.0.1_windows_amd64.exe", windows.Name)
require.Empty(t, windows.ExtraOr("WrappedIn", ""))
require.Empty(t, windows.ExtraOr(artifact.ExtraWrappedIn, ""))
})
}
}
@ -826,8 +826,8 @@ func TestRunPipeSameArchiveFilename(t *testing.T) {
Path: filepath.Join(dist, "darwinamd64", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraID: "default",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -837,9 +837,9 @@ func TestRunPipeSameArchiveFilename(t *testing.T) {
Path: filepath.Join(dist, "windowsamd64", "mybin.exe"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"Extension": ".exe",
"ID": "default",
artifact.ExtraBinary: "mybin",
artifact.ExtraExt: ".exe",
artifact.ExtraID: "default",
},
})
ctx.Version = "0.0.1"
@ -1059,7 +1059,7 @@ func TestArchive_globbing(t *testing.T) {
Path: bin.Name(),
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})

View File

@ -91,7 +91,7 @@ func TestMinioUpload(t *testing.T) {
Name: "source.tar.gz",
Path: srcpath,
Extra: map[string]interface{}{
"Format": "tar.gz",
artifact.ExtraFormat: "tar.gz",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -99,7 +99,7 @@ func TestMinioUpload(t *testing.T) {
Name: "bin.tar.gz",
Path: tgzpath,
Extra: map[string]interface{}{
"ID": "foo",
artifact.ExtraID: "foo",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -107,7 +107,7 @@ func TestMinioUpload(t *testing.T) {
Name: "bin.deb",
Path: debpath,
Extra: map[string]interface{}{
"ID": "bar",
artifact.ExtraID: "bar",
},
})

View File

@ -278,7 +278,7 @@ func installs(cfg config.Homebrew, artifacts []*artifact.Artifact) []string {
install := []string{}
bins := map[string]bool{}
for _, a := range artifacts {
for _, bin := range a.ExtraOr("Binaries", []string{}).([]string) {
for _, bin := range a.ExtraOr(artifact.ExtraBinaries, []string{}).([]string) {
if !bins[bin] {
install = append(install, fmt.Sprintf("bin.install %q", bin))
}

View File

@ -285,8 +285,8 @@ func TestFullPipe(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "bar",
"Format": "tar.gz",
artifact.ExtraID: "bar",
artifact.ExtraFormat: "tar.gz",
},
})
path := filepath.Join(folder, "bin.tar.gz")
@ -297,8 +297,8 @@ func TestFullPipe(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
artifact.ExtraID: "foo",
artifact.ExtraFormat: "tar.gz",
},
})
@ -366,8 +366,8 @@ func TestRunPipeNameTemplate(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
artifact.ExtraID: "foo",
artifact.ExtraFormat: "tar.gz",
},
})
@ -456,8 +456,8 @@ func TestRunPipeMultipleBrewsWithSkip(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
artifact.ExtraID: "foo",
artifact.ExtraFormat: "tar.gz",
},
})
@ -577,8 +577,8 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
Goarm: a.goarm,
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": a.name,
"Format": "tar.gz",
artifact.ExtraID: a.name,
artifact.ExtraFormat: "tar.gz",
},
})
f, err := os.Create(path)
@ -754,8 +754,8 @@ func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
Goarch: ttt.goarch,
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": fmt.Sprintf("foo%d", idx),
"Format": "tar.gz",
artifact.ExtraID: fmt.Sprintf("foo%d", idx),
artifact.ExtraFormat: "tar.gz",
},
})
}
@ -823,8 +823,8 @@ func TestRunPipeNoUpload(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
artifact.ExtraID: "foo",
artifact.ExtraFormat: "tar.gz",
},
})
client := client.NewMock()
@ -880,8 +880,8 @@ func TestRunEmptyTokenType(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
artifact.ExtraID: "foo",
artifact.ExtraFormat: "tar.gz",
},
})
client := client.NewMock()
@ -956,22 +956,22 @@ func TestInstalls(t *testing.T) {
[]*artifact.Artifact{
{
Extra: map[string]interface{}{
"Binaries": []string{"foo", "bar"},
artifact.ExtraBinaries: []string{"foo", "bar"},
},
},
{
Extra: map[string]interface{}{
"Binaries": []string{"foo"},
artifact.ExtraBinaries: []string{"foo"},
},
},
{
Extra: map[string]interface{}{
"Binaries": []string{"bar"},
artifact.ExtraBinaries: []string{"bar"},
},
},
{
Extra: map[string]interface{}{
"Binaries": []string{"bar", "foo"},
artifact.ExtraBinaries: []string{"bar", "foo"},
},
},
},
@ -1013,8 +1013,8 @@ func TestRunPipeUniversalBinary(t *testing.T) {
Goarch: "all",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "unibin",
"Format": "tar.gz",
artifact.ExtraID: "unibin",
artifact.ExtraFormat: "tar.gz",
},
})

View File

@ -67,7 +67,7 @@ func TestPipe(t *testing.T) {
Path: file,
Type: artifact.UploadableBinary,
Extra: map[string]interface{}{
"ID": "id-1",
artifact.ExtraID: "id-1",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -75,7 +75,7 @@ func TestPipe(t *testing.T) {
Path: file,
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "id-2",
artifact.ExtraID: "id-2",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -83,7 +83,7 @@ func TestPipe(t *testing.T) {
Path: file,
Type: artifact.LinuxPackage,
Extra: map[string]interface{}{
"ID": "id-3",
artifact.ExtraID: "id-3",
},
})
require.NoError(t, Pipe{}.Run(ctx))
@ -281,7 +281,7 @@ func TestPipeCheckSumsWithExtraFiles(t *testing.T) {
Path: file,
Type: artifact.UploadableBinary,
Extra: map[string]interface{}{
"ID": "id-1",
artifact.ExtraID: "id-1",
},
})

View File

@ -244,7 +244,7 @@ func dockerPush(ctx *context.Context, image *artifact.Artifact) error {
Extra: map[string]interface{}{},
}
if docker.ID != "" {
art.Extra["ID"] = docker.ID
art.Extra[artifact.ExtraID] = docker.ID
}
ctx.Artifacts.Add(art)
return nil

View File

@ -862,7 +862,7 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "nope",
artifact.ExtraID: "nope",
},
})
},
@ -980,7 +980,7 @@ func TestRunPipe(t *testing.T) {
Goos: os,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": bin,
artifact.ExtraID: bin,
},
})
}
@ -995,7 +995,7 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Type: artifact.LinuxPackage,
Extra: map[string]interface{}{
"ID": "mybin",
artifact.ExtraID: "mybin",
},
})
}

View File

@ -77,7 +77,7 @@ func (ManifestPipe) Publish(ctx *context.Context) error {
Extra: map[string]interface{}{},
}
if manifest.ID != "" {
art.Extra["ID"] = manifest.ID
art.Extra[artifact.ExtraID] = manifest.ID
}
ctx.Artifacts.Add(art)

View File

@ -190,8 +190,8 @@ func dataFor(ctx *context.Context, cfg config.GoFish, cl client.Client, artifact
License: cfg.License,
}
for _, artifact := range artifacts {
sum, err := artifact.Checksum("sha256")
for _, art := range artifacts {
sum, err := art.Checksum("sha256")
if err != nil {
return result, err
}
@ -203,13 +203,13 @@ func dataFor(ctx *context.Context, cfg config.GoFish, cl client.Client, artifact
}
cfg.URLTemplate = url
}
url, err := tmpl.New(ctx).WithArtifact(artifact, map[string]string{}).Apply(cfg.URLTemplate)
url, err := tmpl.New(ctx).WithArtifact(art, map[string]string{}).Apply(cfg.URLTemplate)
if err != nil {
return result, err
}
goarch := []string{artifact.Goarch}
if artifact.Goarch == "all" {
goarch := []string{art.Goarch}
if art.Goarch == "all" {
goarch = []string{"amd64", "arm64"}
}
@ -217,12 +217,12 @@ func dataFor(ctx *context.Context, cfg config.GoFish, cl client.Client, artifact
releasePackage := releasePackage{
DownloadURL: url,
SHA256: sum,
OS: artifact.Goos,
OS: art.Goos,
Arch: arch,
Binaries: artifact.ExtraOr("Binaries", []string{}).([]string),
Binaries: art.ExtraOr(artifact.ExtraBinaries, []string{}).([]string),
}
for _, v := range result.ReleasePackages {
if v.OS == artifact.Goos && v.Arch == artifact.Goarch {
if v.OS == art.Goos && v.Arch == art.Goarch {
return result, ErrMultipleArchivesSameOS
}
}

View File

@ -196,8 +196,8 @@ func TestFullPipe(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "bar",
"Format": "tar.gz",
artifact.ExtraID: "bar",
artifact.ExtraFormat: "tar.gz",
},
})
path := filepath.Join(folder, "bin.tar.gz")
@ -208,9 +208,9 @@ func TestFullPipe(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
"Binaries": []string{"name"},
artifact.ExtraID: "foo",
artifact.ExtraFormat: "tar.gz",
artifact.ExtraBinaries: []string{"name"},
},
})
@ -270,9 +270,9 @@ func TestRunPipeUniversalBinary(t *testing.T) {
Goarch: "all",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "unibin",
"Format": "tar.gz",
"Binaries": []string{"unibin"},
artifact.ExtraID: "unibin",
artifact.ExtraFormat: "tar.gz",
artifact.ExtraBinaries: []string{"unibin"},
},
})
@ -327,9 +327,9 @@ func TestRunPipeNameTemplate(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
"Binaries": []string{"foo"},
artifact.ExtraID: "foo",
artifact.ExtraFormat: "tar.gz",
artifact.ExtraBinaries: []string{"foo"},
},
})
@ -406,9 +406,9 @@ func TestRunPipeMultipleGoFishWithSkip(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
"Binaries": []string{"foo"},
artifact.ExtraID: "foo",
artifact.ExtraFormat: "tar.gz",
artifact.ExtraBinaries: []string{"foo"},
},
})
@ -522,9 +522,9 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
Goarm: a.goarm,
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": a.name,
"Format": "tar.gz",
"Binaries": []string{"foo"},
artifact.ExtraID: a.name,
artifact.ExtraFormat: "tar.gz",
artifact.ExtraBinaries: []string{"foo"},
},
})
f, err := os.Create(path)
@ -700,9 +700,9 @@ func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
Goarch: ttt.goarch,
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": fmt.Sprintf("foo%d", idx),
"Format": "tar.gz",
"Binaries": []string{"foo"},
artifact.ExtraID: fmt.Sprintf("foo%d", idx),
artifact.ExtraFormat: "tar.gz",
artifact.ExtraBinaries: []string{"foo"},
},
})
}
@ -767,9 +767,9 @@ func TestRunPipeNoUpload(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
"Binaries": []string{"foo"},
artifact.ExtraID: "foo",
artifact.ExtraFormat: "tar.gz",
artifact.ExtraBinaries: []string{"foo"},
},
})
client := client.NewMock()
@ -819,8 +819,8 @@ func TestRunEmptyTokenType(t *testing.T) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
artifact.ExtraID: "foo",
artifact.ExtraFormat: "tar.gz",
},
})
client := client.NewMock()

View File

@ -25,7 +25,10 @@ import (
"github.com/goreleaser/goreleaser/pkg/context"
)
const defaultNameTemplate = "{{ .PackageName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
const (
defaultNameTemplate = "{{ .PackageName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
extraFiles = "Files"
)
// Pipe for nfpm packaging.
type Pipe struct{}
@ -313,10 +316,10 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
Goarch: binaries[0].Goarch,
Goarm: binaries[0].Goarm,
Extra: map[string]interface{}{
"Builds": binaries,
"ID": fpm.ID,
"Format": format,
"Files": contents,
artifact.ExtraBuilds: binaries,
artifact.ExtraID: fpm.ID,
artifact.ExtraFormat: format,
extraFiles: contents,
},
})
return nil

View File

@ -64,7 +64,7 @@ func TestRunPipeInvalidFormat(t *testing.T) {
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "foo",
artifact.ExtraID: "foo",
},
})
}
@ -156,7 +156,7 @@ func TestRunPipe(t *testing.T) {
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
}
@ -165,10 +165,10 @@ func TestRunPipe(t *testing.T) {
packages := ctx.Artifacts.Filter(artifact.ByType(artifact.LinuxPackage)).List()
require.Len(t, packages, 6)
for _, pkg := range packages {
format := pkg.ExtraOr("Format", "").(string)
format := pkg.Format()
require.NotEmpty(t, format)
require.Equal(t, pkg.Name, "foo_1.0.0_Tux_"+pkg.Goarch+"-10-20."+format)
require.Equal(t, pkg.ExtraOr("ID", ""), "someid")
require.Equal(t, pkg.ID(), "someid")
require.ElementsMatch(t, []string{
"./testdata/testfile.txt",
"./testdata/testfile.txt",
@ -176,7 +176,7 @@ func TestRunPipe(t *testing.T) {
"/etc/nope.conf",
"./testdata/testfile-" + pkg.Goarch + ".txt",
binPath,
}, sources(pkg.ExtraOr("Files", files.Contents{}).(files.Contents)))
}, sources(pkg.ExtraOr(extraFiles, files.Contents{}).(files.Contents)))
require.ElementsMatch(t, []string{
"/usr/share/testfile.txt",
"/etc/nope.conf",
@ -184,7 +184,7 @@ func TestRunPipe(t *testing.T) {
"/etc/nope2.conf",
"/etc/nope3_mybin.conf",
"/usr/bin/subdir/mybin",
}, destinations(pkg.ExtraOr("Files", files.Contents{}).(files.Contents)))
}, destinations(pkg.ExtraOr(extraFiles, files.Contents{}).(files.Contents)))
}
require.Len(t, ctx.Config.NFPMs[0].Contents, 5, "should not modify the config file list")
}
@ -210,7 +210,7 @@ func TestInvalidTemplate(t *testing.T) {
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
return ctx
@ -315,7 +315,7 @@ func TestRunPipeInvalidContentsSourceTemplate(t *testing.T) {
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
require.EqualError(t, Pipe{}.Run(ctx), `template: tmpl:1: unexpected "}" in operand`)
@ -340,7 +340,7 @@ func TestNoBuildsFound(t *testing.T) {
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
require.EqualError(t, Pipe{}.Run(ctx), `no linux binaries found for builds [nope]`)
@ -381,7 +381,7 @@ func TestCreateFileDoesntExist(t *testing.T) {
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
require.Contains(t, Pipe{}.Run(ctx).Error(), `dist/mybin/mybin": file does not exist`)
@ -410,7 +410,7 @@ func TestInvalidConfig(t *testing.T) {
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
require.Contains(t, Pipe{}.Run(ctx).Error(), `invalid nfpm config: package name must be provided`)
@ -533,7 +533,7 @@ func TestDebSpecificConfig(t *testing.T) {
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
}
@ -607,7 +607,7 @@ func TestRPMSpecificConfig(t *testing.T) {
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
}
@ -676,7 +676,7 @@ func TestRPMSpecificScriptsConfig(t *testing.T) {
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
}
@ -754,7 +754,7 @@ func TestAPKSpecificConfig(t *testing.T) {
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
}
@ -831,7 +831,7 @@ func TestAPKSpecificScriptsConfig(t *testing.T) {
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
}
@ -955,7 +955,7 @@ func TestMeta(t *testing.T) {
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
}
@ -964,15 +964,15 @@ func TestMeta(t *testing.T) {
packages := ctx.Artifacts.Filter(artifact.ByType(artifact.LinuxPackage)).List()
require.Len(t, packages, 4)
for _, pkg := range packages {
format := pkg.ExtraOr("Format", "").(string)
format := pkg.Format()
require.NotEmpty(t, format)
require.Equal(t, pkg.Name, "foo_1.0.0_Tux_"+pkg.Goarch+"-10-20."+format)
require.Equal(t, pkg.ExtraOr("ID", ""), "someid")
require.Equal(t, pkg.ID(), "someid")
require.ElementsMatch(t, []string{
"/usr/share/testfile.txt",
"/etc/nope.conf",
"/etc/nope-rpm.conf",
}, destinations(pkg.ExtraOr("Files", files.Contents{}).(files.Contents)))
}, destinations(pkg.ExtraOr(extraFiles, files.Contents{}).(files.Contents)))
}
require.Len(t, ctx.Config.NFPMs[0].Contents, 3, "should not modify the config file list")
@ -1034,7 +1034,7 @@ func TestSkipSign(t *testing.T) {
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
}
@ -1105,7 +1105,7 @@ func TestBinDirTemplating(t *testing.T) {
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": "default",
artifact.ExtraID: "default",
},
})
}
@ -1114,12 +1114,12 @@ func TestBinDirTemplating(t *testing.T) {
packages := ctx.Artifacts.Filter(artifact.ByType(artifact.LinuxPackage)).List()
for _, pkg := range packages {
format := pkg.ExtraOr("Format", "").(string)
format := pkg.Format()
require.NotEmpty(t, format)
// the final binary should contain the evaluated bindir (after template eval)
require.ElementsMatch(t, []string{
"/usr/lib/pro/nagios/plugins/subdir/mybin",
}, destinations(pkg.ExtraOr("Files", files.Contents{}).(files.Contents)))
}, destinations(pkg.ExtraOr(extraFiles, files.Contents{}).(files.Contents)))
}
}

View File

@ -52,7 +52,7 @@ func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
Name: "bin.tar.gz",
Path: tarfile.Name(),
Extra: map[string]interface{}{
"ID": "foo",
artifact.ExtraID: "foo",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -60,7 +60,7 @@ func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
Name: "bin.deb",
Path: debfile.Name(),
Extra: map[string]interface{}{
"ID": "foo",
artifact.ExtraID: "foo",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -68,7 +68,7 @@ func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
Name: "filtered.tar.gz",
Path: filteredtarfile.Name(),
Extra: map[string]interface{}{
"ID": "bar",
artifact.ExtraID: "bar",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -76,7 +76,7 @@ func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
Name: "filtered.deb",
Path: filtereddebfile.Name(),
Extra: map[string]interface{}{
"ID": "bar",
artifact.ExtraID: "bar",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -84,7 +84,7 @@ func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
Name: "source.tar.gz",
Path: srcfile.Name(),
Extra: map[string]interface{}{
"Format": "tar.gz",
artifact.ExtraFormat: "tar.gz",
},
})
client := &client.Mock{}
@ -133,7 +133,7 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) {
Name: "bin.tar.gz",
Path: tarfile.Name(),
Extra: map[string]interface{}{
"ID": "foo",
artifact.ExtraID: "foo",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -141,7 +141,7 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) {
Name: "bin.deb",
Path: debfile.Name(),
Extra: map[string]interface{}{
"ID": "foo",
artifact.ExtraID: "foo",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -149,7 +149,7 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) {
Name: "filtered.tar.gz",
Path: filteredtarfile.Name(),
Extra: map[string]interface{}{
"ID": "bar",
artifact.ExtraID: "bar",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -157,7 +157,7 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) {
Name: "filtered.deb",
Path: filtereddebfile.Name(),
Extra: map[string]interface{}{
"ID": "bar",
artifact.ExtraID: "bar",
},
})
client := &client.Mock{}

View File

@ -258,8 +258,8 @@ func dataFor(ctx *context.Context, cl client.Client, artifacts []*artifact.Artif
func binaries(a *artifact.Artifact) []string {
// nolint: prealloc
var bins []string
wrap := a.ExtraOr("WrappedIn", "").(string)
for _, b := range a.ExtraOr("Builds", []*artifact.Artifact{}).([]*artifact.Artifact) {
wrap := a.ExtraOr(artifact.ExtraWrappedIn, "").(string)
for _, b := range a.ExtraOr(artifact.ExtraBuilds, []*artifact.Artifact{}).([]*artifact.Artifact) {
bins = append(bins, filepath.Join(wrap, b.Name))
}
return bins

View File

@ -832,7 +832,7 @@ func Test_buildManifest(t *testing.T) {
Goarch: "amd64",
Path: file,
Extra: map[string]interface{}{
"Builds": []*artifact.Artifact{
artifact.ExtraBuilds: []*artifact.Artifact{
{
Name: "foo.exe",
},
@ -848,7 +848,7 @@ func Test_buildManifest(t *testing.T) {
Goarch: "arm",
Path: file,
Extra: map[string]interface{}{
"Builds": []*artifact.Artifact{
artifact.ExtraBuilds: []*artifact.Artifact{
{
Name: "foo.exe",
},
@ -864,7 +864,7 @@ func Test_buildManifest(t *testing.T) {
Goarch: "386",
Path: file,
Extra: map[string]interface{}{
"Builds": []*artifact.Artifact{
artifact.ExtraBuilds: []*artifact.Artifact{
{
Name: "foo.exe",
},
@ -922,8 +922,8 @@ func getScoopPipeSkipCtx(folder string) (*context.Context, string) {
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
artifact.ExtraID: "foo",
artifact.ExtraFormat: "tar.gz",
},
})
@ -1000,8 +1000,8 @@ func TestWrapInDirectory(t *testing.T) {
Goarch: "amd64",
Path: file,
Extra: map[string]interface{}{
"WrappedIn": "foo_1.0.1_windows_amd64",
"Builds": []*artifact.Artifact{
artifact.ExtraWrappedIn: "foo_1.0.1_windows_amd64",
artifact.ExtraBuilds: []*artifact.Artifact{
{
Name: "foo.exe",
},

View File

@ -115,7 +115,7 @@ func sign(ctx *context.Context, cfg config.Sign, artifacts []*artifact.Artifact)
func signone(ctx *context.Context, cfg config.Sign, a *artifact.Artifact) (*artifact.Artifact, error) {
env := ctx.Env.Copy()
env["artifact"] = a.Path
env["artifactID"] = a.ExtraOr("ID", "").(string)
env["artifactID"] = a.ID()
name, err := tmpl.New(ctx).WithEnv(env).Apply(expand(cfg.Signature, env))
if err != nil {
@ -186,7 +186,7 @@ func signone(ctx *context.Context, cfg config.Sign, a *artifact.Artifact) (*arti
Name: name,
Path: filepath.Join(artifactPathBase, sigFilename),
Extra: map[string]interface{}{
"ID": cfg.ID,
artifact.ExtraID: cfg.ID,
},
}, nil
}

View File

@ -143,7 +143,7 @@ func TestDockerSignArtifacts(t *testing.T) {
Path: img1,
Type: artifact.DockerImage,
Extra: map[string]interface{}{
"ID": "img1",
artifact.ExtraID: "img1",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -151,7 +151,7 @@ func TestDockerSignArtifacts(t *testing.T) {
Path: img2,
Type: artifact.DockerImage,
Extra: map[string]interface{}{
"ID": "img2",
artifact.ExtraID: "img2",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -159,7 +159,7 @@ func TestDockerSignArtifacts(t *testing.T) {
Path: man1,
Type: artifact.DockerManifest,
Extra: map[string]interface{}{
"ID": "man1",
artifact.ExtraID: "man1",
},
})

View File

@ -476,7 +476,7 @@ func testSign(tb testing.TB, ctx *context.Context, signaturePaths []string, sign
Path: filepath.Join(tmpdir, "artifact1"),
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
artifact.ExtraID: "foo",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -484,7 +484,7 @@ func testSign(tb testing.TB, ctx *context.Context, signaturePaths []string, sign
Path: filepath.Join(tmpdir, "artifact2"),
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo3",
artifact.ExtraID: "foo3",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -492,7 +492,7 @@ func testSign(tb testing.TB, ctx *context.Context, signaturePaths []string, sign
Path: filepath.Join(tmpdir, "artifact3"),
Type: artifact.UploadableBinary,
Extra: map[string]interface{}{
"ID": "foo",
artifact.ExtraID: "foo",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -510,7 +510,7 @@ func testSign(tb testing.TB, ctx *context.Context, signaturePaths []string, sign
Path: filepath.Join(tmpdir, "linux_amd64", "artifact4"),
Type: artifact.UploadableBinary,
Extra: map[string]interface{}{
"ID": "foo3",
artifact.ExtraID: "foo3",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
@ -523,7 +523,7 @@ func testSign(tb testing.TB, ctx *context.Context, signaturePaths []string, sign
Path: filepath.Join(tmpdir, "package1.deb"),
Type: artifact.LinuxPackage,
Extra: map[string]interface{}{
"ID": "foo",
artifact.ExtraID: "foo",
},
})
@ -549,7 +549,7 @@ func testSign(tb testing.TB, ctx *context.Context, signaturePaths []string, sign
// ensure all artifacts have an ID
for _, arti := range ctx.Artifacts.Filter(artifact.ByType(artifact.Signature)).List() {
require.NotEmptyf(tb, arti.ExtraOr("ID", ""), ".Extra.ID on %s", arti.Path)
require.NotEmptyf(tb, arti.ID(), ".Extra.ID on %s", arti.Path)
}
// verify that only the artifacts and the signatures are in the dist dir

View File

@ -494,7 +494,7 @@ func addBinaries(t *testing.T, ctx *context.Context, name, dist string) {
Goos: goos,
Type: artifact.Binary,
Extra: map[string]interface{}{
"ID": name,
artifact.ExtraID: name,
},
})
}

View File

@ -38,7 +38,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
Name: filename,
Path: path,
Extra: map[string]interface{}{
"Format": ctx.Config.Source.Format,
artifact.ExtraFormat: ctx.Config.Source.Format,
},
})
return err

View File

@ -45,7 +45,7 @@ func TestArchive(t *testing.T) {
Name: "foo-1.0.0." + format,
Path: "dist/foo-1.0.0." + format,
Extra: map[string]interface{}{
"Format": format,
artifact.ExtraFormat: format,
},
}, *artifacts[0])
stat, err := os.Stat(filepath.Join(tmp, "dist", "foo-1.0.0."+format))

View File

@ -162,8 +162,8 @@ func TestRun(t *testing.T) {
Goarch: arch,
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "fake",
"ID": "foo",
artifact.ExtraBinary: "fake",
artifact.ExtraID: "foo",
},
}
ctx1.Artifacts.Add(&art)
@ -175,8 +175,8 @@ func TestRun(t *testing.T) {
Goarch: arch,
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "fake",
"ID": "foo",
artifact.ExtraBinary: "fake",
artifact.ExtraID: "foo",
},
})
}

View File

@ -69,7 +69,7 @@ func TestWithArtifact(t *testing.T) {
Goarm: "6",
Gomips: "softfloat",
Extra: map[string]interface{}{
"Binary": "binary",
artifact.ExtraBinary: "binary",
},
},
map[string]string{"linux": "Linux"},