1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-03 13:11:48 +02:00
goreleaser/context/context.go

57 lines
1.2 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"
"log"
"strings"
"sync"
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 {
CurrentTag string
PreviousTag string
Diff string
2017-03-25 20:24:38 -03:00
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
Config config.Project
Token string
Git GitInfo
Archives map[string]string
Artifacts []string
Version string
}
var lock sync.Mutex
// AddArtifact adds a file to upload list
func (ctx *Context) AddArtifact(file string) {
lock.Lock()
defer lock.Unlock()
file = strings.TrimPrefix(file, ctx.Config.Dist)
file = strings.Replace(file, "/", "", -1)
ctx.Artifacts = append(ctx.Artifacts, file)
log.Println("Registered artifact", file)
2017-01-14 12:34:22 -02: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-02-23 16:01:54 -03:00
Context: ctx.Background(),
2017-01-18 15:08:48 -02:00
Config: config,
2017-01-14 15:08:10 -02:00
Archives: map[string]string{},
2017-01-14 12:34:22 -02:00
}
}