2017-04-14 20:39:32 +02: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 16:34:22 +02:00
|
|
|
package context
|
|
|
|
|
2017-02-23 21:01:54 +02:00
|
|
|
import (
|
|
|
|
ctx "context"
|
2017-12-06 01:01:47 +02:00
|
|
|
"os"
|
2017-04-14 17:07:40 +02:00
|
|
|
"strings"
|
2017-12-29 21:07:06 +02:00
|
|
|
"time"
|
2017-02-23 21:01:54 +02:00
|
|
|
|
2017-12-17 19:18:46 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
2018-08-15 04:50:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
2017-02-23 21:01:54 +02:00
|
|
|
)
|
2017-01-14 16:34:22 +02:00
|
|
|
|
|
|
|
// GitInfo includes tags and diffs used in some point
|
|
|
|
type GitInfo struct {
|
2018-10-03 22:44:31 +02:00
|
|
|
CurrentTag string
|
|
|
|
Commit string
|
|
|
|
ShortCommit string
|
|
|
|
FullCommit string
|
2018-10-04 14:38:19 +02:00
|
|
|
URL string
|
2017-01-14 16:34:22 +02:00
|
|
|
}
|
|
|
|
|
2019-04-09 14:15:05 +02:00
|
|
|
// Env is the environment variables
|
|
|
|
type Env map[string]string
|
|
|
|
|
|
|
|
// Strings returns the current environment as a list of strings, suitable for
|
|
|
|
// os executions.
|
|
|
|
func (e Env) Strings() []string {
|
|
|
|
var result = make([]string, 0, len(e))
|
|
|
|
for k, v := range e {
|
|
|
|
result = append(result, k+"="+v)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2019-06-29 16:02:40 +02:00
|
|
|
// tokenType is either github or gitlab
|
|
|
|
type tokenType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// TokenTypeGitHub defines github as type of the token
|
|
|
|
TokenTypeGitHub tokenType = "github"
|
|
|
|
// TokenTypeGitLab defines gitlab as type of the token
|
|
|
|
TokenTypeGitLab tokenType = "gitlab"
|
|
|
|
)
|
|
|
|
|
2017-01-15 12:48:27 +02:00
|
|
|
// Context carries along some data through the pipes
|
2017-01-14 16:34:22 +02:00
|
|
|
type Context struct {
|
2017-02-23 21:01:54 +02:00
|
|
|
ctx.Context
|
2017-04-19 22:05:10 +02:00
|
|
|
Config config.Project
|
2019-04-09 14:15:05 +02:00
|
|
|
Env Env
|
2017-04-19 22:05:10 +02:00
|
|
|
Token string
|
2019-06-29 16:02:40 +02:00
|
|
|
TokenType tokenType
|
2017-04-19 22:05:10 +02:00
|
|
|
Git GitInfo
|
2017-12-17 19:18:46 +02:00
|
|
|
Artifacts artifact.Artifacts
|
2017-04-19 22:05:10 +02:00
|
|
|
ReleaseNotes string
|
|
|
|
Version string
|
2017-04-29 12:49:22 +02:00
|
|
|
Snapshot bool
|
2018-03-01 06:12:58 +02:00
|
|
|
SkipPublish bool
|
2018-05-24 10:50:14 +02:00
|
|
|
SkipSign bool
|
2018-03-08 13:42:33 +02:00
|
|
|
SkipValidate bool
|
2017-07-05 03:53:50 +02:00
|
|
|
RmDist bool
|
2018-11-29 20:42:14 +02:00
|
|
|
PreRelease bool
|
2017-07-15 21:49:52 +02:00
|
|
|
Parallelism int
|
2019-01-19 20:57:58 +02:00
|
|
|
Semver Semver
|
|
|
|
}
|
|
|
|
|
|
|
|
// Semver represents a semantic version
|
|
|
|
type Semver struct {
|
|
|
|
Major int64
|
|
|
|
Minor int64
|
|
|
|
Patch int64
|
|
|
|
Prerelease string
|
2017-04-14 17:07:40 +02:00
|
|
|
}
|
|
|
|
|
2017-01-15 12:48:27 +02:00
|
|
|
// New context
|
2017-01-15 18:37:00 +02:00
|
|
|
func New(config config.Project) *Context {
|
2018-01-22 00:07:18 +02:00
|
|
|
return Wrap(ctx.Background(), config)
|
2017-12-29 21: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-22 00:07:18 +02:00
|
|
|
return Wrap(ctx, config), cancel
|
2017-12-29 21:07:06 +02:00
|
|
|
}
|
|
|
|
|
2018-01-22 00:07:18 +02:00
|
|
|
// Wrap wraps an existing context
|
|
|
|
func Wrap(ctx ctx.Context, config config.Project) *Context {
|
2017-01-14 16:34:22 +02:00
|
|
|
return &Context{
|
2017-12-29 21:07:06 +02:00
|
|
|
Context: ctx,
|
2017-07-15 21:49:52 +02:00
|
|
|
Config: config,
|
2019-03-03 19:12:22 +02:00
|
|
|
Env: splitEnv(append(os.Environ(), config.Env...)),
|
2017-07-15 21:49:52 +02:00
|
|
|
Parallelism: 4,
|
2017-12-17 21:25:04 +02:00
|
|
|
Artifacts: artifact.New(),
|
2017-01-14 16:34:22 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-06 01:01:47 +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
|
|
|
|
}
|