1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-10-30 23:58:09 +02:00

feat: store which action is being taken in the context (#4508)

refs #4504

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2023-12-29 15:22:03 -03:00
committed by GitHub
parent 48f036b5d6
commit 12469c4251
5 changed files with 21 additions and 0 deletions

View File

@@ -167,6 +167,7 @@ func setupPipeline(ctx *context.Context, options buildOpts) []pipeline.Piper {
}
func setupBuildContext(ctx *context.Context, options buildOpts) error {
ctx.Action = context.ActionBuild
ctx.Deprecated = options.deprecated // test only
ctx.Parallelism = runtime.GOMAXPROCS(0)
if options.parallelism > 0 {

View File

@@ -137,6 +137,11 @@ func TestBuildFlags(t *testing.T) {
return ctx
}
t.Run("action", func(t *testing.T) {
ctx := setup(buildOpts{})
require.Equal(t, context.ActionBuild, ctx.Action)
})
t.Run("snapshot", func(t *testing.T) {
ctx := setup(buildOpts{
snapshot: true,

View File

@@ -171,6 +171,7 @@ func releaseProject(options releaseOpts) (*context.Context, error) {
}
func setupReleaseContext(ctx *context.Context, options releaseOpts) error {
ctx.Action = context.ActionRelease
ctx.Deprecated = options.deprecated // test only
ctx.Parallelism = runtime.GOMAXPROCS(0)
if options.parallelism > 0 {

View File

@@ -62,6 +62,11 @@ func TestReleaseFlags(t *testing.T) {
return ctx
}
t.Run("action", func(t *testing.T) {
ctx := setup(t, releaseOpts{})
require.Equal(t, context.ActionRelease, ctx.Action)
})
t.Run("snapshot", func(t *testing.T) {
ctx := setup(t, releaseOpts{
snapshot: true,

View File

@@ -69,9 +69,18 @@ const (
TokenTypeGitea TokenType = "gitea"
)
type Action uint8
const (
ActionNone Action = iota
ActionBuild
ActionRelease
)
// Context carries along some data through the pipes.
type Context struct {
stdctx.Context
Action Action
Config config.Project
Env Env
Token string