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

feat(stage): add independent tag for independency #247

Merged
merged 15 commits into from
Dec 9, 2022
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
5 changes: 3 additions & 2 deletions pipeline/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 18 additions & 16 deletions pipeline/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-" yaml:"-"`
}

// Ruletype is the pipeline representation of an element
Expand All @@ -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:"-" yaml:"-"`
}
)

Expand Down
1 change: 1 addition & 0 deletions pipeline/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Independent bool `json:"independent,omitempty" yaml:"independent,omitempty"`
Steps ContainerSlice `json:"steps,omitempty" yaml:"steps,omitempty"`
}
)
Expand Down
15 changes: 9 additions & 6 deletions yaml/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,9 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
},
Stages: StageSlice{
{
Name: "dependencies",
Needs: []string{"clone"},
Name: "dependencies",
Needs: []string{"clone"},
Independent: false,
Steps: StepSlice{
{
Commands: raw.StringSlice{"./gradlew downloadDependencies"},
Expand Down Expand Up @@ -368,8 +369,9 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
},
},
{
Name: "test",
Needs: []string{"dependencies", "clone"},
Name: "test",
Needs: []string{"dependencies", "clone"},
Independent: false,
Steps: StepSlice{
{
Commands: raw.StringSlice{"./gradlew check"},
Expand Down Expand Up @@ -403,8 +405,9 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
},
},
{
Name: "build",
Needs: []string{"dependencies", "clone"},
Name: "build",
Needs: []string{"dependencies", "clone"},
Independent: true,
Steps: StepSlice{
{
Commands: raw.StringSlice{"./gradlew build"},
Expand Down
5 changes: 5 additions & 0 deletions yaml/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
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"`
}
)
Expand All @@ -42,6 +43,7 @@ func (s *StageSlice) ToPipeline() *pipeline.StageSlice {
Environment: stage.Environment,
Name: stage.Name,
Needs: stage.Needs,
Independent: stage.Independent,
Steps: *stage.Steps.ToPipeline(),
})
}
Expand Down Expand Up @@ -113,6 +115,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.Independent = inputStage.Independent

// add the existing steps to the new stage
outputStage.Steps = inputStage.Steps

Expand Down
18 changes: 12 additions & 6 deletions yaml/stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func TestYaml_StageSlice_UnmarshalYAML(t *testing.T) {
Environment: map[string]string{
"STAGE_ENV_VAR": "stage",
},
Independent: true,
Steps: StepSlice{
{
Commands: []string{"./gradlew downloadDependencies"},
Expand All @@ -213,6 +214,7 @@ func TestYaml_StageSlice_UnmarshalYAML(t *testing.T) {
"STAGE_ENV_VAR": "stage",
"SECOND_STAGE_ENV": "stage2",
},
Independent: false,
Steps: StepSlice{
{
Commands: []string{"./gradlew check"},
Expand All @@ -232,6 +234,7 @@ func TestYaml_StageSlice_UnmarshalYAML(t *testing.T) {
Environment: map[string]string{
"STAGE_ENV_VAR": "stage",
},
Independent: false,
Steps: StepSlice{
{
Commands: []string{"./gradlew build"},
Expand Down Expand Up @@ -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"},
Independent: true,
Steps: StepSlice{
{
Commands: []string{"./gradlew downloadDependencies"},
Expand All @@ -326,8 +330,9 @@ func TestYaml_StageSlice_MarshalYAML(t *testing.T) {
},
},
{
Name: "test",
Needs: []string{"dependencies", "clone"},
Name: "test",
Needs: []string{"dependencies", "clone"},
Independent: false,
Steps: StepSlice{
{
Commands: []string{"./gradlew check"},
Expand All @@ -342,8 +347,9 @@ func TestYaml_StageSlice_MarshalYAML(t *testing.T) {
},
},
{
Name: "build",
Needs: []string{"dependencies", "clone"},
Name: "build",
Needs: []string{"dependencies", "clone"},
Independent: false,
Steps: StepSlice{
{
Commands: []string{"./gradlew build"},
Expand Down
1 change: 1 addition & 0 deletions yaml/testdata/build_anchor_stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ stages:

build:
needs: [ dependencies ]
independent: true
steps:
- name: build
commands:
Expand Down
2 changes: 2 additions & 0 deletions yaml/testdata/stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
dependencies:
environment:
STAGE_ENV_VAR: stage
independent: true
steps:
- name: install
commands:
Expand All @@ -17,6 +18,7 @@ test:
environment:
STAGE_ENV_VAR: stage
SECOND_STAGE_ENV: stage2
independent: false
steps:
- name: test
commands:
Expand Down