Skip to content

Commit

Permalink
Fix bug when redefining default workflow
Browse files Browse the repository at this point in the history
Previously, given the config:
  workflows:
    default:
      ...

We wouldn't actually use the redefined default workfow in our always
existing first repo config. This would mean that the redefined default
was never used unless users explicitly set workflow: default in the
repos array.
  • Loading branch information
lkysow committed Nov 27, 2019
1 parent 634392d commit 153ac96
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
53 changes: 52 additions & 1 deletion server/events/yaml/parser_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"testing"

version "github.com/hashicorp/go-version"
"github.com/hashicorp/go-version"
"github.com/runatlantis/atlantis/server/events/yaml"
"github.com/runatlantis/atlantis/server/events/yaml/valid"
. "github.com/runatlantis/atlantis/testing"
Expand Down Expand Up @@ -1076,6 +1076,57 @@ repos:
},
},
},
"redefine default workflow": {
input: `
workflows:
default:
plan:
steps:
- run: custom
apply:
steps: []
`,
exp: valid.GlobalCfg{
Repos: []valid.Repo{
{
IDRegex: regexp.MustCompile(".*"),
ApplyRequirements: []string{},
Workflow: &valid.Workflow{
Name: "default",
Apply: valid.Stage{
Steps: nil,
},
Plan: valid.Stage{
Steps: []valid.Step{
{
StepName: "run",
RunCommand: "custom",
},
},
},
},
AllowedOverrides: []string{},
AllowCustomWorkflows: Bool(false),
},
},
Workflows: map[string]valid.Workflow{
"default": {
Name: "default",
Apply: valid.Stage{
Steps: nil,
},
Plan: valid.Stage{
Steps: []valid.Step{
{
StepName: "run",
RunCommand: "custom",
},
},
},
},
},
},
},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
Expand Down
9 changes: 8 additions & 1 deletion server/events/yaml/raw/global_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ func (g GlobalCfg) Validate() error {
func (g GlobalCfg) ToValid(defaultCfg valid.GlobalCfg) valid.GlobalCfg {
workflows := make(map[string]valid.Workflow)
for k, v := range g.Workflows {
workflows[k] = v.ToValid(k)
validatedWorkflow := v.ToValid(k)
workflows[k] = validatedWorkflow
if k == valid.DefaultWorkflowName {
// Handle the special case where they're redefining the default
// workflow. In this case, our default repo config references
// the "old" default workflow and so needs to be redefined.
defaultCfg.Repos[0].Workflow = &validatedWorkflow
}
}
// Merge in defaults without overriding.
for k, v := range defaultCfg.Workflows {
Expand Down

0 comments on commit 153ac96

Please sign in to comment.