From 454abc9a0a722591afdd0f6a9e1c7cc7134d101b Mon Sep 17 00:00:00 2001 From: Jorin Vogel Date: Mon, 5 Jun 2017 16:38:59 +0200 Subject: [PATCH] Add option to skip archive. See #243. Upload binaries directly instead of creating archive. This option, however currently doesn't work together with brew and fpm since they both require archived artifacts. --- README.md | 6 +++++ config/config.go | 1 + pipeline/archive/archive.go | 10 +++++++++ pipeline/archive/archive_test.go | 38 ++++++++++++++++++++++++++++++++ pipeline/brew/brew.go | 4 ++++ pipeline/build/build.go | 3 +++ pipeline/fpm/fpm.go | 4 ++++ 7 files changed, 66 insertions(+) diff --git a/README.md b/README.md index 7898a60b4..e4ff897d0 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,12 @@ build: ```yml # goreleaser.yml archive: + # If set, no archives are created and the binaries are instead uploaded directly. + # In that case name_template is used to name the binary + # and the below specified files are ignored. + # Default is false + skip: true + # You can change the name of the archive. # This is parsed with Golang template engine and the following variables # are available: diff --git a/config/config.go b/config/config.go index 1db76a004..baf9af937 100644 --- a/config/config.go +++ b/config/config.go @@ -67,6 +67,7 @@ type FormatOverride struct { // Archive config used for the archive type Archive struct { + Skip bool `yaml:",omitempty"` Format string `yaml:",omitempty"` FormatOverrides []FormatOverride `yaml:"format_overrides,omitempty"` NameTemplate string `yaml:"name_template,omitempty"` diff --git a/pipeline/archive/archive.go b/pipeline/archive/archive.go index 6cdc5234d..cc78814db 100644 --- a/pipeline/archive/archive.go +++ b/pipeline/archive/archive.go @@ -32,6 +32,9 @@ func (Pipe) Run(ctx *context.Context) error { archive := archive platform := platform g.Go(func() error { + if ctx.Config.Archive.Skip { + return skip(ctx, platform, archive) + } return create(ctx, platform, archive) }) } @@ -73,6 +76,13 @@ func create(ctx *context.Context, platform, name string) error { return nil } +func skip(ctx *context.Context, platform, name string) error { + log.Println("Skip archiving") + var binary = filepath.Join(ctx.Config.Dist, name+ext.For(platform)) + ctx.AddArtifact(binary) + return nil +} + func findFiles(ctx *context.Context) (result []string, err error) { for _, glob := range ctx.Config.Archive.Files { files, err := zglob.Glob(glob) diff --git a/pipeline/archive/archive_test.go b/pipeline/archive/archive_test.go index fc4797ab2..de3c273be 100644 --- a/pipeline/archive/archive_test.go +++ b/pipeline/archive/archive_test.go @@ -65,6 +65,44 @@ func TestRunPipe(t *testing.T) { } } +func TestRunPipeSkip(t *testing.T) { + var assert = assert.New(t) + folder, err := ioutil.TempDir("", "archivetest") + assert.NoError(err) + current, err := os.Getwd() + assert.NoError(err) + assert.NoError(os.Chdir(folder)) + defer func() { + assert.NoError(os.Chdir(current)) + }() + var dist = filepath.Join(folder, "dist") + assert.NoError(os.Mkdir(dist, 0755)) + assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755)) + _, err = os.Create(filepath.Join(dist, "mybin", "mybin")) + assert.NoError(err) + _, err = os.Create(filepath.Join(dist, "mybin", "mybin.exe")) + assert.NoError(err) + _, err = os.Create(filepath.Join(folder, "README.md")) + assert.NoError(err) + var ctx = &context.Context{ + Archives: map[string]string{ + "darwinamd64": "mybin", + "windowsamd64": "mybin", + }, + Config: config.Project{ + Dist: dist, + Build: config.Build{ + Binary: "mybin", + }, + Archive: config.Archive{ + Skip: true, + }, + }, + } + assert.NoError(Pipe{}.Run(ctx)) + assert.Equal([]string{"mybin.exe", "mybin"}, ctx.Artifacts) +} + func TestRunPipeDistRemoved(t *testing.T) { var assert = assert.New(t) var ctx = &context.Context{ diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index e6947cdd4..b9858b2db 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -106,6 +106,10 @@ func doRun(ctx *context.Context, client client.Client) error { log.Println("Skipped because release is marked as draft") return nil } + if ctx.Config.Archive.Skip { + log.Println("Skipped because archiving is skipped") + return nil + } path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb") log.Println("Pushing", path, "to", ctx.Config.Brew.GitHub.String()) content, err := buildFormula(ctx, client) diff --git a/pipeline/build/build.go b/pipeline/build/build.go index b1c50622e..c57806d25 100644 --- a/pipeline/build/build.go +++ b/pipeline/build/build.go @@ -67,6 +67,9 @@ func build(ctx *context.Context, name string, target buildTarget) error { name, ctx.Config.Build.Binary+ext.For(target.goos), ) + if ctx.Config.Archive.Skip { + output = filepath.Join(ctx.Config.Dist, name+ext.For(target.goos)) + } log.Println("Building", output) cmd := []string{"go", "build"} if ctx.Config.Build.Flags != "" { diff --git a/pipeline/fpm/fpm.go b/pipeline/fpm/fpm.go index 70bdebbac..cd0ce8fc5 100644 --- a/pipeline/fpm/fpm.go +++ b/pipeline/fpm/fpm.go @@ -33,6 +33,10 @@ func (Pipe) Run(ctx *context.Context) error { log.Println("No output formats configured, skipping") return nil } + if ctx.Config.Archive.Skip { + log.Println("Skipped because archiving is skipped") + return nil + } _, err := exec.LookPath("fpm") if err != nil { return ErrNoFPM