From a47621eaa1b0fa78e1c1558c1078be1a966fde8c Mon Sep 17 00:00:00 2001 From: ecrupper Date: Mon, 18 Apr 2022 10:22:32 -0500 Subject: [PATCH 1/4] add continue tag to stage --- pipeline/container.go | 5 ++-- pipeline/ruleset.go | 34 +++++++++++++++------------- pipeline/stage.go | 1 + yaml/build_test.go | 15 +++++++----- yaml/stage.go | 8 +++++++ yaml/stage_test.go | 18 ++++++++++----- yaml/testdata/build_anchor_stage.yml | 1 + yaml/testdata/stage.yml | 2 ++ 8 files changed, 54 insertions(+), 30 deletions(-) diff --git a/pipeline/container.go b/pipeline/container.go index 30b48134..24efb0b4 100644 --- a/pipeline/container.go +++ b/pipeline/container.go @@ -191,8 +191,9 @@ func (c *Container) Execute(r *RuleData) bool { execute = false // check if you need to run a status failure ruleset - if !(c.Ruleset.If.Empty() && c.Ruleset.Unless.Empty()) && - !(c.Ruleset.If.NoStatus() && c.Ruleset.Unless.NoStatus()) && + + if ((!(c.Ruleset.If.Empty() && c.Ruleset.Unless.Empty()) && + !(c.Ruleset.If.NoStatus() && c.Ruleset.Unless.NoStatus())) || c.Ruleset.If.Parallel) && c.Ruleset.Match(r) { // approve the need to run the container execute = true diff --git a/pipeline/ruleset.go b/pipeline/ruleset.go index 630206c4..b2f70df1 100644 --- a/pipeline/ruleset.go +++ b/pipeline/ruleset.go @@ -30,14 +30,15 @@ type ( // // swagger:model PipelineRules Rules struct { - Branch Ruletype `json:"branch,omitempty" yaml:"branch,omitempty"` - Comment Ruletype `json:"comment,omitempty" yaml:"comment,omitempty"` - Event Ruletype `json:"event,omitempty" yaml:"event,omitempty"` - Path Ruletype `json:"path,omitempty" yaml:"path,omitempty"` - Repo Ruletype `json:"repo,omitempty" yaml:"repo,omitempty"` - Status Ruletype `json:"status,omitempty" yaml:"status,omitempty"` - Tag Ruletype `json:"tag,omitempty" yaml:"tag,omitempty"` - Target Ruletype `json:"target,omitempty" yaml:"target,omitempty"` + Branch Ruletype `json:"branch,omitempty" yaml:"branch,omitempty"` + Comment Ruletype `json:"comment,omitempty" yaml:"comment,omitempty"` + Event Ruletype `json:"event,omitempty" yaml:"event,omitempty"` + Path Ruletype `json:"path,omitempty" yaml:"path,omitempty"` + Repo Ruletype `json:"repo,omitempty" yaml:"repo,omitempty"` + Status Ruletype `json:"status,omitempty" yaml:"status,omitempty"` + Tag Ruletype `json:"tag,omitempty" yaml:"tag,omitempty"` + Target Ruletype `json:"target,omitempty" yaml:"target,omitempty"` + Parallel bool `json:"parallel,omitempty" yaml:"parallel,omitempty"` } // Ruletype is the pipeline representation of an element @@ -49,14 +50,15 @@ type ( // RuleData is the data to check our ruleset // against for a step in a pipeline. RuleData struct { - Branch string `json:"branch,omitempty" yaml:"branch,omitempty"` - Comment string `json:"comment,omitempty" yaml:"comment,omitempty"` - Event string `json:"event,omitempty" yaml:"event,omitempty"` - Path []string `json:"path,omitempty" yaml:"path,omitempty"` - Repo string `json:"repo,omitempty" yaml:"repo,omitempty"` - Status string `json:"status,omitempty" yaml:"status,omitempty"` - Tag string `json:"tag,omitempty" yaml:"tag,omitempty"` - Target string `json:"target,omitempty" yaml:"target,omitempty"` + Branch string `json:"branch,omitempty" yaml:"branch,omitempty"` + Comment string `json:"comment,omitempty" yaml:"comment,omitempty"` + Event string `json:"event,omitempty" yaml:"event,omitempty"` + Path []string `json:"path,omitempty" yaml:"path,omitempty"` + Repo string `json:"repo,omitempty" yaml:"repo,omitempty"` + Status string `json:"status,omitempty" yaml:"status,omitempty"` + Tag string `json:"tag,omitempty" yaml:"tag,omitempty"` + Target string `json:"target,omitempty" yaml:"target,omitempty"` + Parallel bool `json:"parallel,omitempty" yaml:"parallel,omitempty"` } ) diff --git a/pipeline/stage.go b/pipeline/stage.go index 78238591..8155e932 100644 --- a/pipeline/stage.go +++ b/pipeline/stage.go @@ -26,6 +26,7 @@ type ( Environment map[string]string `json:"environment,omitempty" yaml:"environment,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` Needs []string `json:"needs,omitempty" yaml:"needs,omitempty"` + Continue bool `json:"continue,omitempty" yaml:"continue,omitempty"` Steps ContainerSlice `json:"steps,omitempty" yaml:"steps,omitempty"` } ) diff --git a/yaml/build_test.go b/yaml/build_test.go index 4ed23426..df4647dd 100644 --- a/yaml/build_test.go +++ b/yaml/build_test.go @@ -333,8 +333,9 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) { }, Stages: StageSlice{ { - Name: "dependencies", - Needs: []string{"clone"}, + Name: "dependencies", + Needs: []string{"clone"}, + Continue: false, Steps: StepSlice{ { Commands: raw.StringSlice{"./gradlew downloadDependencies"}, @@ -368,8 +369,9 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) { }, }, { - Name: "test", - Needs: []string{"dependencies", "clone"}, + Name: "test", + Needs: []string{"dependencies", "clone"}, + Continue: false, Steps: StepSlice{ { Commands: raw.StringSlice{"./gradlew check"}, @@ -403,8 +405,9 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) { }, }, { - Name: "build", - Needs: []string{"dependencies", "clone"}, + Name: "build", + Needs: []string{"dependencies", "clone"}, + Continue: true, Steps: StepSlice{ { Commands: raw.StringSlice{"./gradlew build"}, diff --git a/yaml/stage.go b/yaml/stage.go index 355ecbed..b04d770e 100644 --- a/yaml/stage.go +++ b/yaml/stage.go @@ -24,6 +24,7 @@ type ( Environment raw.StringSliceMap `yaml:"environment,omitempty" json:"environment,omitempty" jsonschema:"description=Provide environment variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-environment-tag"` Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"minLength=1,description=Unique identifier for the stage in the pipeline.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-name-tag"` Needs raw.StringSlice `yaml:"needs,omitempty,flow" json:"needs,omitempty" jsonschema:"description=Stages that must complete before starting the current one.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-needs-tag"` + Continue bool `yaml:"continue,omitempty" json:"continue,omitempty" jsonschema:"description=Stage will continue executing if other stage fails if set to false; default is true"` Steps StepSlice `yaml:"steps,omitempty" json:"steps,omitempty" jsonschema:"required,description=Sequential execution instructions for the stage.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-steps-tag"` } ) @@ -42,6 +43,7 @@ func (s *StageSlice) ToPipeline() *pipeline.StageSlice { Environment: stage.Environment, Name: stage.Name, Needs: stage.Needs, + Continue: stage.Continue, Steps: *stage.Steps.ToPipeline(), }) } @@ -93,6 +95,9 @@ func (s *StageSlice) UnmarshalYAML(unmarshal func(interface{}) error) error { }(stage.Needs) } + fmt.Println("THIS IS THE VALUE OF CONTINUE IN TYPES") + fmt.Println(stage.Continue) + // append stage to stage slice *s = append(*s, stage) } @@ -113,6 +118,9 @@ func (s StageSlice) MarshalYAML() (interface{}, error) { // add the existing needs to the new stage outputStage.Needs = inputStage.Needs + // add the existing dependent tag to the new stage + outputStage.Continue = inputStage.Continue + // add the existing steps to the new stage outputStage.Steps = inputStage.Steps diff --git a/yaml/stage_test.go b/yaml/stage_test.go index 62d40b70..210571e8 100644 --- a/yaml/stage_test.go +++ b/yaml/stage_test.go @@ -193,6 +193,7 @@ func TestYaml_StageSlice_UnmarshalYAML(t *testing.T) { Environment: map[string]string{ "STAGE_ENV_VAR": "stage", }, + Continue: true, Steps: StepSlice{ { Commands: []string{"./gradlew downloadDependencies"}, @@ -213,6 +214,7 @@ func TestYaml_StageSlice_UnmarshalYAML(t *testing.T) { "STAGE_ENV_VAR": "stage", "SECOND_STAGE_ENV": "stage2", }, + Continue: false, Steps: StepSlice{ { Commands: []string{"./gradlew check"}, @@ -232,6 +234,7 @@ func TestYaml_StageSlice_UnmarshalYAML(t *testing.T) { Environment: map[string]string{ "STAGE_ENV_VAR": "stage", }, + Continue: false, Steps: StepSlice{ { Commands: []string{"./gradlew build"}, @@ -310,8 +313,9 @@ func TestYaml_StageSlice_MarshalYAML(t *testing.T) { file: "testdata/stage.yml", want: &StageSlice{ { - Name: "dependencies", - Needs: []string{"clone"}, + Name: "dependencies", + Needs: []string{"clone"}, + Continue: true, Steps: StepSlice{ { Commands: []string{"./gradlew downloadDependencies"}, @@ -326,8 +330,9 @@ func TestYaml_StageSlice_MarshalYAML(t *testing.T) { }, }, { - Name: "test", - Needs: []string{"dependencies", "clone"}, + Name: "test", + Needs: []string{"dependencies", "clone"}, + Continue: false, Steps: StepSlice{ { Commands: []string{"./gradlew check"}, @@ -342,8 +347,9 @@ func TestYaml_StageSlice_MarshalYAML(t *testing.T) { }, }, { - Name: "build", - Needs: []string{"dependencies", "clone"}, + Name: "build", + Needs: []string{"dependencies", "clone"}, + Continue: false, Steps: StepSlice{ { Commands: []string{"./gradlew build"}, diff --git a/yaml/testdata/build_anchor_stage.yml b/yaml/testdata/build_anchor_stage.yml index bfeb0e43..a3d684af 100644 --- a/yaml/testdata/build_anchor_stage.yml +++ b/yaml/testdata/build_anchor_stage.yml @@ -38,6 +38,7 @@ stages: build: needs: [ dependencies ] + continue: true steps: - name: build commands: diff --git a/yaml/testdata/stage.yml b/yaml/testdata/stage.yml index 6f3fd2ff..6a72e6bc 100644 --- a/yaml/testdata/stage.yml +++ b/yaml/testdata/stage.yml @@ -2,6 +2,7 @@ dependencies: environment: STAGE_ENV_VAR: stage + continue: true steps: - name: install commands: @@ -17,6 +18,7 @@ test: environment: STAGE_ENV_VAR: stage SECOND_STAGE_ENV: stage2 + continue: false steps: - name: test commands: From 896a0b3698f22110201e96f79d782e7d6016f57b Mon Sep 17 00:00:00 2001 From: ecrupper Date: Mon, 18 Apr 2022 12:23:16 -0500 Subject: [PATCH 2/4] lost print statements and fix json scheme description --- yaml/stage.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/yaml/stage.go b/yaml/stage.go index b04d770e..61835d8f 100644 --- a/yaml/stage.go +++ b/yaml/stage.go @@ -24,7 +24,7 @@ type ( Environment raw.StringSliceMap `yaml:"environment,omitempty" json:"environment,omitempty" jsonschema:"description=Provide environment variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-environment-tag"` Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"minLength=1,description=Unique identifier for the stage in the pipeline.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-name-tag"` Needs raw.StringSlice `yaml:"needs,omitempty,flow" json:"needs,omitempty" jsonschema:"description=Stages that must complete before starting the current one.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-needs-tag"` - Continue bool `yaml:"continue,omitempty" json:"continue,omitempty" jsonschema:"description=Stage will continue executing if other stage fails if set to false; default is true"` + Continue bool `yaml:"continue,omitempty" json:"continue,omitempty" jsonschema:"description=Stage will continue executing if other stage fails"` Steps StepSlice `yaml:"steps,omitempty" json:"steps,omitempty" jsonschema:"required,description=Sequential execution instructions for the stage.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-steps-tag"` } ) @@ -95,9 +95,6 @@ func (s *StageSlice) UnmarshalYAML(unmarshal func(interface{}) error) error { }(stage.Needs) } - fmt.Println("THIS IS THE VALUE OF CONTINUE IN TYPES") - fmt.Println(stage.Continue) - // append stage to stage slice *s = append(*s, stage) } From e67eb52c9da52837a7065de22ddf4d237e03d5b9 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Fri, 9 Sep 2022 14:48:28 -0500 Subject: [PATCH 3/4] changing continue to independent, as that seems more appropriate for given the functionality --- pipeline/stage.go | 6 +++--- yaml/build_test.go | 18 +++++++++--------- yaml/stage.go | 6 +++--- yaml/stage_test.go | 24 ++++++++++++------------ yaml/testdata/build_anchor_stage.yml | 2 +- yaml/testdata/stage.yml | 4 ++-- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/pipeline/stage.go b/pipeline/stage.go index 8155e932..10289514 100644 --- a/pipeline/stage.go +++ b/pipeline/stage.go @@ -26,7 +26,7 @@ type ( Environment map[string]string `json:"environment,omitempty" yaml:"environment,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` Needs []string `json:"needs,omitempty" yaml:"needs,omitempty"` - Continue bool `json:"continue,omitempty" yaml:"continue,omitempty"` + Independent bool `json:"independent,omitempty" yaml:"independent,omitempty"` Steps ContainerSlice `json:"steps,omitempty" yaml:"steps,omitempty"` } ) @@ -79,8 +79,8 @@ func (s *StageSlice) Purge(r *RuleData) *StageSlice { // based off of the provided runtime driver which is setup on every // worker. Currently, this function supports the following runtimes: // -// * Docker -// * Kubernetes +// - Docker +// - Kubernetes func (s *StageSlice) Sanitize(driver string) *StageSlice { stages := new(StageSlice) diff --git a/yaml/build_test.go b/yaml/build_test.go index 2334d788..5110aab5 100644 --- a/yaml/build_test.go +++ b/yaml/build_test.go @@ -333,9 +333,9 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) { }, Stages: StageSlice{ { - Name: "dependencies", - Needs: []string{"clone"}, - Continue: false, + Name: "dependencies", + Needs: []string{"clone"}, + Independent: false, Steps: StepSlice{ { Commands: raw.StringSlice{"./gradlew downloadDependencies"}, @@ -369,9 +369,9 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) { }, }, { - Name: "test", - Needs: []string{"dependencies", "clone"}, - Continue: false, + Name: "test", + Needs: []string{"dependencies", "clone"}, + Independent: false, Steps: StepSlice{ { Commands: raw.StringSlice{"./gradlew check"}, @@ -405,9 +405,9 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) { }, }, { - Name: "build", - Needs: []string{"dependencies", "clone"}, - Continue: true, + Name: "build", + Needs: []string{"dependencies", "clone"}, + Independent: true, Steps: StepSlice{ { Commands: raw.StringSlice{"./gradlew build"}, diff --git a/yaml/stage.go b/yaml/stage.go index 61835d8f..8a4bc5d6 100644 --- a/yaml/stage.go +++ b/yaml/stage.go @@ -24,7 +24,7 @@ type ( Environment raw.StringSliceMap `yaml:"environment,omitempty" json:"environment,omitempty" jsonschema:"description=Provide environment variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-environment-tag"` Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"minLength=1,description=Unique identifier for the stage in the pipeline.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-name-tag"` Needs raw.StringSlice `yaml:"needs,omitempty,flow" json:"needs,omitempty" jsonschema:"description=Stages that must complete before starting the current one.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-needs-tag"` - Continue bool `yaml:"continue,omitempty" json:"continue,omitempty" jsonschema:"description=Stage will continue executing if other stage fails"` + Independent bool `yaml:"independent,omitempty" json:"independent,omitempty" jsonschema:"description=Stage will continue executing if other stage fails"` Steps StepSlice `yaml:"steps,omitempty" json:"steps,omitempty" jsonschema:"required,description=Sequential execution instructions for the stage.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/#the-steps-tag"` } ) @@ -43,7 +43,7 @@ func (s *StageSlice) ToPipeline() *pipeline.StageSlice { Environment: stage.Environment, Name: stage.Name, Needs: stage.Needs, - Continue: stage.Continue, + Independent: stage.Independent, Steps: *stage.Steps.ToPipeline(), }) } @@ -116,7 +116,7 @@ func (s StageSlice) MarshalYAML() (interface{}, error) { outputStage.Needs = inputStage.Needs // add the existing dependent tag to the new stage - outputStage.Continue = inputStage.Continue + outputStage.Independent = inputStage.Independent // add the existing steps to the new stage outputStage.Steps = inputStage.Steps diff --git a/yaml/stage_test.go b/yaml/stage_test.go index 210571e8..f7e5a1b3 100644 --- a/yaml/stage_test.go +++ b/yaml/stage_test.go @@ -193,7 +193,7 @@ func TestYaml_StageSlice_UnmarshalYAML(t *testing.T) { Environment: map[string]string{ "STAGE_ENV_VAR": "stage", }, - Continue: true, + Independent: true, Steps: StepSlice{ { Commands: []string{"./gradlew downloadDependencies"}, @@ -214,7 +214,7 @@ func TestYaml_StageSlice_UnmarshalYAML(t *testing.T) { "STAGE_ENV_VAR": "stage", "SECOND_STAGE_ENV": "stage2", }, - Continue: false, + Independent: false, Steps: StepSlice{ { Commands: []string{"./gradlew check"}, @@ -234,7 +234,7 @@ func TestYaml_StageSlice_UnmarshalYAML(t *testing.T) { Environment: map[string]string{ "STAGE_ENV_VAR": "stage", }, - Continue: false, + Independent: false, Steps: StepSlice{ { Commands: []string{"./gradlew build"}, @@ -313,9 +313,9 @@ func TestYaml_StageSlice_MarshalYAML(t *testing.T) { file: "testdata/stage.yml", want: &StageSlice{ { - Name: "dependencies", - Needs: []string{"clone"}, - Continue: true, + Name: "dependencies", + Needs: []string{"clone"}, + Independent: true, Steps: StepSlice{ { Commands: []string{"./gradlew downloadDependencies"}, @@ -330,9 +330,9 @@ func TestYaml_StageSlice_MarshalYAML(t *testing.T) { }, }, { - Name: "test", - Needs: []string{"dependencies", "clone"}, - Continue: false, + Name: "test", + Needs: []string{"dependencies", "clone"}, + Independent: false, Steps: StepSlice{ { Commands: []string{"./gradlew check"}, @@ -347,9 +347,9 @@ func TestYaml_StageSlice_MarshalYAML(t *testing.T) { }, }, { - Name: "build", - Needs: []string{"dependencies", "clone"}, - Continue: false, + Name: "build", + Needs: []string{"dependencies", "clone"}, + Independent: false, Steps: StepSlice{ { Commands: []string{"./gradlew build"}, diff --git a/yaml/testdata/build_anchor_stage.yml b/yaml/testdata/build_anchor_stage.yml index a3d684af..2fc87932 100644 --- a/yaml/testdata/build_anchor_stage.yml +++ b/yaml/testdata/build_anchor_stage.yml @@ -38,7 +38,7 @@ stages: build: needs: [ dependencies ] - continue: true + independent: true steps: - name: build commands: diff --git a/yaml/testdata/stage.yml b/yaml/testdata/stage.yml index 6a72e6bc..543ffdf8 100644 --- a/yaml/testdata/stage.yml +++ b/yaml/testdata/stage.yml @@ -2,7 +2,7 @@ dependencies: environment: STAGE_ENV_VAR: stage - continue: true + independent: true steps: - name: install commands: @@ -18,7 +18,7 @@ test: environment: STAGE_ENV_VAR: stage SECOND_STAGE_ENV: stage2 - continue: false + independent: false steps: - name: test commands: From ec7dea881c0673f51498143b5ad961bd746227c2 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Fri, 9 Dec 2022 13:54:27 -0600 Subject: [PATCH 4/4] fixing indentation and ditching yaml/json tag --- pipeline/ruleset.go | 4 ++-- pipeline/stage.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pipeline/ruleset.go b/pipeline/ruleset.go index cbcd636c..e63ba0fc 100644 --- a/pipeline/ruleset.go +++ b/pipeline/ruleset.go @@ -38,7 +38,7 @@ type ( Status Ruletype `json:"status,omitempty" yaml:"status,omitempty"` Tag Ruletype `json:"tag,omitempty" yaml:"tag,omitempty"` Target Ruletype `json:"target,omitempty" yaml:"target,omitempty"` - Parallel bool `json:"parallel,omitempty" yaml:"parallel,omitempty"` + Parallel bool `json:"-" yaml:"-"` } // Ruletype is the pipeline representation of an element @@ -58,7 +58,7 @@ type ( Status string `json:"status,omitempty" yaml:"status,omitempty"` Tag string `json:"tag,omitempty" yaml:"tag,omitempty"` Target string `json:"target,omitempty" yaml:"target,omitempty"` - Parallel bool `json:"parallel,omitempty" yaml:"parallel,omitempty"` + Parallel bool `json:"-" yaml:"-"` } ) diff --git a/pipeline/stage.go b/pipeline/stage.go index 10289514..e1c9d449 100644 --- a/pipeline/stage.go +++ b/pipeline/stage.go @@ -26,7 +26,7 @@ type ( Environment map[string]string `json:"environment,omitempty" yaml:"environment,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` Needs []string `json:"needs,omitempty" yaml:"needs,omitempty"` - Independent bool `json:"independent,omitempty" yaml:"independent,omitempty"` + Independent bool `json:"independent,omitempty" yaml:"independent,omitempty"` Steps ContainerSlice `json:"steps,omitempty" yaml:"steps,omitempty"` } )