This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpublish.go
More file actions
52 lines (46 loc) · 1.26 KB
/
publish.go
File metadata and controls
52 lines (46 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package magetasks
import (
"context"
"errors"
"fmt"
"github.com/magefile/mage/mg"
"github.com/wavesoftware/go-magetasks/config"
"github.com/wavesoftware/go-magetasks/pkg/artifact"
"github.com/wavesoftware/go-magetasks/pkg/tasks"
)
// ErrNoPublisherForArtifact when no publisher for artifact is found.
var ErrNoPublisherForArtifact = errors.New("no publisher for artifact found")
// Publish will publish built artifacts to remote site.
func Publish(ctx context.Context) {
mg.CtxDeps(ctx, Build)
artifacts := config.Actual().Artifacts
t := tasks.Start("📤", "Publishing", len(artifacts) > 0)
for _, art := range artifacts {
p := t.Part(fmt.Sprintf("%s %s", art.GetType(), art.GetName()))
pp := p.Starting()
publishArtifact(art, pp)
}
t.End()
}
func publishArtifact(art config.Artifact, pp tasks.PartProcessing) {
found := false
for _, publisher := range config.Actual().Publishers {
if !publisher.Accepts(art) {
continue
}
found = true
result := publisher.Publish(art, pp)
if result.Failed() {
pp.Done(result.Error)
return
}
config.WithContext(func(ctx context.Context) context.Context {
return context.WithValue(ctx, artifact.PublishKey(art), result)
})
}
var err error
if !found {
err = ErrNoPublisherForArtifact
}
pp.Done(err)
}