1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

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.
This commit is contained in:
Jorin Vogel 2017-06-05 16:38:59 +02:00
parent 5b332d2358
commit 454abc9a0a
No known key found for this signature in database
GPG Key ID: 647AFD30D56CE8CC
7 changed files with 66 additions and 0 deletions

View File

@ -250,6 +250,12 @@ build:
```yml ```yml
# goreleaser.yml # goreleaser.yml
archive: 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. # You can change the name of the archive.
# This is parsed with Golang template engine and the following variables # This is parsed with Golang template engine and the following variables
# are available: # are available:

View File

@ -67,6 +67,7 @@ type FormatOverride struct {
// Archive config used for the archive // Archive config used for the archive
type Archive struct { type Archive struct {
Skip bool `yaml:",omitempty"`
Format string `yaml:",omitempty"` Format string `yaml:",omitempty"`
FormatOverrides []FormatOverride `yaml:"format_overrides,omitempty"` FormatOverrides []FormatOverride `yaml:"format_overrides,omitempty"`
NameTemplate string `yaml:"name_template,omitempty"` NameTemplate string `yaml:"name_template,omitempty"`

View File

@ -32,6 +32,9 @@ func (Pipe) Run(ctx *context.Context) error {
archive := archive archive := archive
platform := platform platform := platform
g.Go(func() error { g.Go(func() error {
if ctx.Config.Archive.Skip {
return skip(ctx, platform, archive)
}
return create(ctx, platform, archive) return create(ctx, platform, archive)
}) })
} }
@ -73,6 +76,13 @@ func create(ctx *context.Context, platform, name string) error {
return nil 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) { func findFiles(ctx *context.Context) (result []string, err error) {
for _, glob := range ctx.Config.Archive.Files { for _, glob := range ctx.Config.Archive.Files {
files, err := zglob.Glob(glob) files, err := zglob.Glob(glob)

View File

@ -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) { func TestRunPipeDistRemoved(t *testing.T) {
var assert = assert.New(t) var assert = assert.New(t)
var ctx = &context.Context{ var ctx = &context.Context{

View File

@ -106,6 +106,10 @@ func doRun(ctx *context.Context, client client.Client) error {
log.Println("Skipped because release is marked as draft") log.Println("Skipped because release is marked as draft")
return nil 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") path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb")
log.Println("Pushing", path, "to", ctx.Config.Brew.GitHub.String()) log.Println("Pushing", path, "to", ctx.Config.Brew.GitHub.String())
content, err := buildFormula(ctx, client) content, err := buildFormula(ctx, client)

View File

@ -67,6 +67,9 @@ func build(ctx *context.Context, name string, target buildTarget) error {
name, name,
ctx.Config.Build.Binary+ext.For(target.goos), 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) log.Println("Building", output)
cmd := []string{"go", "build"} cmd := []string{"go", "build"}
if ctx.Config.Build.Flags != "" { if ctx.Config.Build.Flags != "" {

View File

@ -33,6 +33,10 @@ func (Pipe) Run(ctx *context.Context) error {
log.Println("No output formats configured, skipping") log.Println("No output formats configured, skipping")
return nil return nil
} }
if ctx.Config.Archive.Skip {
log.Println("Skipped because archiving is skipped")
return nil
}
_, err := exec.LookPath("fpm") _, err := exec.LookPath("fpm")
if err != nil { if err != nil {
return ErrNoFPM return ErrNoFPM