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

73 lines
1.7 KiB
Go
Raw Normal View History

2017-04-14 15:39:32 -03:00
// 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.
2017-01-14 12:34:22 -02:00
package context
2017-02-23 16:01:54 -03:00
import (
ctx "context"
"os"
"strings"
2017-12-29 17:07:06 -02:00
"time"
2017-02-23 16:01:54 -03:00
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/internal/artifact"
2017-02-23 16:01:54 -03:00
)
2017-01-14 12:34:22 -02:00
// GitInfo includes tags and diffs used in some point
type GitInfo struct {
2017-04-19 17:05:10 -03:00
CurrentTag string
Commit string
2017-01-14 12:34:22 -02:00
}
2017-01-15 08:48:27 -02:00
// Context carries along some data through the pipes
2017-01-14 12:34:22 -02:00
type Context struct {
2017-02-23 16:01:54 -03:00
ctx.Context
2017-04-19 17:05:10 -03:00
Config config.Project
Env map[string]string
2017-04-19 17:05:10 -03:00
Token string
Git GitInfo
Artifacts artifact.Artifacts
2017-04-19 17:05:10 -03:00
ReleaseNotes string
Version string
2017-04-29 12:49:22 +02:00
Snapshot bool
SkipPublish bool
2018-03-08 08:42:33 -03:00
SkipValidate bool
2017-07-04 22:53:50 -03:00
RmDist bool
Debug bool
2017-07-15 16:49:52 -03:00
Parallelism int
}
2017-01-15 08:48:27 -02:00
// New context
func New(config config.Project) *Context {
2018-01-21 20:07:18 -02:00
return Wrap(ctx.Background(), config)
2017-12-29 17:07:06 -02:00
}
// 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)
2018-01-21 20:07:18 -02:00
return Wrap(ctx, config), cancel
2017-12-29 17:07:06 -02:00
}
2018-01-21 20:07:18 -02:00
// Wrap wraps an existing context
func Wrap(ctx ctx.Context, config config.Project) *Context {
2017-01-14 12:34:22 -02:00
return &Context{
2017-12-29 17:07:06 -02:00
Context: ctx,
2017-07-15 16:49:52 -03:00
Config: config,
Env: splitEnv(os.Environ()),
2017-07-15 16:49:52 -03:00
Parallelism: 4,
2017-12-17 17:25:04 -02:00
Artifacts: artifact.New(),
2017-01-14 12:34:22 -02:00
}
}
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
}