diff --git a/.semver.yaml b/.semver.yaml index 8f3900a..f551ac4 100644 --- a/.semver.yaml +++ b/.semver.yaml @@ -1,4 +1,4 @@ alpha: 0 beta: 0 rc: 0 -release: v1.1.0 +release: v1.1.1 diff --git a/cmd/affected.go b/cmd/affected.go index 8c5a1ac..8a65ac8 100644 --- a/cmd/affected.go +++ b/cmd/affected.go @@ -3,9 +3,11 @@ package cmd import ( "errors" "fmt" + "os" "slices" "strings" + "github.com/kperreau/goac/pkg/printer" "github.com/kperreau/goac/pkg/project" "github.com/spf13/cobra" ) @@ -39,7 +41,8 @@ var affectedCmd = &cobra.Command{ return err } if err := projectsList.Affected(); err != nil { - return err + printer.Errorf("%s\n", err) + os.Exit(1) } return nil } diff --git a/cmd/version.go b/cmd/version.go index 65f5a22..53c3bd2 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -3,10 +3,10 @@ package cmd import ( "errors" "fmt" - "gopkg.in/yaml.v3" "os" "github.com/spf13/cobra" + "gopkg.in/yaml.v3" ) // versionCmd represents the project command diff --git a/go.mod b/go.mod index a6fb33a..b157d77 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,11 @@ go 1.22 require ( github.com/codeskyblue/dockerignore v0.0.0-20151214070507-de82dee623d9 - github.com/fatih/color v1.16.0 - github.com/spf13/cobra v1.8.0 + github.com/fatih/color v1.17.0 + github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.9.0 - golang.org/x/mod v0.17.0 + golang.org/x/mod v0.18.0 + golang.org/x/sync v0.7.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -19,5 +20,5 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/smartystreets/goconvey v1.8.1 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/sys v0.19.0 // indirect + golang.org/x/sys v0.21.0 // indirect ) diff --git a/go.sum b/go.sum index 4c44a07..9927c66 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,10 @@ github.com/codeskyblue/dockerignore v0.0.0-20151214070507-de82dee623d9 h1:c9axcChJwkLuSl9AvwTHi8jiBa6+VX4gGgERhABgv2E= github.com/codeskyblue/dockerignore v0.0.0-20151214070507-de82dee623d9/go.mod h1:XNZkUhPf+qgRnhY/ecS3B73ODJ2NXCzDMJHXM069IMg= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= -github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= +github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= +github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= @@ -23,18 +23,20 @@ github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGB github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec= github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY= github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60= -github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= -github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= +golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/pkg/project/affected.go b/pkg/project/affected.go index 433ddb3..4e04a17 100644 --- a/pkg/project/affected.go +++ b/pkg/project/affected.go @@ -1,12 +1,13 @@ package project import ( + "fmt" "path" - "sync" "github.com/fatih/color" "github.com/kperreau/goac/pkg/printer" "github.com/kperreau/goac/pkg/utils" + "golang.org/x/sync/errgroup" ) type Target string @@ -19,39 +20,25 @@ const ( func (t Target) String() string { return string(t) } -type processAffectedOptions struct { - wg *sync.WaitGroup - sem chan bool -} - func (l *List) Affected() error { l.printAffected() - // init process options - sem := make(chan bool, l.Options.MaxConcurrency) - wg := sync.WaitGroup{} - pOpts := &processAffectedOptions{ - wg: &wg, - sem: sem, - } - + eg := errgroup.Group{} + eg.SetLimit(l.Options.MaxConcurrency) for _, p := range l.Projects { - sem <- true // acquire - wg.Add(1) - go processAffected(p, pOpts) + eg.Go(func() error { + return processAffected(p) + }) } - wg.Wait() + if err := eg.Wait(); err != nil { + return err + } return nil } -func processAffected(p *Project, opts *processAffectedOptions) { - defer opts.wg.Done() - defer func() { - <-opts.sem // release - }() - +func processAffected(p *Project) error { isAffected := p.isAffected() if isAffected && p.CMDOptions.DryRun { @@ -59,18 +46,18 @@ func processAffected(p *Project, opts *processAffectedOptions) { } if p.CMDOptions.DryRun || !isAffected { - return + return nil } if err := p.build(); err != nil { - printer.Errorf("error building: %s\n", err.Error()) - return + return fmt.Errorf("error building: %s", err.Error()) } if err := p.writeCache(); err != nil { - printer.Errorf("%v\n", err) - return + return err } + + return nil } func (l *List) countAffected() (n int) { diff --git a/pkg/project/affected_test.go b/pkg/project/affected_test.go index d139a96..1e9a1fc 100644 --- a/pkg/project/affected_test.go +++ b/pkg/project/affected_test.go @@ -6,7 +6,6 @@ import ( "io" "log" "os" - "sync" "testing" "github.com/fatih/color" @@ -463,25 +462,14 @@ func TestProcessAffected_BuildAffectedProject(t *testing.T) { }, } - // Create a processAffectedOptions with a wait group and semaphore - opts := &processAffectedOptions{ - wg: &sync.WaitGroup{}, - sem: make(chan bool, 1), - } - - // Add a wait group counter - opts.wg.Add(1) - - // Acquire the semaphore - opts.sem <- true - // Redirect stdout to a buffer old := os.Stdout r, w, _ := os.Pipe() os.Stdout = w // Call the processAffected function - processAffected(p, opts) + err := processAffected(p) + assert.NoError(t, err) // Restore stdout if err := w.Close(); err != nil {