@@ -5,30 +5,35 @@ import (
55 "errors"
66 "fmt"
77
8- "github.com/magefile/mage/mg"
98 "github.com/wavesoftware/go-magetasks/config"
109 "github.com/wavesoftware/go-magetasks/pkg/artifact"
11- "github.com/wavesoftware/go-magetasks/pkg/files "
10+ "github.com/wavesoftware/go-magetasks/pkg/targets "
1211 "github.com/wavesoftware/go-magetasks/pkg/tasks"
1312)
1413
1514// ErrNoBuilderForArtifact when no builder for artifact is found.
1615var ErrNoBuilderForArtifact = errors .New ("no builder for artifact found" )
1716
1817// Build will build project artifacts, binaries and images.
19- func Build () {
20- mg .Deps (Test , files . EnsureBuildDir )
18+ func Build (ctx context. Context ) error {
19+ targets .Deps (ctx , Test )
2120 t := tasks .Start ("🔨" , "Building" , len (config .Actual ().Artifacts ) > 0 )
2221 for _ , art := range config .Actual ().Artifacts {
2322 p := t .Part (fmt .Sprintf ("%s %s" , art .GetType (), art .GetName ()))
2423 pp := p .Starting ()
2524
26- buildArtifact (art , pp )
25+ err := buildArtifact (art , pp )
26+ if err != nil {
27+ t .End (err )
28+ return err
29+ }
2730 }
2831 t .End ()
32+
33+ return nil
2934}
3035
31- func buildArtifact (art config.Artifact , pp tasks.PartProcessing ) {
36+ func buildArtifact (art config.Artifact , pp tasks.PartProcessing ) error {
3237 found := false
3338 for _ , builder := range config .Actual ().Builders {
3439 if ! builder .Accepts (art ) {
@@ -37,8 +42,9 @@ func buildArtifact(art config.Artifact, pp tasks.PartProcessing) {
3742 found = true
3843 result := builder .Build (art , pp )
3944 if result .Failed () {
40- pp .Done (result .Error )
41- return
45+ err := result .Error
46+ pp .Done (err )
47+ return err
4248 }
4349 config .WithContext (func (ctx context.Context ) context.Context {
4450 return context .WithValue (ctx , artifact .BuildKey (art ), result )
@@ -49,4 +55,5 @@ func buildArtifact(art config.Artifact, pp tasks.PartProcessing) {
4955 err = ErrNoBuilderForArtifact
5056 }
5157 pp .Done (err )
58+ return err
5259}
0 commit comments