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

Merge pull request #306 from goreleaser/parallelism-cfg

allow configuring parallelism via flag
This commit is contained in:
Carlos Alexandro Becker 2017-07-16 10:59:59 -03:00 committed by GitHub
commit 7251281990
8 changed files with 98 additions and 111 deletions

View File

@ -40,6 +40,7 @@ type Context struct {
Publish bool
Snapshot bool
RmDist bool
Parallelism int
}
var artifactsLock sync.Mutex
@ -81,7 +82,8 @@ func (ctx *Context) AddBinary(platform, folder, name, path string) {
// New context
func New(config config.Project) *Context {
return &Context{
Context: ctx.Background(),
Config: config,
Context: ctx.Background(),
Config: config,
Parallelism: 4,
}
}

View File

@ -40,6 +40,7 @@ var pipes = []pipeline.Pipe{
type Flags interface {
IsSet(s string) bool
String(s string) string
Int(s string) int
Bool(s string) bool
}
@ -61,6 +62,8 @@ func Release(flags Flags) error {
log.WithField("file", file).Warn("could not load config, using defaults")
}
var ctx = context.New(cfg)
ctx.Parallelism = flags.Int("parallelism")
log.Debugf("parallelism: %v", ctx.Parallelism)
ctx.Validate = !flags.Bool("skip-validate")
ctx.Publish = !flags.Bool("skip-publish")
if notes != "" {

View File

@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"testing"
"github.com/goreleaser/goreleaser/config"
@ -25,6 +26,7 @@ func TestRelease(t *testing.T) {
"skip-publish": "true",
"skip-validate": "true",
"debug": "true",
"parallelism": "4",
},
}
assert.NoError(Release(flags))
@ -36,7 +38,8 @@ func TestSnapshotRelease(t *testing.T) {
defer back()
var flags = fakeFlags{
flags: map[string]string{
"snapshot": "true",
"snapshot": "true",
"parallelism": "4",
},
}
assert.NoError(Release(flags))
@ -89,6 +92,7 @@ func TestCustomReleaseNotesFile(t *testing.T) {
"release-notes": releaseNotes,
"skip-publish": "true",
"skip-validate": "true",
"parallelism": "4",
},
}
assert.NoError(Release(flags))
@ -103,6 +107,7 @@ func TestBrokenPipe(t *testing.T) {
flags: map[string]string{
"skip-publish": "true",
"skip-validate": "true",
"parallelism": "4",
},
}
assert.Error(Release(flags))
@ -150,9 +155,16 @@ type fakeFlags struct {
func (f fakeFlags) IsSet(s string) bool {
return f.flags[s] != ""
}
func (f fakeFlags) String(s string) string {
return f.flags[s]
}
func (f fakeFlags) Int(s string) int {
i, _ := strconv.ParseInt(f.flags[s], 10, 32)
return int(i)
}
func (f fakeFlags) Bool(s string) bool {
return f.flags[s] == "true"
}

View File

@ -51,6 +51,11 @@ func main() {
Name: "rm-dist",
Usage: "Remove ./dist before building",
},
cli.IntFlag{
Name: "parallelism, p",
Usage: "Amount of builds launch in parallel",
Value: 4,
},
cli.BoolFlag{
Name: "debug",
Usage: "Enable debug mode",

View File

@ -41,7 +41,7 @@ func runPipeOnBuild(ctx *context.Context, build config.Build) error {
if err := runHook(build.Env, build.Hooks.Pre); err != nil {
return err
}
sem := make(chan bool, 4)
sem := make(chan bool, ctx.Parallelism)
var g errgroup.Group
for _, target := range buildtarget.All(build) {
sem <- true

View File

@ -38,9 +38,7 @@ func TestBuild(t *testing.T) {
},
},
}
var ctx = &context.Context{
Config: config,
}
var ctx = context.New(config)
assert.NoError(doBuild(ctx, ctx.Config.Builds[0], buildtarget.Runtime))
}
@ -71,10 +69,7 @@ func TestRunFullPipe(t *testing.T) {
},
},
}
var ctx = &context.Context{
Config: config,
}
assert.NoError(Pipe{}.Run(ctx))
assert.NoError(Pipe{}.Run(context.New(config)))
assert.True(exists(binary), binary)
assert.True(exists(pre), pre)
assert.True(exists(post), post)
@ -104,10 +99,7 @@ func TestRunPipeFormatBinary(t *testing.T) {
NameTemplate: "binary-{{.Binary}}",
},
}
var ctx = &context.Context{
Config: config,
}
assert.NoError(Pipe{}.Run(ctx))
assert.NoError(Pipe{}.Run(context.New(config)))
assert.True(exists(binary))
}
@ -136,10 +128,7 @@ func TestRunPipeArmBuilds(t *testing.T) {
},
},
}
var ctx = &context.Context{
Config: config,
}
assert.NoError(Pipe{}.Run(ctx))
assert.NoError(Pipe{}.Run(context.New(config)))
assert.True(exists(binary), binary)
}
@ -158,10 +147,7 @@ func TestBuildFailed(t *testing.T) {
},
},
}
var ctx = &context.Context{
Config: config,
}
assert.Error(Pipe{}.Run(ctx))
assert.Error(Pipe{}.Run(context.New(config)))
}
func TestRunPipeWithInvalidOS(t *testing.T) {
@ -179,49 +165,18 @@ func TestRunPipeWithInvalidOS(t *testing.T) {
},
},
}
var ctx = &context.Context{
Config: config,
}
assert.NoError(Pipe{}.Run(ctx))
assert.NoError(Pipe{}.Run(context.New(config)))
}
func TestRunInvalidNametemplate(t *testing.T) {
var assert = assert.New(t)
for _, format := range []string{"tar.gz", "zip", "binary"} {
var ctx = &context.Context{
Config: config.Project{
ProjectName: "nameeeee",
Builds: []config.Build{
{
Binary: "namet{{.est}",
Flags: "-v",
Goos: []string{
runtime.GOOS,
},
Goarch: []string{
runtime.GOARCH,
},
},
},
Archive: config.Archive{
Format: format,
NameTemplate: "{{.Binary}",
},
},
}
assert.Error(Pipe{}.Run(ctx))
}
}
func TestRunInvalidLdflags(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Config: config.Project{
var config = config.Project{
ProjectName: "nameeeee",
Builds: []config.Build{
{
Binary: "nametest",
Flags: "-v",
Ldflags: "-s -w -X main.version={{.Version}",
Binary: "namet{{.est}",
Flags: "-v",
Goos: []string{
runtime.GOOS,
},
@ -230,9 +185,33 @@ func TestRunInvalidLdflags(t *testing.T) {
},
},
},
Archive: config.Archive{
Format: format,
NameTemplate: "{{.Binary}",
},
}
assert.Error(Pipe{}.Run(context.New(config)))
}
}
func TestRunInvalidLdflags(t *testing.T) {
var assert = assert.New(t)
var config = config.Project{
Builds: []config.Build{
{
Binary: "nametest",
Flags: "-v",
Ldflags: "-s -w -X main.version={{.Version}",
Goos: []string{
runtime.GOOS,
},
Goarch: []string{
runtime.GOARCH,
},
},
},
}
assert.Error(Pipe{}.Run(ctx))
assert.Error(Pipe{}.Run(context.New(config)))
}
func TestRunPipeFailingHooks(t *testing.T) {
@ -250,9 +229,7 @@ func TestRunPipeFailingHooks(t *testing.T) {
},
},
}
var ctx = &context.Context{
Config: config,
}
var ctx = context.New(config)
t.Run("pre-hook", func(t *testing.T) {
ctx.Config.Builds[0].Hooks.Pre = "exit 1"
assert.Error(Pipe{}.Run(ctx))

View File

@ -42,7 +42,7 @@ func doRun(ctx *context.Context, client client.Client) error {
return err
}
var g errgroup.Group
sem := make(chan bool, 4)
sem := make(chan bool, ctx.Parallelism)
for _, artifact := range ctx.Artifacts {
sem <- true
artifact := artifact

View File

@ -25,21 +25,18 @@ func TestRunPipe(t *testing.T) {
assert.NoError(err)
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
assert.NoError(err)
var ctx = &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.0",
},
Config: config.Project{
Dist: folder,
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
var config = config.Project{
Dist: folder,
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Publish: true,
}
var ctx = context.New(config)
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
ctx.Publish = true
ctx.AddArtifact(tarfile.Name())
ctx.AddArtifact(debfile.Name())
client := &DummyClient{}
@ -52,20 +49,17 @@ func TestRunPipe(t *testing.T) {
func TestRunPipeReleaseCreationFailed(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.0",
},
Config: config.Project{
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
var config = config.Project{
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Publish: true,
}
var ctx = context.New(config)
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
ctx.Publish = true
client := &DummyClient{
FailToCreateRelease: true,
}
@ -76,20 +70,17 @@ func TestRunPipeReleaseCreationFailed(t *testing.T) {
func TestRunPipeWithFileThatDontExist(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.0",
},
Config: config.Project{
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
var config = config.Project{
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Publish: true,
}
var ctx = context.New(config)
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
ctx.Publish = true
ctx.AddArtifact("this-file-wont-exist-hopefully")
client := &DummyClient{}
assert.Error(doRun(ctx, client))
@ -103,21 +94,17 @@ func TestRunPipeUploadFailure(t *testing.T) {
assert.NoError(err)
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
assert.NoError(err)
var ctx = &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.0",
},
Config: config.Project{
Dist: folder,
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
var config = config.Project{
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Publish: true,
}
var ctx = context.New(config)
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
ctx.Publish = true
ctx.AddArtifact(tarfile.Name())
client := &DummyClient{
FailToUpload: true,
@ -130,7 +117,8 @@ func TestRunPipeUploadFailure(t *testing.T) {
func TestSkipPublish(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Publish: false,
Publish: false,
Parallelism: 1,
}
client := &DummyClient{}
assert.NoError(doRun(ctx, client))