github.com/axxelG/goreleaser@v0.92.0/pkg/context/context.go (about) 1 // Package context provides gorelease context which is passed through the 2 // pipeline. 3 // 4 // The context extends the standard library context and add a few more 5 // fields and other things, so pipes can gather data provided by previous 6 // pipes without really knowing each other. 7 package context 8 9 import ( 10 ctx "context" 11 "os" 12 "strings" 13 "time" 14 15 "github.com/goreleaser/goreleaser/internal/artifact" 16 "github.com/goreleaser/goreleaser/pkg/config" 17 ) 18 19 // GitInfo includes tags and diffs used in some point 20 type GitInfo struct { 21 CurrentTag string 22 Commit string 23 ShortCommit string 24 FullCommit string 25 URL string 26 } 27 28 // Context carries along some data through the pipes 29 type Context struct { 30 ctx.Context 31 Config config.Project 32 Env map[string]string 33 Token string 34 Git GitInfo 35 Artifacts artifact.Artifacts 36 ReleaseNotes string 37 Version string 38 Snapshot bool 39 SkipPublish bool 40 SkipSign bool 41 SkipValidate bool 42 RmDist bool 43 Debug bool 44 Parallelism int 45 } 46 47 // New context 48 func New(config config.Project) *Context { 49 return Wrap(ctx.Background(), config) 50 } 51 52 // NewWithTimeout new context with the given timeout 53 func NewWithTimeout(config config.Project, timeout time.Duration) (*Context, ctx.CancelFunc) { 54 ctx, cancel := ctx.WithTimeout(ctx.Background(), timeout) 55 return Wrap(ctx, config), cancel 56 } 57 58 // Wrap wraps an existing context 59 func Wrap(ctx ctx.Context, config config.Project) *Context { 60 return &Context{ 61 Context: ctx, 62 Config: config, 63 Env: splitEnv(os.Environ()), 64 Parallelism: 4, 65 Artifacts: artifact.New(), 66 } 67 } 68 69 func splitEnv(env []string) map[string]string { 70 r := map[string]string{} 71 for _, e := range env { 72 p := strings.SplitN(e, "=", 2) 73 r[p[0]] = p[1] 74 } 75 return r 76 }