Update schema (#6156)

closes https://github.com/woodpecker-ci/woodpecker/issues/6135

Everything else in the issue is correct, and nothing that has to be fixed.

Also changes the parsing for the `status` filter from the constraint list (with includes/excludes) to an allowlist only (as we only have two statuses it's quite useless to have an exclude and this was also not documented).
This commit is contained in:
qwerty287
2026-02-26 12:46:50 +01:00
committed by GitHub
parent 69c934873d
commit 05f55fb0f9
4 changed files with 14 additions and 8 deletions

View File

@@ -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
}
}

View File

@@ -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)

View File

@@ -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

View File

@@ -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",