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-04-14 17:07:40 +02:00
|
|
|
"strings"
|
|
|
|
"sync"
|
2017-02-23 21:01:54 +02:00
|
|
|
|
2017-06-22 05:09:14 +02:00
|
|
|
"github.com/apex/log"
|
2017-02-23 21:01:54 +02:00
|
|
|
"github.com/goreleaser/goreleaser/config"
|
|
|
|
)
|
2017-01-14 16:34:22 +02:00
|
|
|
|
|
|
|
// GitInfo includes tags and diffs used in some point
|
|
|
|
type GitInfo struct {
|
2017-04-19 22:05:10 +02:00
|
|
|
CurrentTag string
|
|
|
|
Commit string
|
2017-01-14 16:34:22 +02:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:46:48 +02:00
|
|
|
// Binary with pretty name and path
|
|
|
|
type Binary struct {
|
|
|
|
Name, Path string
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
Token string
|
|
|
|
Git GitInfo
|
2017-07-14 00:46:48 +02:00
|
|
|
Binaries map[string]map[string][]Binary
|
2017-04-19 22:05:10 +02:00
|
|
|
Artifacts []string
|
|
|
|
ReleaseNotes string
|
|
|
|
Version string
|
|
|
|
Validate bool
|
|
|
|
Publish bool
|
2017-04-29 12:49:22 +02:00
|
|
|
Snapshot bool
|
2017-07-05 03:53:50 +02:00
|
|
|
RmDist bool
|
2017-04-14 17:07:40 +02:00
|
|
|
}
|
|
|
|
|
2017-07-01 17:31:12 +02:00
|
|
|
var artifactsLock sync.Mutex
|
2017-07-14 00:46:48 +02:00
|
|
|
var binariesLock sync.Mutex
|
2017-04-14 17:07:40 +02:00
|
|
|
|
|
|
|
// AddArtifact adds a file to upload list
|
|
|
|
func (ctx *Context) AddArtifact(file string) {
|
2017-07-01 17:31:12 +02:00
|
|
|
artifactsLock.Lock()
|
|
|
|
defer artifactsLock.Unlock()
|
2017-07-03 05:57:39 +02:00
|
|
|
file = strings.TrimPrefix(file, ctx.Config.Dist+"/")
|
2017-04-14 17:07:40 +02:00
|
|
|
ctx.Artifacts = append(ctx.Artifacts, file)
|
2017-07-01 17:46:08 +02:00
|
|
|
log.WithField("artifact", file).Info("new artifact")
|
2017-01-14 16:34:22 +02:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:46:48 +02:00
|
|
|
// AddBinary adds a built binary to the current context
|
2017-07-14 03:48:12 +02:00
|
|
|
func (ctx *Context) AddBinary(platform, folder, name, path string) {
|
2017-07-14 00:46:48 +02:00
|
|
|
binariesLock.Lock()
|
|
|
|
defer binariesLock.Unlock()
|
2017-07-14 01:43:12 +02:00
|
|
|
if ctx.Binaries == nil {
|
|
|
|
ctx.Binaries = map[string]map[string][]Binary{}
|
|
|
|
}
|
2017-07-14 03:48:12 +02:00
|
|
|
if ctx.Binaries[platform] == nil {
|
|
|
|
ctx.Binaries[platform] = map[string][]Binary{}
|
2017-07-14 00:46:48 +02:00
|
|
|
}
|
2017-07-14 03:48:12 +02:00
|
|
|
ctx.Binaries[platform][folder] = append(
|
|
|
|
ctx.Binaries[platform][folder],
|
2017-07-14 00:46:48 +02:00
|
|
|
Binary{
|
|
|
|
Name: name,
|
|
|
|
Path: path,
|
|
|
|
},
|
|
|
|
)
|
2017-07-14 03:48:12 +02:00
|
|
|
log.WithField("platform", platform).
|
|
|
|
WithField("folder", folder).
|
2017-07-14 00:46:48 +02:00
|
|
|
WithField("name", name).
|
|
|
|
WithField("path", path).
|
|
|
|
Info("new binary")
|
2017-07-01 17:27:13 +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 {
|
2017-01-14 16:34:22 +02:00
|
|
|
return &Context{
|
2017-07-14 03:50:21 +02:00
|
|
|
Context: ctx.Background(),
|
|
|
|
Config: config,
|
2017-01-14 16:34:22 +02:00
|
|
|
}
|
|
|
|
}
|