Skip to content

Commit

Permalink
feat: remove singular archive config (#1282)
Browse files Browse the repository at this point in the history
* feat: remove singular archive config

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

* fix: tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Dec 29, 2019
1 parent 468401b commit 8defb77
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 51 deletions.
6 changes: 3 additions & 3 deletions internal/http/http.go
Expand Up @@ -372,9 +372,9 @@ func resolveTargetTemplate(ctx *context.Context, upload *config.Upload, artifact

if upload.Mode == ModeBinary {
// TODO: multiple archives here
data.Os = replace(ctx.Config.Archive.Replacements, artifact.Goos)
data.Arch = replace(ctx.Config.Archive.Replacements, artifact.Goarch)
data.Arm = replace(ctx.Config.Archive.Replacements, artifact.Goarm)
data.Os = replace(ctx.Config.Archives[0].Replacements, artifact.Goos)
data.Arch = replace(ctx.Config.Archives[0].Replacements, artifact.Goarch)
data.Arm = replace(ctx.Config.Archives[0].Replacements, artifact.Goarm)
}

var out bytes.Buffer
Expand Down
7 changes: 6 additions & 1 deletion internal/http/http_test.go
Expand Up @@ -205,7 +205,12 @@ func TestUpload(t *testing.T) {
}
return errors.Errorf("unexpected http status code: %v", r.StatusCode)
}
ctx := context.New(config.Project{ProjectName: "blah"})
ctx := context.New(config.Project{
ProjectName: "blah",
Archives: []config.Archive{
{},
},
})
ctx.Env["TEST_A_SECRET"] = "x"
ctx.Env["TEST_A_USERNAME"] = "u2"
ctx.Version = "2.1.0"
Expand Down
10 changes: 3 additions & 7 deletions internal/pipe/archive/archive.go
Expand Up @@ -7,22 +7,21 @@ import (
"fmt"
"os"
"path/filepath"
"reflect"
"strings"
"sync"

"github.com/apex/log"
"github.com/campoy/unique"
"github.com/mattn/go-zglob"

"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/deprecate"
"github.com/goreleaser/goreleaser/internal/ids"
"github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/archive"
archivelib "github.com/goreleaser/goreleaser/pkg/archive"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
zglob "github.com/mattn/go-zglob"
)

const (
Expand All @@ -44,10 +43,7 @@ func (Pipe) String() string {
func (Pipe) Default(ctx *context.Context) error {
var ids = ids.New("archives")
if len(ctx.Config.Archives) == 0 {
ctx.Config.Archives = append(ctx.Config.Archives, ctx.Config.Archive)
if !reflect.DeepEqual(ctx.Config.Archive, config.Archive{}) {
deprecate.Notice("archive")
}
ctx.Config.Archives = append(ctx.Config.Archives, config.Archive{})
}
for i := range ctx.Config.Archives {
var archive = &ctx.Config.Archives[i]
Expand Down
30 changes: 30 additions & 0 deletions internal/pipe/artifactory/artifactory_test.go
Expand Up @@ -188,6 +188,9 @@ func TestRunPipe_ModeBinary(t *testing.T) {
Username: "productionuser",
},
},
Archives: []config.Archive{
{},
},
})
ctx.Env = map[string]string{
"ARTIFACTORY_PRODUCTION-US_SECRET": "deployuser-secret",
Expand Down Expand Up @@ -229,6 +232,9 @@ func TestRunPipe_ModeArchive(t *testing.T) {
Username: "deployuser",
},
},
Archives: []config.Archive{
{},
},
})
ctx.Env = map[string]string{
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
Expand Down Expand Up @@ -361,6 +367,9 @@ func TestRunPipe_TargetTemplateError(t *testing.T) {
Username: "deployuser",
},
},
Archives: []config.Archive{
{},
},
})
ctx.Env = map[string]string{
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
Expand Down Expand Up @@ -418,6 +427,9 @@ func TestRunPipe_BadCredentials(t *testing.T) {
Username: "deployuser",
},
},
Archives: []config.Archive{
{},
},
})
ctx.Env = map[string]string{
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
Expand Down Expand Up @@ -476,6 +488,9 @@ func TestRunPipe_UnparsableErrorResponse(t *testing.T) {
Username: "deployuser",
},
},
Archives: []config.Archive{
{},
},
})
ctx.Env = map[string]string{
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
Expand Down Expand Up @@ -531,6 +546,9 @@ func TestRunPipe_UnparsableResponse(t *testing.T) {
Username: "deployuser",
},
},
Archives: []config.Archive{
{},
},
})
ctx.Env = map[string]string{
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
Expand Down Expand Up @@ -559,6 +577,9 @@ func TestRunPipe_FileNotFound(t *testing.T) {
Username: "deployuser",
},
},
Archives: []config.Archive{
{},
},
})
ctx.Env = map[string]string{
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
Expand Down Expand Up @@ -597,6 +618,9 @@ func TestRunPipe_UnparsableTarget(t *testing.T) {
Username: "deployuser",
},
},
Archives: []config.Archive{
{},
},
})
ctx.Env = map[string]string{
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
Expand All @@ -623,6 +647,9 @@ func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
Username: "deployuser",
},
},
Archives: []config.Archive{
{},
},
})
ctx.Env = map[string]string{
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
Expand Down Expand Up @@ -654,6 +681,9 @@ func TestRunPipe_DirUpload(t *testing.T) {
Username: "deployuser",
},
},
Archives: []config.Archive{
{},
},
})
ctx.Env = map[string]string{
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
Expand Down
10 changes: 6 additions & 4 deletions internal/pipe/defaults/defaults_test.go
Expand Up @@ -63,9 +63,11 @@ func TestFillPartial(t *testing.T) {
Name: "test",
},
},
Archive: config.Archive{
Files: []string{
"glob/*",
Archives: []config.Archive{
{
Files: []string{
"glob/*",
},
},
},
Builds: []config.Build{
Expand All @@ -90,7 +92,7 @@ func TestFillPartial(t *testing.T) {
},
}
assert.NoError(t, Pipe{}.Run(ctx))
assert.Len(t, ctx.Config.Archive.Files, 1)
assert.Len(t, ctx.Config.Archives[0].Files, 1)
assert.Equal(t, `bin.install "testreleaser"`, ctx.Config.Brews[0].Install)
assert.NotEmpty(t, ctx.Config.Dockers[0].Binaries)
assert.NotEmpty(t, ctx.Config.Dockers[0].Goos)
Expand Down
3 changes: 2 additions & 1 deletion internal/pipe/scoop/scoop.go
Expand Up @@ -61,7 +61,8 @@ func doRun(ctx *context.Context, client client.Client) error {
// if ctx.Config.Release.Disable {
// }

if ctx.Config.Archive.Format == "binary" {
// TODO: multiple archives
if ctx.Config.Archives[0].Format == "binary" {
return pipe.Skip("archive format is binary")
}

Expand Down
56 changes: 28 additions & 28 deletions internal/pipe/scoop/scoop_test.go
Expand Up @@ -101,8 +101,8 @@ func Test_doRun(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Expand Down Expand Up @@ -145,8 +145,8 @@ func Test_doRun(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Expand Down Expand Up @@ -188,8 +188,8 @@ func Test_doRun(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitLab: config.Repo{
Expand Down Expand Up @@ -248,8 +248,8 @@ func Test_doRun(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Expand Down Expand Up @@ -306,8 +306,8 @@ func Test_doRun(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Expand Down Expand Up @@ -349,8 +349,8 @@ func Test_doRun(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Expand Down Expand Up @@ -392,8 +392,8 @@ func Test_doRun(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Expand Down Expand Up @@ -427,8 +427,8 @@ func Test_doRun(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Expand Down Expand Up @@ -471,8 +471,8 @@ func Test_doRun(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
Draft: true,
Expand Down Expand Up @@ -511,8 +511,8 @@ func Test_doRun(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
Disable: true,
Expand Down Expand Up @@ -551,8 +551,8 @@ func Test_doRun(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "binary",
Archives: []config.Archive{
{Format: "binary"},
},
Release: config.Release{
Draft: true,
Expand Down Expand Up @@ -613,8 +613,8 @@ func Test_buildManifest(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Expand Down Expand Up @@ -652,8 +652,8 @@ func Test_buildManifest(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Expand Down Expand Up @@ -692,8 +692,8 @@ func Test_buildManifest(t *testing.T) {
},
Dist: ".",
ProjectName: "run-pipe",
Archive: config.Archive{
Format: "tar.gz",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Expand Down

0 comments on commit 8defb77

Please sign in to comment.