Skip to content

Commit

Permalink
Add var step to workflows
Browse files Browse the repository at this point in the history
Add new var step for setting environment variable in workflows.
  • Loading branch information
anasinnyk authored and lkysow committed Aug 21, 2019
1 parent 1fb16b1 commit 33c0a72
Show file tree
Hide file tree
Showing 26 changed files with 680 additions and 148 deletions.
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.

133 changes: 133 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.

26 changes: 20 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, name string, cmd string, value string, path string, envs map[string]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 @@ -174,17 +182,23 @@ func (p *DefaultProjectCommandRunner) doPlan(ctx models.ProjectCommandContext) (
func (p *DefaultProjectCommandRunner) runSteps(steps []valid.Step, ctx models.ProjectCommandContext, absPath string) ([]string, error) {
var outputs []string
for _, step := range steps {
var envs = make(map[string]string)
var out string
var err error
var name string
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":
name, out, err = p.EnvStepRunner.Run(ctx, step.EnvVarName, step.RunCommand, step.EnvVarValue, absPath, envs)
envs[name] = out
out = ""
}

if out != "" {
Expand Down
Loading

0 comments on commit 33c0a72

Please sign in to comment.