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

Merge branch 'master' into ldflags

This commit is contained in:
Carlos Alexandro Becker 2017-03-25 21:35:17 -03:00 committed by GitHub
commit ec57004312
9 changed files with 64 additions and 7 deletions

View File

@ -7,11 +7,11 @@ setup: ## Install all the build and lint dependencies
go get -u github.com/golang/dep/...
go get -u github.com/pierrre/gotestcover
go get -u golang.org/x/tools/cmd/cover
dep ensure
dep ensure
gometalinter --install
test: ## Run all the tests
gotestcover $(TEST_OPTIONS) -coverprofile=coverage.out $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=30s
gotestcover $(TEST_OPTIONS) -covermode=count -coverprofile=coverage.out $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=30s
fmt: ## gofmt and goimports all go files
find . -name '*.go' -not -wholename './vendor/*' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done

View File

@ -75,6 +75,9 @@ type Project struct {
Build Build
Archive Archive
FPM FPM `yaml:"fpm"`
// test only property indicating the path to the dist folder
Dist string `yaml:"-"`
}
// Load config file

View File

@ -39,7 +39,7 @@ type Archive interface {
}
func create(name string, ctx *context.Context) error {
folder := filepath.Join("dist", name)
folder := filepath.Join(ctx.Config.Dist, name)
file, err := os.Create(folder + "." + ctx.Config.Archive.Format)
log.Println("Creating", file.Name())
if err != nil {

View File

@ -186,7 +186,12 @@ func dataFor(
if file == "" {
return result, ErrNoDarwin64Build
}
sum, err := sha256sum.For("dist/" + file + "." + ctx.Config.Archive.Format)
sum, err := sha256sum.For(
filepath.Join(
ctx.Config.Dist,
file+"."+ctx.Config.Archive.Format,
),
)
if err != nil {
return
}

View File

@ -5,6 +5,7 @@ import (
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
@ -61,7 +62,11 @@ func (Pipe) Run(ctx *context.Context) error {
}
func build(name, goos, goarch string, ctx *context.Context) error {
output := "dist/" + name + "/" + ctx.Config.Build.Binary + extFor(goos)
output := filepath.Join(
ctx.Config.Dist,
name,
ctx.Config.Build.Binary+extFor(goos),
)
log.Println("Building", output)
cmd := []string{"go", "build"}
if ctx.Config.Build.Flags != "" {

View File

@ -1,6 +1,9 @@
package build
import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
@ -34,3 +37,43 @@ func TestBuild(t *testing.T) {
}
assert.NoError(build("build_test", runtime.GOOS, runtime.GOARCH, ctx))
}
func TestRunFullPipe(t *testing.T) {
assert := assert.New(t)
folder, err := ioutil.TempDir("", "gorelasertest")
assert.NoError(err)
var binary = filepath.Join(folder, "testing")
var pre = filepath.Join(folder, "pre")
var post = filepath.Join(folder, "post")
var config = config.Project{
Dist: folder,
Build: config.Build{
Binary: "testing",
Flags: "-v",
Ldflags: "-X main.test=testing",
Hooks: config.Hooks{
Pre: "touch " + pre,
Post: "touch " + post,
},
Goos: []string{
runtime.GOOS,
},
Goarch: []string{
runtime.GOARCH,
},
},
}
var ctx = &context.Context{
Config: config,
Archives: map[string]string{},
}
assert.NoError(Pipe{}.Run(ctx))
assert.True(exists(binary), binary)
assert.True(exists(pre), pre)
assert.True(exists(post), post)
}
func exists(file string) bool {
_, err := os.Stat(file)
return !os.IsNotExist(err)
}

View File

@ -82,6 +82,7 @@ func (Pipe) Run(ctx *context.Context) error {
if ctx.Config.Brew.Install == "" {
ctx.Config.Brew.Install = "bin.install \"" + ctx.Config.Build.Binary + "\""
}
ctx.Config.Dist = "dist"
return nil
}

View File

@ -54,7 +54,7 @@ func (Pipe) Run(ctx *context.Context) error {
}
func create(ctx *context.Context, format, archive, arch string) error {
var path = filepath.Join("dist", archive)
var path = filepath.Join(ctx.Config.Dist, archive)
var file = path + ".deb"
var name = ctx.Config.Build.Binary
log.Println("Creating", file)

View File

@ -89,7 +89,7 @@ func description(diff string) string {
func upload(ctx *context.Context, client *github.Client, releaseID int, archive, format string) error {
archive = archive + "." + format
var path = filepath.Join("dist", archive)
var path = filepath.Join(ctx.Config.Dist, archive)
// In case the file doesn't exist, we just ignore it.
// We do this because we can get invalid combinations of archive+format here,
// like darwinamd64 + deb or something like that.