Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add var step to workflows #751

Merged
merged 2 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions server/events/mocks/matchers/map_of_string_to_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions server/events/mocks/mock_custom_step_runner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions server/events/mocks/mock_env_step_runner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions server/events/mocks/mock_step_runner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 21 additions & 6 deletions server/events/project_command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,22 @@ type LockURLGenerator interface {
// `terraform plan`.
type StepRunner interface {
// Run runs the step.
Run(ctx models.ProjectCommandContext, extraArgs []string, path string) (string, error)
Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error)
}

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_custom_step_runner.go CustomStepRunner

// CustomStepRunner runs custom run steps.
type CustomStepRunner interface {
// Run cmd in path.
Run(ctx models.ProjectCommandContext, cmd string, path string) (string, error)
Run(ctx models.ProjectCommandContext, cmd string, path string, envs map[string]string) (string, error)
}

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_env_step_runner.go EnvStepRunner

// EnvStepRunner runs env steps.
type EnvStepRunner interface {
Run(ctx models.ProjectCommandContext, cmd string, value string, path string, envs map[string]string) (string, error)
}

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_webhooks_sender.go WebhooksSender
Expand Down Expand Up @@ -90,6 +97,7 @@ type DefaultProjectCommandRunner struct {
PlanStepRunner StepRunner
ApplyStepRunner StepRunner
RunStepRunner CustomStepRunner
EnvStepRunner EnvStepRunner
PullApprovedChecker runtime.PullApprovedChecker
WorkingDir WorkingDir
Webhooks WebhooksSender
Expand Down Expand Up @@ -173,18 +181,25 @@ func (p *DefaultProjectCommandRunner) doPlan(ctx models.ProjectCommandContext) (

func (p *DefaultProjectCommandRunner) runSteps(steps []valid.Step, ctx models.ProjectCommandContext, absPath string) ([]string, error) {
var outputs []string
envs := make(map[string]string)
for _, step := range steps {
var out string
var err error
switch step.StepName {
case "init":
out, err = p.InitStepRunner.Run(ctx, step.ExtraArgs, absPath)
out, err = p.InitStepRunner.Run(ctx, step.ExtraArgs, absPath, envs)
case "plan":
out, err = p.PlanStepRunner.Run(ctx, step.ExtraArgs, absPath)
out, err = p.PlanStepRunner.Run(ctx, step.ExtraArgs, absPath, envs)
case "apply":
out, err = p.ApplyStepRunner.Run(ctx, step.ExtraArgs, absPath)
out, err = p.ApplyStepRunner.Run(ctx, step.ExtraArgs, absPath, envs)
case "run":
out, err = p.RunStepRunner.Run(ctx, step.RunCommand, absPath)
out, err = p.RunStepRunner.Run(ctx, step.RunCommand, absPath, envs)
case "env":
out, err = p.EnvStepRunner.Run(ctx, step.RunCommand, step.EnvVarValue, absPath, envs)
envs[step.EnvVarName] = out
// We reset out to the empty string because we don't want it to
// be printed to the PR, it's solely to set the environment variable.
out = ""
}

if out != "" {
Expand Down
Loading