diff --git a/pipeline/frontend/yaml/constraint/constraint.go b/pipeline/frontend/yaml/constraint/constraint.go index c6c3afedc..7f77193f0 100644 --- a/pipeline/frontend/yaml/constraint/constraint.go +++ b/pipeline/frontend/yaml/constraint/constraint.go @@ -28,6 +28,11 @@ import ( "go.woodpecker-ci.org/woodpecker/v3/shared/optional" ) +const ( + statusFailure = "failure" + statusSuccess = "success" +) + type ( // When defines a set of runtime constraints. When struct { @@ -42,7 +47,7 @@ type ( Platform List `yaml:"platform,omitempty"` Branch List `yaml:"branch,omitempty"` Cron List `yaml:"cron,omitempty"` - Status List `yaml:"status,omitempty"` + Status []string `yaml:"status,omitempty"` Matrix Map `yaml:"matrix,omitempty"` Local optional.Option[bool] `yaml:"local,omitempty"` Path Path `yaml:"path,omitempty"` @@ -77,7 +82,7 @@ func (when *When) Match(metadata metadata.Metadata, global bool, env map[string] func (when *When) IncludesStatusFailure() bool { for _, c := range when.Constraints { - if c.Status.Includes("failure") { + if slices.Contains(c.Status, statusFailure) { return true } } @@ -93,7 +98,7 @@ func (when *When) IncludesStatusSuccess() bool { return true } for _, c := range when.Constraints { - if len(c.Status.Include) == 0 || c.Status.Includes("success") { + if len(c.Status) == 0 || slices.Contains(c.Status, statusSuccess) { return true } } diff --git a/pipeline/frontend/yaml/constraint/constraint_test.go b/pipeline/frontend/yaml/constraint/constraint_test.go index 2f7f3376d..4812390c8 100644 --- a/pipeline/frontend/yaml/constraint/constraint_test.go +++ b/pipeline/frontend/yaml/constraint/constraint_test.go @@ -32,8 +32,6 @@ func TestConstraintStatusSuccess(t *testing.T) { {conf: "{status: [failure]}", want: false}, {conf: "{status: [success]}", want: true}, {conf: "{status: [failure, success]}", want: true}, - {conf: "{status: {exclude: [success], include: [failure]}}", want: false}, - {conf: "{status: {exclude: [failure], include: [success]}}", want: true}, } for _, test := range testdata { c := parseConstraints(t, test.conf) diff --git a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-when.yaml b/pipeline/frontend/yaml/linter/schema/.woodpecker/test-when.yaml index 93b462192..390420956 100644 --- a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-when.yaml +++ b/pipeline/frontend/yaml/linter/schema/.woodpecker/test-when.yaml @@ -43,7 +43,10 @@ steps: commands: - echo "test" when: - ref: 'refs/tags/v**' + - ref: 'refs/tags/v**' + - ref: + include: 'refs/tags/v**' + exclude: 'refs/tags/v1.**' when-status: image: alpine diff --git a/pipeline/frontend/yaml/linter/schema/schema.json b/pipeline/frontend/yaml/linter/schema/schema.json index 5b20b1ee0..f3cf824a5 100644 --- a/pipeline/frontend/yaml/linter/schema/schema.json +++ b/pipeline/frontend/yaml/linter/schema/schema.json @@ -181,7 +181,7 @@ }, "ref": { "description": "Read more: https://woodpecker-ci.org/docs/usage/workflow-syntax#ref", - "type": "string" + "$ref": "#/definitions/constraint_list" }, "cron": { "description": "filter cron by title. Read more: https://woodpecker-ci.org/docs/usage/workflow-syntax#cron", @@ -420,7 +420,7 @@ }, "ref": { "description": "Read more: https://woodpecker-ci.org/docs/usage/workflow-syntax#ref", - "type": "string" + "$ref": "#/definitions/constraint_list" }, "cron": { "description": "filter cron by title. Read more: https://woodpecker-ci.org/docs/usage/workflow-syntax#cron",