From 153ac965109addf3770721da3ee9140c159cf44f Mon Sep 17 00:00:00 2001 From: Luke Kysow <1034429+lkysow@users.noreply.github.com> Date: Tue, 26 Nov 2019 16:07:51 -0800 Subject: [PATCH] Fix bug when redefining default workflow 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. --- server/events/yaml/parser_validator_test.go | 53 ++++++++++++++++++++- server/events/yaml/raw/global_cfg.go | 9 +++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/server/events/yaml/parser_validator_test.go b/server/events/yaml/parser_validator_test.go index ae332636f..bc3f2e42a 100644 --- a/server/events/yaml/parser_validator_test.go +++ b/server/events/yaml/parser_validator_test.go @@ -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" @@ -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) { diff --git a/server/events/yaml/raw/global_cfg.go b/server/events/yaml/raw/global_cfg.go index 47a4d1f2a..eeaed643b 100644 --- a/server/events/yaml/raw/global_cfg.go +++ b/server/events/yaml/raw/global_cfg.go @@ -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 {