Skip to content

Commit

Permalink
feat: store which action is being taken in the context (#4508)
Browse files Browse the repository at this point in the history
refs #4504

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Dec 29, 2023
1 parent 48f036b commit 12469c4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/build.go
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions cmd/build_test.go
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions cmd/release.go
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions cmd/release_test.go
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions pkg/context/context.go
Expand Up @@ -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
Expand Down

0 comments on commit 12469c4

Please sign in to comment.