Skip to content

Commit

Permalink
Merge pull request #2407 from buildkite/fix-string-skips
Browse files Browse the repository at this point in the history
Fix parsing pipelines what use a string as the skip key in a matrix adjustment
  • Loading branch information
moskyb authored Oct 3, 2023
2 parents 91890fa + f6c41e1 commit 8faa01f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
24 changes: 20 additions & 4 deletions internal/pipeline/parser_matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ steps:
skip: true
- with: 42
soft_fail: true
- with: banana
skip: "how dare you, you know i'm allergic to bananas!"
`,
want: &Pipeline{
Steps: Steps{
Expand All @@ -119,8 +121,14 @@ steps:
Skip: true,
},
{
With: MatrixAdjustmentWith{"": 42},
SoftFail: true,
With: MatrixAdjustmentWith{"": 42},
RemainingFields: map[string]any{
"soft_fail": true,
},
},
{
With: MatrixAdjustmentWith{"": "banana"},
Skip: "how dare you, you know i'm allergic to bananas!",
},
},
},
Expand All @@ -140,6 +148,10 @@ steps:
{
"soft_fail": true,
"with": 42
},
{
"skip": "how dare you, you know i'm allergic to bananas!",
"with": "banana"
}
],
"setup": [
Expand Down Expand Up @@ -265,7 +277,9 @@ steps:
"arch": "ppc",
"os": 8,
},
SoftFail: true,
RemainingFields: map[string]any{
"soft_fail": true,
},
},
},
},
Expand Down Expand Up @@ -369,7 +383,9 @@ steps:
"arch": "s390x",
"os": "zos",
},
SoftFail: true,
RemainingFields: map[string]any{
"soft_fail": true,
},
},
},
},
Expand Down
20 changes: 16 additions & 4 deletions internal/pipeline/step_command_matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,23 @@ type MatrixAdjustments []*MatrixAdjustment
// MatrixAdjustment models an adjustment - a combination of (possibly new)
// matrix values, and skip/soft fail configuration.
type MatrixAdjustment struct {
With MatrixAdjustmentWith `yaml:"with"`
Skip bool `yaml:"skip,omitempty"`
SoftFail bool `yaml:"soft_fail,omitempty"`
With MatrixAdjustmentWith `yaml:"with"`
Skip any `yaml:"skip,omitempty"`

RemainingFields map[string]any `yaml:",inline"`
RemainingFields map[string]any `yaml:",inline"` // NB: soft_fail is in the remaining fields
}

func (ma *MatrixAdjustment) ShouldSkip() bool {
switch s := ma.Skip.(type) {
case bool:
return s

case nil:
return false

default:
return true
}
}

// MarshalJSON is needed to use inlineFriendlyMarshalJSON.
Expand Down

0 comments on commit 8faa01f

Please sign in to comment.