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

101 lines
2.4 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"
2017-08-03 22:01:18 -03:00
"path/filepath"
"strings"
"sync"
2017-02-23 16:01:54 -03:00
2017-06-22 00:09:14 -03:00
"github.com/apex/log"
2017-02-23 16:01:54 -03:00
"github.com/goreleaser/goreleaser/config"
)
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
}
// Binary with pretty name and path
type Binary struct {
Name, Path string
}
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
Token string
Git GitInfo
Binaries map[string]map[string][]Binary
2017-04-19 17:05:10 -03:00
Artifacts []string
Dockers []string
2017-04-19 17:05:10 -03:00
ReleaseNotes string
Version string
Validate bool
Publish bool
2017-04-29 12:49:22 +02:00
Snapshot bool
2017-07-04 22:53:50 -03:00
RmDist bool
2017-07-15 16:49:52 -03:00
Parallelism int
}
2017-07-01 12:31:12 -03:00
var artifactsLock sync.Mutex
var dockersLock sync.Mutex
var binariesLock sync.Mutex
// AddArtifact adds a file to upload list
func (ctx *Context) AddArtifact(file string) {
2017-07-01 12:31:12 -03:00
artifactsLock.Lock()
defer artifactsLock.Unlock()
2017-08-03 22:01:18 -03:00
file = strings.TrimPrefix(file, ctx.Config.Dist+string(filepath.Separator))
ctx.Artifacts = append(ctx.Artifacts, file)
2017-08-20 17:46:30 -03:00
log.WithField("artifact", file).Info("new release artifact")
2017-01-14 12:34:22 -02:00
}
// AddDocker adds a docker image to the docker images list
func (ctx *Context) AddDocker(image string) {
dockersLock.Lock()
defer dockersLock.Unlock()
ctx.Dockers = append(ctx.Dockers, image)
log.WithField("image", image).Info("new docker image")
}
// AddBinary adds a built binary to the current context
2017-07-13 22:48:12 -03:00
func (ctx *Context) AddBinary(platform, folder, name, path string) {
binariesLock.Lock()
defer binariesLock.Unlock()
2017-07-13 20:43:12 -03:00
if ctx.Binaries == nil {
ctx.Binaries = map[string]map[string][]Binary{}
}
2017-07-13 22:48:12 -03:00
if ctx.Binaries[platform] == nil {
ctx.Binaries[platform] = map[string][]Binary{}
}
2017-07-13 22:48:12 -03:00
ctx.Binaries[platform][folder] = append(
ctx.Binaries[platform][folder],
Binary{
Name: name,
Path: path,
},
)
2017-07-13 22:48:12 -03:00
log.WithField("platform", platform).
WithField("folder", folder).
WithField("name", name).
WithField("path", path).
2017-08-20 17:46:30 -03:00
Debug("new binary")
2017-07-01 12:27:13 -03:00
}
2017-01-15 08:48:27 -02:00
// New context
func New(config config.Project) *Context {
2017-01-14 12:34:22 -02:00
return &Context{
2017-07-15 16:49:52 -03:00
Context: ctx.Background(),
Config: config,
Parallelism: 4,
2017-01-14 12:34:22 -02:00
}
}