From b477ffa0957e9eefffa143b5dfe2b2091f021023 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 12 Aug 2019 17:44:48 -0300 Subject: [PATCH] refactor: pointer to artifact (#1110) Signed-off-by: Carlos Alexandro Becker --- internal/artifact/artifact.go | 30 +++++++++---------- internal/artifact/artifact_test.go | 14 ++++----- internal/builders/golang/build.go | 2 +- internal/builders/golang/build_test.go | 2 +- internal/http/http.go | 6 ++-- internal/http/http_test.go | 2 +- internal/pipe/archive/archive.go | 10 +++---- internal/pipe/archive/archive_test.go | 30 +++++++++---------- internal/pipe/artifactory/artifactory_test.go | 22 +++++++------- internal/pipe/blob/blob_test.go | 12 ++++---- internal/pipe/brew/brew.go | 4 +-- internal/pipe/brew/brew_test.go | 12 ++++---- internal/pipe/build/build_test.go | 6 ++-- internal/pipe/checksums/checksums.go | 4 +-- internal/pipe/checksums/checksums_test.go | 10 +++---- internal/pipe/docker/docker.go | 8 ++--- internal/pipe/docker/docker_test.go | 2 +- internal/pipe/nfpm/nfpm.go | 4 +-- internal/pipe/nfpm/nfpm_test.go | 12 ++++---- internal/pipe/put/put_test.go | 18 +++++------ internal/pipe/release/body_test.go | 2 +- internal/pipe/release/release.go | 2 +- internal/pipe/release/release_test.go | 10 +++---- internal/pipe/s3/s3_test.go | 12 ++++---- internal/pipe/scoop/scoop.go | 6 ++-- internal/pipe/scoop/scoop_test.go | 24 +++++++-------- internal/pipe/sign/sign.go | 6 ++-- internal/pipe/sign/sign_test.go | 10 +++---- internal/pipe/snapcraft/snapcraft.go | 6 ++-- internal/pipe/snapcraft/snapcraft_test.go | 4 +-- internal/tmpl/tmpl.go | 2 +- internal/tmpl/tmpl_test.go | 4 +-- 32 files changed, 149 insertions(+), 149 deletions(-) diff --git a/internal/artifact/artifact.go b/internal/artifact/artifact.go index 5b190f222..c98684e8f 100644 --- a/internal/artifact/artifact.go +++ b/internal/artifact/artifact.go @@ -122,26 +122,26 @@ func (a Artifact) Checksum(algorithm string) (string, error) { // Artifacts is a list of artifacts type Artifacts struct { - items []Artifact + items []*Artifact lock *sync.Mutex } // New return a new list of artifacts func New() Artifacts { return Artifacts{ - items: []Artifact{}, + items: []*Artifact{}, lock: &sync.Mutex{}, } } // List return the actual list of artifacts -func (artifacts Artifacts) List() []Artifact { +func (artifacts Artifacts) List() []*Artifact { return artifacts.items } // GroupByPlatform groups the artifacts by their platform -func (artifacts Artifacts) GroupByPlatform() map[string][]Artifact { - var result = map[string][]Artifact{} +func (artifacts Artifacts) GroupByPlatform() map[string][]*Artifact { + var result = map[string][]*Artifact{} for _, a := range artifacts.items { plat := a.Goos + a.Goarch + a.Goarm result[plat] = append(result[plat], a) @@ -150,7 +150,7 @@ func (artifacts Artifacts) GroupByPlatform() map[string][]Artifact { } // Add safely adds a new artifact to an artifact list -func (artifacts *Artifacts) Add(a Artifact) { +func (artifacts *Artifacts) Add(a *Artifact) { artifacts.lock.Lock() defer artifacts.lock.Unlock() log.WithFields(log.Fields{ @@ -163,32 +163,32 @@ func (artifacts *Artifacts) Add(a Artifact) { // Filter defines an artifact filter which can be used within the Filter // function -type Filter func(a Artifact) bool +type Filter func(a *Artifact) bool // ByGoos is a predefined filter that filters by the given goos func ByGoos(s string) Filter { - return func(a Artifact) bool { + return func(a *Artifact) bool { return a.Goos == s } } // ByGoarch is a predefined filter that filters by the given goarch func ByGoarch(s string) Filter { - return func(a Artifact) bool { + return func(a *Artifact) bool { return a.Goarch == s } } // ByGoarm is a predefined filter that filters by the given goarm func ByGoarm(s string) Filter { - return func(a Artifact) bool { + return func(a *Artifact) bool { return a.Goarm == s } } // ByType is a predefined filter that filters by the given type func ByType(t Type) Filter { - return func(a Artifact) bool { + return func(a *Artifact) bool { return a.Type == t } } @@ -198,7 +198,7 @@ func ByFormats(formats ...string) Filter { var filters = make([]Filter, 0, len(formats)) for _, format := range formats { format := format - filters = append(filters, func(a Artifact) bool { + filters = append(filters, func(a *Artifact) bool { return a.ExtraOr("Format", "") == format }) } @@ -210,7 +210,7 @@ func ByIDs(ids ...string) Filter { var filters = make([]Filter, 0, len(ids)) for _, id := range ids { id := id - filters = append(filters, func(a Artifact) bool { + filters = append(filters, func(a *Artifact) bool { return a.ExtraOr("ID", "") == id }) } @@ -219,7 +219,7 @@ func ByIDs(ids ...string) Filter { // Or performs an OR between all given filters func Or(filters ...Filter) Filter { - return func(a Artifact) bool { + return func(a *Artifact) bool { for _, f := range filters { if f(a) { return true @@ -231,7 +231,7 @@ func Or(filters ...Filter) Filter { // And performs an AND between all given filters func And(filters ...Filter) Filter { - return func(a Artifact) bool { + return func(a *Artifact) bool { for _, f := range filters { if !f(a) { return false diff --git a/internal/artifact/artifact_test.go b/internal/artifact/artifact_test.go index 546d443f5..a6f0e295e 100644 --- a/internal/artifact/artifact_test.go +++ b/internal/artifact/artifact_test.go @@ -17,7 +17,7 @@ var _ fmt.Stringer = Type(0) func TestAdd(t *testing.T) { var g errgroup.Group var artifacts = New() - for _, a := range []Artifact{ + for _, a := range []*Artifact{ { Name: "foo", Type: UploadableArchive, @@ -46,7 +46,7 @@ func TestAdd(t *testing.T) { } func TestFilter(t *testing.T) { - var data = []Artifact{ + var data = []*Artifact{ { Name: "foo", Goos: "linux", @@ -89,7 +89,7 @@ func TestFilter(t *testing.T) { assert.Len(t, artifacts.Filter( And( ByType(Checksum), - func(a Artifact) bool { + func(a *Artifact) bool { return a.Name == "checkzumm" }, ), @@ -107,7 +107,7 @@ func TestFilter(t *testing.T) { } func TestGroupByPlatform(t *testing.T) { - var data = []Artifact{ + var data = []*Artifact{ { Name: "foo", Goos: "linux", @@ -187,7 +187,7 @@ func TestInvalidAlgorithm(t *testing.T) { } func TestExtraOr(t *testing.T) { - var a = Artifact{ + var a = &Artifact{ Extra: map[string]interface{}{ "Foo": "foo", }, @@ -197,7 +197,7 @@ func TestExtraOr(t *testing.T) { } func TestByIDs(t *testing.T) { - var data = []Artifact{ + var data = []*Artifact{ { Name: "foo", Extra: map[string]interface{}{ @@ -234,7 +234,7 @@ func TestByIDs(t *testing.T) { } func TestByFormats(t *testing.T) { - var data = []Artifact{ + var data = []*Artifact{ { Name: "foo", Extra: map[string]interface{}{ diff --git a/internal/builders/golang/build.go b/internal/builders/golang/build.go index ae9303504..cb9df06e0 100644 --- a/internal/builders/golang/build.go +++ b/internal/builders/golang/build.go @@ -100,7 +100,7 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti if err := run(ctx, cmd, env); err != nil { return errors.Wrapf(err, "failed to build for %s", options.Target) } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.Binary, Path: options.Path, Name: options.Name, diff --git a/internal/builders/golang/build_test.go b/internal/builders/golang/build_test.go index d3423e10c..572d412fe 100644 --- a/internal/builders/golang/build_test.go +++ b/internal/builders/golang/build_test.go @@ -115,7 +115,7 @@ func TestBuild(t *testing.T) { }) assert.NoError(t, err) } - assert.ElementsMatch(t, ctx.Artifacts.List(), []artifact.Artifact{ + assert.ElementsMatch(t, ctx.Artifacts.List(), []*artifact.Artifact{ { Name: "foo", Path: filepath.Join(folder, "dist", "linux_amd64", "foo"), diff --git a/internal/http/http.go b/internal/http/http.go index 424f85535..654a7bb8b 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -179,7 +179,7 @@ func uploadWithFilter(ctx *context.Context, put *config.Put, filter artifact.Fil } // uploadAsset uploads file to target and logs all actions -func uploadAsset(ctx *context.Context, put *config.Put, artifact artifact.Artifact, kind string, check ResponseChecker) error { +func uploadAsset(ctx *context.Context, put *config.Put, artifact *artifact.Artifact, kind string, check ResponseChecker) error { envBase := fmt.Sprintf("%s_%s_", strings.ToUpper(kind), strings.ToUpper(put.Name)) username := put.Username if username == "" { @@ -197,7 +197,7 @@ func uploadAsset(ctx *context.Context, put *config.Put, artifact artifact.Artifa } // Handle the artifact - asset, err := assetOpen(kind, &artifact) + asset, err := assetOpen(kind, artifact) if err != nil { return err } @@ -335,7 +335,7 @@ type targetData struct { // resolveTargetTemplate returns the resolved target template with replaced variables // Those variables can be replaced by the given context, goos, goarch, goarm and more // TODO: replace this with our internal template pkg -func resolveTargetTemplate(ctx *context.Context, put *config.Put, artifact artifact.Artifact) (string, error) { +func resolveTargetTemplate(ctx *context.Context, put *config.Put, artifact *artifact.Artifact) (string, error) { data := targetData{ Version: ctx.Version, Tag: ctx.Git.CurrentTag, diff --git a/internal/http/http_test.go b/internal/http/http_test.go index a0335a3ee..8f35f4981 100644 --- a/internal/http/http_test.go +++ b/internal/http/http_test.go @@ -226,7 +226,7 @@ func TestUpload(t *testing.T) { } { var file = filepath.Join(folder, "a."+a.ext) require.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644)) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "a." + a.ext, Path: file, Type: a.typ, diff --git a/internal/pipe/archive/archive.go b/internal/pipe/archive/archive.go index e8e6619c5..5f82721b8 100644 --- a/internal/pipe/archive/archive.go +++ b/internal/pipe/archive/archive.go @@ -110,7 +110,7 @@ func (Pipe) Run(ctx *context.Context) error { return g.Wait() } -func create(ctx *context.Context, archive config.Archive, binaries []artifact.Artifact) error { +func create(ctx *context.Context, archive config.Archive, binaries []*artifact.Artifact) error { var format = packageFormat(archive, binaries[0].Goos) folder, err := tmpl.New(ctx). WithArtifact(binaries[0], archive.Replacements). @@ -159,7 +159,7 @@ func create(ctx *context.Context, archive config.Archive, binaries []artifact.Ar return fmt.Errorf("failed to add %s -> %s to the archive: %s", binary.Path, binary.Name, err.Error()) } } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: folder + "." + format, Path: archivePath, @@ -186,7 +186,7 @@ func wrapFolder(a config.Archive) string { } } -func skip(ctx *context.Context, archive config.Archive, binaries []artifact.Artifact) error { +func skip(ctx *context.Context, archive config.Archive, binaries []*artifact.Artifact) error { for _, binary := range binaries { log.WithField("binary", binary.Name).Info("skip archiving") name, err := tmpl.New(ctx). @@ -195,7 +195,7 @@ func skip(ctx *context.Context, archive config.Archive, binaries []artifact.Arti if err != nil { return err } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableBinary, Name: name + binary.ExtraOr("Ext", "").(string), Path: binary.Path, @@ -203,7 +203,7 @@ func skip(ctx *context.Context, archive config.Archive, binaries []artifact.Arti Goarch: binary.Goarch, Goarm: binary.Goarm, Extra: map[string]interface{}{ - "Builds": []artifact.Artifact{binary}, + "Builds": []*artifact.Artifact{binary}, "ID": archive.ID, "Format": archive.Format, }, diff --git a/internal/pipe/archive/archive_test.go b/internal/pipe/archive/archive_test.go index b685e8f61..47a4533a2 100644 --- a/internal/pipe/archive/archive_test.go +++ b/internal/pipe/archive/archive_test.go @@ -63,7 +63,7 @@ func TestRunPipe(t *testing.T) { }, }, ) - var darwinBuild = artifact.Artifact{ + var darwinBuild = &artifact.Artifact{ Goos: "darwin", Goarch: "amd64", Name: "mybin", @@ -74,7 +74,7 @@ func TestRunPipe(t *testing.T) { "ID": "default", }, } - var windowsBuild = artifact.Artifact{ + var windowsBuild = &artifact.Artifact{ Goos: "windows", Goarch: "amd64", Name: "mybin.exe", @@ -102,8 +102,8 @@ func TestRunPipe(t *testing.T) { require.Equal(tt, "foobar_0.0.1_darwin_amd64."+format, darwin.Name) require.Equal(tt, "foobar_0.0.1_windows_amd64.zip", windows.Name) - require.Equal(t, []artifact.Artifact{darwinBuild}, darwin.Extra["Builds"].([]artifact.Artifact)) - require.Equal(t, []artifact.Artifact{windowsBuild}, windows.Extra["Builds"].([]artifact.Artifact)) + require.Equal(t, []*artifact.Artifact{darwinBuild}, darwin.Extra["Builds"].([]*artifact.Artifact)) + require.Equal(t, []*artifact.Artifact{windowsBuild}, windows.Extra["Builds"].([]*artifact.Artifact)) if format == "tar.gz" { // Check archive contents @@ -195,7 +195,7 @@ func TestRunPipeBinary(t *testing.T) { ) ctx.Version = "0.0.1" ctx.Git.CurrentTag = "v0.0.1" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Goos: "darwin", Goarch: "amd64", Name: "mybin", @@ -206,7 +206,7 @@ func TestRunPipeBinary(t *testing.T) { "ID": "default", }, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Goos: "windows", Goarch: "amd64", Name: "mybin.exe", @@ -241,7 +241,7 @@ func TestRunPipeDistRemoved(t *testing.T) { }, ) ctx.Git.CurrentTag = "v0.0.1" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Goos: "windows", Goarch: "amd64", Name: "mybin.exe", @@ -280,7 +280,7 @@ func TestRunPipeInvalidGlob(t *testing.T) { }, ) ctx.Git.CurrentTag = "v0.0.1" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Goos: "darwin", Goarch: "amd64", Name: "mybin", @@ -315,7 +315,7 @@ func TestRunPipeInvalidNameTemplate(t *testing.T) { }, ) ctx.Git.CurrentTag = "v0.0.1" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Goos: "darwin", Goarch: "amd64", Name: "mybin", @@ -351,7 +351,7 @@ func TestRunPipeInvalidWrapInDirectoryTemplate(t *testing.T) { }, ) ctx.Git.CurrentTag = "v0.0.1" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Goos: "darwin", Goarch: "amd64", Name: "mybin", @@ -395,7 +395,7 @@ func TestRunPipeWrap(t *testing.T) { }, ) ctx.Git.CurrentTag = "v0.0.1" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Goos: "darwin", Goarch: "amd64", Name: "mybin", @@ -531,7 +531,7 @@ func TestBinaryOverride(t *testing.T) { }, ) ctx.Git.CurrentTag = "v0.0.1" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Goos: "darwin", Goarch: "amd64", Name: "mybin", @@ -542,7 +542,7 @@ func TestBinaryOverride(t *testing.T) { "ID": "default", }, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Goos: "windows", Goarch: "amd64", Name: "mybin.exe", @@ -599,7 +599,7 @@ func TestRunPipeSameArchiveFilename(t *testing.T) { }, }, ) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Goos: "darwin", Goarch: "amd64", Name: "mybin", @@ -610,7 +610,7 @@ func TestRunPipeSameArchiveFilename(t *testing.T) { "ID": "default", }, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Goos: "windows", Goarch: "amd64", Name: "mybin.exe", diff --git a/internal/pipe/artifactory/artifactory_test.go b/internal/pipe/artifactory/artifactory_test.go index be9a4b98c..1ece7d327 100644 --- a/internal/pipe/artifactory/artifactory_test.go +++ b/internal/pipe/artifactory/artifactory_test.go @@ -194,7 +194,7 @@ func TestRunPipe_ModeBinary(t *testing.T) { "ARTIFACTORY_PRODUCTION-EU_SECRET": "productionuser-apikey", } for _, goos := range []string{"linux", "darwin"} { - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: binPath, Goarch: "amd64", @@ -233,12 +233,12 @@ func TestRunPipe_ModeArchive(t *testing.T) { "ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret", } ctx.Version = "1.0.0" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tarfile.Name(), }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.LinuxPackage, Name: "bin.deb", Path: debfile.Name(), @@ -329,7 +329,7 @@ func TestRunPipe_ArtifactoryDown(t *testing.T) { ctx.Env = map[string]string{ "ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tarfile.Name(), @@ -361,7 +361,7 @@ func TestRunPipe_TargetTemplateError(t *testing.T) { ctx.Env = map[string]string{ "ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: binPath, Goarch: "amd64", @@ -417,7 +417,7 @@ func TestRunPipe_BadCredentials(t *testing.T) { ctx.Env = map[string]string{ "ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: binPath, Goarch: "amd64", @@ -474,7 +474,7 @@ func TestRunPipe_UnparsableErrorResponse(t *testing.T) { ctx.Env = map[string]string{ "ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: binPath, Goarch: "amd64", @@ -528,7 +528,7 @@ func TestRunPipe_UnparsableResponse(t *testing.T) { ctx.Env = map[string]string{ "ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: binPath, Goarch: "amd64", @@ -555,7 +555,7 @@ func TestRunPipe_FileNotFound(t *testing.T) { ctx.Env = map[string]string{ "ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: "archivetest/dist/mybin/mybin", Goarch: "amd64", @@ -592,7 +592,7 @@ func TestRunPipe_UnparsableTarget(t *testing.T) { ctx.Env = map[string]string{ "ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: binPath, Goarch: "amd64", @@ -647,7 +647,7 @@ func TestRunPipe_DirUpload(t *testing.T) { ctx.Env = map[string]string{ "ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: filepath.Dir(binPath), Goarch: "amd64", diff --git a/internal/pipe/blob/blob_test.go b/internal/pipe/blob/blob_test.go index a11aa5219..e4b4237a3 100644 --- a/internal/pipe/blob/blob_test.go +++ b/internal/pipe/blob/blob_test.go @@ -137,12 +137,12 @@ func TestPipe_Publish(t *testing.T) { }) azblobctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} - azblobctx.Artifacts.Add(artifact.Artifact{ + azblobctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tgzpath, }) - azblobctx.Artifacts.Add(artifact.Artifact{ + azblobctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.LinuxPackage, Name: "bin.deb", Path: debpath, @@ -162,12 +162,12 @@ func TestPipe_Publish(t *testing.T) { gsctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} - gsctx.Artifacts.Add(artifact.Artifact{ + gsctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tgzpath, }) - gsctx.Artifacts.Add(artifact.Artifact{ + gsctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.LinuxPackage, Name: "bin.deb", Path: debpath, @@ -185,12 +185,12 @@ func TestPipe_Publish(t *testing.T) { }, }) s3ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} - s3ctx.Artifacts.Add(artifact.Artifact{ + s3ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tgzpath, }) - s3ctx.Artifacts.Add(artifact.Artifact{ + s3ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.LinuxPackage, Name: "bin.deb", Path: debpath, diff --git a/internal/pipe/brew/brew.go b/internal/pipe/brew/brew.go index 929b7eb67..9704c7d1c 100644 --- a/internal/pipe/brew/brew.go +++ b/internal/pipe/brew/brew.go @@ -178,7 +178,7 @@ func ghFormulaPath(folder, filename string) string { return path.Join(folder, filename) } -func buildFormula(ctx *context.Context, brew config.Homebrew, artifacts []artifact.Artifact) (string, error) { +func buildFormula(ctx *context.Context, brew config.Homebrew, artifacts []*artifact.Artifact) (string, error) { data, err := dataFor(ctx, brew, artifacts) if err != nil { return "", err @@ -198,7 +198,7 @@ func doBuildFormula(ctx *context.Context, data templateData) (string, error) { return tmpl.New(ctx).Apply(out.String()) } -func dataFor(ctx *context.Context, cfg config.Homebrew, artifacts []artifact.Artifact) (templateData, error) { +func dataFor(ctx *context.Context, cfg config.Homebrew, artifacts []*artifact.Artifact) (templateData, error) { var result = templateData{ Name: formulaNameFor(cfg.Name), Desc: cfg.Description, diff --git a/internal/pipe/brew/brew_test.go b/internal/pipe/brew/brew_test.go index 557cec870..274d5b5b7 100644 --- a/internal/pipe/brew/brew_test.go +++ b/internal/pipe/brew/brew_test.go @@ -163,7 +163,7 @@ func TestRunPipe(t *testing.T) { }, } fn(ctx) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "bar_bin.tar.gz", Path: "doesnt matter", Goos: "darwin", @@ -175,7 +175,7 @@ func TestRunPipe(t *testing.T) { }, }) var path = filepath.Join(folder, "bin.tar.gz") - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "bin.tar.gz", Path: path, Goos: "darwin", @@ -244,7 +244,7 @@ func TestRunPipeMultipleDarwin64Build(t *testing.T) { f, err := ioutil.TempFile("", "") assert.NoError(t, err) defer f.Close() - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "bin1", Path: f.Name(), Goos: "darwin", @@ -255,7 +255,7 @@ func TestRunPipeMultipleDarwin64Build(t *testing.T) { "Format": "tar.gz", }, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "bin2", Path: f.Name(), Goos: "darwin", @@ -293,7 +293,7 @@ func TestRunPipeBinaryRelease(t *testing.T) { }, }, ) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "bin", Path: "doesnt mather", Goos: "darwin", @@ -325,7 +325,7 @@ func TestRunPipeNoUpload(t *testing.T) { var path = filepath.Join(folder, "whatever.tar.gz") _, err = os.Create(path) assert.NoError(t, err) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "bin", Path: path, Goos: "darwin", diff --git a/internal/pipe/build/build_test.go b/internal/pipe/build/build_test.go index 9441df6cf..3f98612c5 100644 --- a/internal/pipe/build/build_test.go +++ b/internal/pipe/build/build_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/assert" ) -var fakeArtifact = artifact.Artifact{ +var fakeArtifact = &artifact.Artifact{ Name: "fake", } @@ -101,7 +101,7 @@ func TestRunPipe(t *testing.T) { var ctx = context.New(config) ctx.Git.CurrentTag = "2.4.5" assert.NoError(t, Pipe{}.Run(ctx)) - assert.Equal(t, ctx.Artifacts.List(), []artifact.Artifact{fakeArtifact}) + assert.Equal(t, ctx.Artifacts.List(), []*artifact.Artifact{fakeArtifact}) } func TestRunFullPipe(t *testing.T) { @@ -129,7 +129,7 @@ func TestRunFullPipe(t *testing.T) { var ctx = context.New(config) ctx.Git.CurrentTag = "2.4.5" assert.NoError(t, Pipe{}.Run(ctx)) - assert.Equal(t, ctx.Artifacts.List(), []artifact.Artifact{fakeArtifact}) + assert.Equal(t, ctx.Artifacts.List(), []*artifact.Artifact{fakeArtifact}) assert.FileExists(t, post) assert.FileExists(t, pre) assert.FileExists(t, filepath.Join(folder, "build1_whatever", "testing")) diff --git a/internal/pipe/checksums/checksums.go b/internal/pipe/checksums/checksums.go index 4dbf64e1c..eac649f86 100644 --- a/internal/pipe/checksums/checksums.go +++ b/internal/pipe/checksums/checksums.go @@ -62,7 +62,7 @@ func (Pipe) Run(ctx *context.Context) (err error) { return checksums(ctx.Config.Checksum.Algorithm, file, artifact) }) } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.Checksum, Path: file.Name(), Name: filename, @@ -70,7 +70,7 @@ func (Pipe) Run(ctx *context.Context) (err error) { return g.Wait() } -func checksums(algorithm string, w io.Writer, artifact artifact.Artifact) error { +func checksums(algorithm string, w io.Writer, artifact *artifact.Artifact) error { log.WithField("file", artifact.Name).Info("checksumming") sha, err := artifact.Checksum(algorithm) if err != nil { diff --git a/internal/pipe/checksums/checksums_test.go b/internal/pipe/checksums/checksums_test.go index 7416a0c2a..cd24a2b0b 100644 --- a/internal/pipe/checksums/checksums_test.go +++ b/internal/pipe/checksums/checksums_test.go @@ -35,12 +35,12 @@ func TestPipe(t *testing.T) { ) ctx.Git.CurrentTag = "1.2.3" ctx.Env = map[string]string{"FOO": "bar"} - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: binary, Path: file, Type: artifact.UploadableBinary, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: binary + ".tar.gz", Path: file, Type: artifact.UploadableArchive, @@ -69,7 +69,7 @@ func TestPipeFileNotExist(t *testing.T) { }, ) ctx.Git.CurrentTag = "1.2.3" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "nope", Path: "/nope", Type: artifact.UploadableBinary, @@ -97,7 +97,7 @@ func TestPipeInvalidNameTemplate(t *testing.T) { }, ) ctx.Git.CurrentTag = "1.2.3" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "whatever", Type: artifact.UploadableBinary, }) @@ -122,7 +122,7 @@ func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) { }, ) ctx.Git.CurrentTag = "1.2.3" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "whatever", Type: artifact.UploadableBinary, }) diff --git a/internal/pipe/docker/docker.go b/internal/pipe/docker/docker.go index c91f82ed0..7a9fdc2f7 100644 --- a/internal/pipe/docker/docker.go +++ b/internal/pipe/docker/docker.go @@ -99,7 +99,7 @@ func doRun(ctx *context.Context) error { artifact.ByGoarch(docker.Goarch), artifact.ByGoarm(docker.Goarm), artifact.ByType(artifact.Binary), - func(a artifact.Artifact) bool { + func(a *artifact.Artifact) bool { for _, bin := range binaryNames { if a.ExtraOr("Binary", "").(string) == bin { return true @@ -125,7 +125,7 @@ func doRun(ctx *context.Context) error { return g.Wait() } -func process(ctx *context.Context, docker config.Docker, bins []artifact.Artifact) error { +func process(ctx *context.Context, docker config.Docker, bins []*artifact.Artifact) error { tmp, err := ioutil.TempDir(ctx.Config.Dist, "goreleaserdocker") if err != nil { return errors.Wrap(err, "failed to create temporary dir") @@ -176,7 +176,7 @@ func process(ctx *context.Context, docker config.Docker, bins []artifact.Artifac return pipe.Skip("prerelease detected with 'auto' push, skipping docker publish") } for _, img := range images { - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.PublishableDockerImage, Name: img, Path: img, @@ -262,7 +262,7 @@ func buildCommand(images, flags []string) []string { return base } -func dockerPush(ctx *context.Context, image artifact.Artifact) error { +func dockerPush(ctx *context.Context, image *artifact.Artifact) error { log.WithField("image", image.Name).Info("pushing docker image") /* #nosec */ var cmd = exec.CommandContext(ctx, "docker", "push", image.Name) diff --git a/internal/pipe/docker/docker_test.go b/internal/pipe/docker/docker_test.go index b42392add..4d90638b5 100644 --- a/internal/pipe/docker/docker_test.go +++ b/internal/pipe/docker/docker_test.go @@ -545,7 +545,7 @@ func TestRunPipe(t *testing.T) { for _, os := range []string{"linux", "darwin"} { for _, arch := range []string{"amd64", "386"} { for _, bin := range []string{"mybin", "anotherbin"} { - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: bin, Path: filepath.Join(dist, "mybin", bin), Goarch: arch, diff --git a/internal/pipe/nfpm/nfpm.go b/internal/pipe/nfpm/nfpm.go index 78222e323..f0d581a6c 100644 --- a/internal/pipe/nfpm/nfpm.go +++ b/internal/pipe/nfpm/nfpm.go @@ -118,7 +118,7 @@ func mergeOverrides(fpm config.NFPM, format string) (*config.NFPMOverridables, e return &overrided, nil } -func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries []artifact.Artifact) error { +func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries []*artifact.Artifact) error { overrided, err := mergeOverrides(fpm, format) if err != nil { return err @@ -195,7 +195,7 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries if err := w.Close(); err != nil { return errors.Wrap(err, "could not close package file") } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.LinuxPackage, Name: name + "." + format, Path: path, diff --git a/internal/pipe/nfpm/nfpm_test.go b/internal/pipe/nfpm/nfpm_test.go index 88cc8a05b..839f055ec 100644 --- a/internal/pipe/nfpm/nfpm_test.go +++ b/internal/pipe/nfpm/nfpm_test.go @@ -50,7 +50,7 @@ func TestRunPipeInvalidFormat(t *testing.T) { } for _, goos := range []string{"linux", "darwin"} { for _, goarch := range []string{"amd64", "386"} { - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: "whatever", Goarch: goarch, @@ -118,7 +118,7 @@ func TestRunPipe(t *testing.T) { ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} for _, goos := range []string{"linux", "darwin"} { for _, goarch := range []string{"amd64", "386"} { - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: binPath, Goarch: goarch, @@ -153,7 +153,7 @@ func TestInvalidNameTemplate(t *testing.T) { }, }, } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Goos: "linux", Goarch: "amd64", @@ -178,7 +178,7 @@ func TestNoBuildsFound(t *testing.T) { }, }, } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Goos: "linux", Goarch: "amd64", @@ -214,7 +214,7 @@ func TestCreateFileDoesntExist(t *testing.T) { ctx.Git = context.GitInfo{ CurrentTag: "v1.2.3", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: filepath.Join(dist, "mybin", "mybin"), Goos: "linux", @@ -244,7 +244,7 @@ func TestInvalidConfig(t *testing.T) { }) ctx.Git.CurrentTag = "v1.2.3" ctx.Version = "v1.2.3" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: filepath.Join(dist, "mybin", "mybin"), Goos: "linux", diff --git a/internal/pipe/put/put_test.go b/internal/pipe/put/put_test.go index 9e0bc4286..b783b891c 100644 --- a/internal/pipe/put/put_test.go +++ b/internal/pipe/put/put_test.go @@ -126,7 +126,7 @@ func TestRunPipe_ModeBinary(t *testing.T) { "PUT_PRODUCTION-EU_SECRET": "productionuser-apikey", } for _, goos := range []string{"linux", "darwin"} { - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: binPath, Goarch: "amd64", @@ -165,12 +165,12 @@ func TestRunPipe_ModeArchive(t *testing.T) { "PUT_PRODUCTION_SECRET": "deployuser-secret", } ctx.Version = "1.0.0" - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tarfile.Name(), }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.LinuxPackage, Name: "bin.deb", Path: debfile.Name(), @@ -227,7 +227,7 @@ func TestRunPipe_ArtifactoryDown(t *testing.T) { ctx.Env = map[string]string{ "PUT_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tarfile.Name(), @@ -259,7 +259,7 @@ func TestRunPipe_TargetTemplateError(t *testing.T) { ctx.Env = map[string]string{ "PUT_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: binPath, Goarch: "amd64", @@ -310,7 +310,7 @@ func TestRunPipe_BadCredentials(t *testing.T) { ctx.Env = map[string]string{ "PUT_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: binPath, Goarch: "amd64", @@ -339,7 +339,7 @@ func TestRunPipe_FileNotFound(t *testing.T) { ctx.Env = map[string]string{ "PUT_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: "archivetest/dist/mybin/mybin", Goarch: "amd64", @@ -376,7 +376,7 @@ func TestRunPipe_UnparsableTarget(t *testing.T) { ctx.Env = map[string]string{ "PUT_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: binPath, Goarch: "amd64", @@ -431,7 +431,7 @@ func TestRunPipe_DirUpload(t *testing.T) { ctx.Env = map[string]string{ "PUT_PRODUCTION_SECRET": "deployuser-secret", } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: filepath.Dir(binPath), Goarch: "amd64", diff --git a/internal/pipe/release/body_test.go b/internal/pipe/release/body_test.go index 1d45c5306..41210bf4c 100644 --- a/internal/pipe/release/body_test.go +++ b/internal/pipe/release/body_test.go @@ -22,7 +22,7 @@ func TestDescribeBody(t *testing.T) { "goreleaser/goreleaser:latest", "goreleaser/godownloader:v0.1.0", } { - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: d, Type: artifact.DockerImage, }) diff --git a/internal/pipe/release/release.go b/internal/pipe/release/release.go index 3e5f2140f..85f946d6f 100644 --- a/internal/pipe/release/release.go +++ b/internal/pipe/release/release.go @@ -135,7 +135,7 @@ func doPublish(ctx *context.Context, client client.Client) error { return g.Wait() } -func upload(ctx *context.Context, client client.Client, releaseID string, artifact artifact.Artifact) error { +func upload(ctx *context.Context, client client.Client, releaseID string, artifact *artifact.Artifact) error { file, err := os.Open(artifact.Path) if err != nil { return err diff --git a/internal/pipe/release/release_test.go b/internal/pipe/release/release_test.go index 2ff76ec0a..d13cd717a 100644 --- a/internal/pipe/release/release_test.go +++ b/internal/pipe/release/release_test.go @@ -37,12 +37,12 @@ func TestRunPipe(t *testing.T) { } var ctx = context.New(config) ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tarfile.Name(), }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.LinuxPackage, Name: "bin.deb", Path: debfile.Name(), @@ -85,7 +85,7 @@ func TestRunPipeWithFileThatDontExist(t *testing.T) { } var ctx = context.New(config) ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: "/nope/nope/nope", @@ -111,7 +111,7 @@ func TestRunPipeUploadFailure(t *testing.T) { } var ctx = context.New(config) ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tarfile.Name(), @@ -139,7 +139,7 @@ func TestRunPipeUploadRetry(t *testing.T) { } var ctx = context.New(config) ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tarfile.Name(), diff --git a/internal/pipe/s3/s3_test.go b/internal/pipe/s3/s3_test.go index 11b5916b6..8615fb053 100644 --- a/internal/pipe/s3/s3_test.go +++ b/internal/pipe/s3/s3_test.go @@ -77,7 +77,7 @@ func TestUpload(t *testing.T) { }, }) ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tgzpath, @@ -85,7 +85,7 @@ func TestUpload(t *testing.T) { "ID": "foo", }, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.LinuxPackage, Name: "bin.deb", Path: debpath, @@ -123,12 +123,12 @@ func TestUploadCustomBucketID(t *testing.T) { }, }) ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tgzpath, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.LinuxPackage, Name: "bin.deb", Path: debpath, @@ -162,12 +162,12 @@ func TestUploadInvalidCustomBucketID(t *testing.T) { }, }) ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tgzpath, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.LinuxPackage, Name: "bin.deb", Path: debpath, diff --git a/internal/pipe/scoop/scoop.go b/internal/pipe/scoop/scoop.go index 6409c06af..24c9950d4 100644 --- a/internal/pipe/scoop/scoop.go +++ b/internal/pipe/scoop/scoop.go @@ -120,7 +120,7 @@ type Resource struct { Hash string `json:"hash"` // the archive checksum } -func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (bytes.Buffer, error) { +func buildManifest(ctx *context.Context, artifacts []*artifact.Artifact) (bytes.Buffer, error) { var result bytes.Buffer var manifest = Manifest{ Version: ctx.Version, @@ -164,10 +164,10 @@ func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (bytes.B return result, err } -func binaries(a artifact.Artifact) []string { +func binaries(a *artifact.Artifact) []string { // nolint: prealloc var bins []string - for _, b := range a.ExtraOr("Builds", []artifact.Artifact{}).([]artifact.Artifact) { + for _, b := range a.ExtraOr("Builds", []*artifact.Artifact{}).([]*artifact.Artifact) { bins = append(bins, b.ExtraOr("Binary", "").(string)+".exe") } return bins diff --git a/internal/pipe/scoop/scoop_test.go b/internal/pipe/scoop/scoop_test.go index 5fb7d2cf4..5e6cecea1 100644 --- a/internal/pipe/scoop/scoop_test.go +++ b/internal/pipe/scoop/scoop_test.go @@ -81,7 +81,7 @@ func Test_doRun(t *testing.T) { tests := []struct { name string args args - artifacts []artifact.Artifact + artifacts []*artifact.Artifact assertError errChecker }{ { @@ -120,7 +120,7 @@ func Test_doRun(t *testing.T) { }, &DummyClient{}, }, - []artifact.Artifact{ + []*artifact.Artifact{ {Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file}, {Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file}, }, @@ -163,7 +163,7 @@ func Test_doRun(t *testing.T) { }, &DummyClient{}, }, - []artifact.Artifact{ + []*artifact.Artifact{ {Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file}, {Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file}, }, @@ -205,7 +205,7 @@ func Test_doRun(t *testing.T) { }, &DummyClient{}, }, - []artifact.Artifact{ + []*artifact.Artifact{ {Name: "foo_1.0.1_linux_amd64.tar.gz", Goos: "linux", Goarch: "amd64"}, {Name: "foo_1.0.1_linux_386.tar.gz", Goos: "linux", Goarch: "386"}, }, @@ -239,7 +239,7 @@ func Test_doRun(t *testing.T) { }, &DummyClient{}, }, - []artifact.Artifact{ + []*artifact.Artifact{ {Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"}, {Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"}, }, @@ -282,7 +282,7 @@ func Test_doRun(t *testing.T) { }, &DummyClient{}, }, - []artifact.Artifact{ + []*artifact.Artifact{ {Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file}, {Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file}, }, @@ -321,7 +321,7 @@ func Test_doRun(t *testing.T) { }, &DummyClient{}, }, - []artifact.Artifact{ + []*artifact.Artifact{ {Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file}, {Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file}, }, @@ -360,7 +360,7 @@ func Test_doRun(t *testing.T) { }, &DummyClient{}, }, - []artifact.Artifact{ + []*artifact.Artifact{ {Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"}, {Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"}, }, @@ -403,7 +403,7 @@ func Test_doRun(t *testing.T) { }, &DummyClient{}, }, - []artifact.Artifact{ + []*artifact.Artifact{ {Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file}, {Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file}, }, @@ -513,14 +513,14 @@ func Test_buildManifest(t *testing.T) { var ctx = tt.ctx err := Pipe{}.Default(ctx) require.NoError(t, err) - out, err := buildManifest(ctx, []artifact.Artifact{ + out, err := buildManifest(ctx, []*artifact.Artifact{ { Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file, Extra: map[string]interface{}{ - "Builds": []artifact.Artifact{ + "Builds": []*artifact.Artifact{ { Extra: map[string]interface{}{ "Binary": "foo", @@ -540,7 +540,7 @@ func Test_buildManifest(t *testing.T) { Goarch: "386", Path: file, Extra: map[string]interface{}{ - "Builds": []artifact.Artifact{ + "Builds": []*artifact.Artifact{ { Extra: map[string]interface{}{ "Binary": "foo", diff --git a/internal/pipe/sign/sign.go b/internal/pipe/sign/sign.go index 219cbc4bb..da797529d 100644 --- a/internal/pipe/sign/sign.go +++ b/internal/pipe/sign/sign.go @@ -84,18 +84,18 @@ func (Pipe) Run(ctx *context.Context) error { return g.Wait() } -func sign(ctx *context.Context, cfg config.Sign, artifacts []artifact.Artifact) error { +func sign(ctx *context.Context, cfg config.Sign, artifacts []*artifact.Artifact) error { for _, a := range artifacts { artifact, err := signone(ctx, cfg, a) if err != nil { return err } - ctx.Artifacts.Add(*artifact) + ctx.Artifacts.Add(artifact) } return nil } -func signone(ctx *context.Context, cfg config.Sign, a artifact.Artifact) (*artifact.Artifact, error) { +func signone(ctx *context.Context, cfg config.Sign, a *artifact.Artifact) (*artifact.Artifact, error) { env := ctx.Env env["artifact"] = a.Path env["signature"] = expand(cfg.Signature, env) diff --git a/internal/pipe/sign/sign_test.go b/internal/pipe/sign/sign_test.go index e7fd0d5a3..49047da0e 100644 --- a/internal/pipe/sign/sign_test.go +++ b/internal/pipe/sign/sign_test.go @@ -172,27 +172,27 @@ func testSign(t *testing.T, ctx *context.Context, signaturePaths []string, signa } assert.NoError(t, ioutil.WriteFile(filepath.Join(tmpdir, "linux_amd64", "artifact4"), []byte("foo"), 0644)) artifacts = append(artifacts, "linux_amd64/artifact4") - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "artifact1", Path: filepath.Join(tmpdir, "artifact1"), Type: artifact.UploadableArchive, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "artifact2", Path: filepath.Join(tmpdir, "artifact2"), Type: artifact.UploadableArchive, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "artifact3_1.0.0_linux_amd64", Path: filepath.Join(tmpdir, "artifact3"), Type: artifact.UploadableBinary, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "checksum", Path: filepath.Join(tmpdir, "checksum"), Type: artifact.Checksum, }) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "artifact4_1.0.0_linux_amd64", Path: filepath.Join(tmpdir, "linux_amd64", "artifact4"), Type: artifact.UploadableBinary, diff --git a/internal/pipe/snapcraft/snapcraft.go b/internal/pipe/snapcraft/snapcraft.go index f3f357a35..7c6a436ee 100644 --- a/internal/pipe/snapcraft/snapcraft.go +++ b/internal/pipe/snapcraft/snapcraft.go @@ -149,7 +149,7 @@ func (Pipe) Publish(ctx *context.Context) error { return g.Wait() } -func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries []artifact.Artifact) error { +func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries []*artifact.Artifact) error { var log = log.WithField("arch", arch) folder, err := tmpl.New(ctx). WithArtifact(binaries[0], snap.Replacements). @@ -266,7 +266,7 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [ if !snap.Publish { return nil } - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.PublishableSnapcraft, Name: folder + ".snap", Path: snapFile, @@ -279,7 +279,7 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [ const reviewWaitMsg = `Waiting for previous upload(s) to complete their review process.` -func push(ctx *context.Context, snap artifact.Artifact) error { +func push(ctx *context.Context, snap *artifact.Artifact) error { var log = log.WithField("snap", snap.Name) log.Info("pushing snap") // TODO: customize --release based on snap.Grade? diff --git a/internal/pipe/snapcraft/snapcraft_test.go b/internal/pipe/snapcraft/snapcraft_test.go index 33a359aea..389728f3f 100644 --- a/internal/pipe/snapcraft/snapcraft_test.go +++ b/internal/pipe/snapcraft/snapcraft_test.go @@ -334,7 +334,7 @@ func TestDefault(t *testing.T) { func TestPublish(t *testing.T) { var ctx = context.New(config.Project{}) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Path: "nope.snap", Goarch: "amd64", @@ -375,7 +375,7 @@ func addBinaries(t *testing.T, ctx *context.Context, name, dist, dest string) { var binPath = filepath.Join(dist, folder, name) _, err := os.Create(binPath) assert.NoError(t, err) - ctx.Artifacts.Add(artifact.Artifact{ + ctx.Artifacts.Add(&artifact.Artifact{ Name: dest, Path: binPath, Goarch: goarch, diff --git a/internal/tmpl/tmpl.go b/internal/tmpl/tmpl.go index b23667204..6e0a4b7e8 100644 --- a/internal/tmpl/tmpl.go +++ b/internal/tmpl/tmpl.go @@ -82,7 +82,7 @@ func (t *Template) WithEnv(e map[string]string) *Template { } // WithArtifact populates fields from the artifact and replacements -func (t *Template) WithArtifact(a artifact.Artifact, replacements map[string]string) *Template { +func (t *Template) WithArtifact(a *artifact.Artifact, replacements map[string]string) *Template { var bin = a.Extra[binary] if bin == nil { bin = t.fields[projectName] diff --git a/internal/tmpl/tmpl_test.go b/internal/tmpl/tmpl_test.go index b5a82a53c..64bc3baa4 100644 --- a/internal/tmpl/tmpl_test.go +++ b/internal/tmpl/tmpl_test.go @@ -45,7 +45,7 @@ func TestWithArtifact(t *testing.T) { t.Run(expect, func(tt *testing.T) { tt.Parallel() result, err := New(ctx).WithArtifact( - artifact.Artifact{ + &artifact.Artifact{ Name: "not-this-binary", Goarch: "amd64", Goos: "linux", @@ -64,7 +64,7 @@ func TestWithArtifact(t *testing.T) { t.Run("artifact without binary name", func(tt *testing.T) { tt.Parallel() result, err := New(ctx).WithArtifact( - artifact.Artifact{ + &artifact.Artifact{ Name: "another-binary", Goarch: "amd64", Goos: "linux",