-
-
Notifications
You must be signed in to change notification settings - Fork 911
/
context.go
85 lines (76 loc) · 1.92 KB
/
context.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Package context provides gorelease context which is passed through the
// pipeline.
//
// The context extends the standard library context and add a few more
// fields and other things, so pipes can gather data provided by previous
// pipes without really knowing each other.
package context
import (
ctx "context"
"os"
"strings"
"time"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/pkg/config"
)
// GitInfo includes tags and diffs used in some point
type GitInfo struct {
CurrentTag string
Commit string
ShortCommit string
FullCommit string
URL string
}
// Context carries along some data through the pipes
type Context struct {
ctx.Context
Config config.Project
Env map[string]string
Token string
Git GitInfo
Artifacts artifact.Artifacts
ReleaseNotes string
Version string
Snapshot bool
SkipPublish bool
SkipSign bool
SkipValidate bool
RmDist bool
PreRelease bool
Parallelism int
Semver Semver
}
// Semver represents a semantic version
type Semver struct {
Major int64
Minor int64
Patch int64
Prerelease string
}
// New context
func New(config config.Project) *Context {
return Wrap(ctx.Background(), config)
}
// NewWithTimeout new context with the given timeout
func NewWithTimeout(config config.Project, timeout time.Duration) (*Context, ctx.CancelFunc) {
ctx, cancel := ctx.WithTimeout(ctx.Background(), timeout)
return Wrap(ctx, config), cancel
}
// Wrap wraps an existing context
func Wrap(ctx ctx.Context, config config.Project) *Context {
return &Context{
Context: ctx,
Config: config,
Env: splitEnv(append(os.Environ(), config.Env...)),
Parallelism: 4,
Artifacts: artifact.New(),
}
}
func splitEnv(env []string) map[string]string {
r := map[string]string{}
for _, e := range env {
p := strings.SplitN(e, "=", 2)
r[p[0]] = p[1]
}
return r
}