You've already forked woodpecker
mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-06-03 16:35:37 +02:00
Fix build error and include status calculation (#6436)
This commit is contained in:
@@ -81,6 +81,9 @@ func (when *When) Match(metadata metadata.Metadata, global bool, env map[string]
|
||||
}
|
||||
|
||||
func (when *When) IncludesStatusFailure(metadata metadata.Metadata, global bool, env map[string]string) bool {
|
||||
if when.IsEmpty() {
|
||||
return false
|
||||
}
|
||||
for _, c := range when.Constraints {
|
||||
if matches, err := c.Match(metadata, global, env); err == nil && matches {
|
||||
if slices.Contains(c.Status, statusFailure) {
|
||||
@@ -100,14 +103,13 @@ func (when *When) IncludesStatusSuccess(metadata metadata.Metadata, global bool,
|
||||
return true
|
||||
}
|
||||
for _, c := range when.Constraints {
|
||||
matches, err := c.Match(metadata, global, env)
|
||||
if matches, err := c.Match(metadata, global, env); err == nil && matches {
|
||||
if len(c.Status) > 0 && !slices.Contains(c.Status, statusSuccess) {
|
||||
return false
|
||||
if len(c.Status) == 0 || slices.Contains(c.Status, statusSuccess) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
// False if (any) non local.
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"go.woodpecker-ci.org/woodpecker/v3/pipeline/frontend/metadata"
|
||||
@@ -33,16 +34,29 @@ func TestConstraintStatusSuccessFailure(t *testing.T) {
|
||||
{conf: "{status: [failure]}", wantSuccess: false, wantFail: true},
|
||||
{conf: "{status: [success]}", wantSuccess: true, wantFail: false},
|
||||
{conf: "{status: [failure, success]}", wantSuccess: true, wantFail: true},
|
||||
{conf: "{event: push, status: [failure, success]}", wantSuccess: true, wantFail: false},
|
||||
{conf: "{event: push, status: [failure, success]}", wantSuccess: false, wantFail: false},
|
||||
{conf: "{event: pull_request, status: [failure, success]}", wantSuccess: true, wantFail: true},
|
||||
{conf: "{event: push, status: [failure]}", wantSuccess: true, wantFail: false},
|
||||
{conf: "{event: push, status: failure}", wantSuccess: false, wantFail: false},
|
||||
{conf: "{event: pull_request, status: [failure]}", wantSuccess: false, wantFail: true},
|
||||
{conf: "{status: success}", wantSuccess: true, wantFail: false},
|
||||
{conf: "[{}]", wantSuccess: true, wantFail: false},
|
||||
{conf: "[{status: success}]", wantSuccess: true, wantFail: false},
|
||||
{conf: "[{},{status: failure}]", wantSuccess: true, wantFail: true},
|
||||
{conf: "[{event: push, status: success},{status: failure}]", wantSuccess: false, wantFail: true},
|
||||
{conf: "[{status: failure},{event: push, status: success}]", wantSuccess: false, wantFail: true},
|
||||
}
|
||||
for _, test := range testdata {
|
||||
c := parseConstraints(t, test.conf)
|
||||
assert.Equal(t, test.wantSuccess, c.IncludesStatusSuccess(metadata.Metadata{Curr: metadata.Pipeline{Event: metadata.EventPull}}, true, map[string]string{}), "when: '%s'", test.conf)
|
||||
assert.Equal(t, test.wantFail, c.IncludesStatusFailure(metadata.Metadata{Curr: metadata.Pipeline{Event: metadata.EventPull}}, true, map[string]string{}), "when: '%s'", test.conf)
|
||||
t.Run(test.conf, func(t *testing.T) {
|
||||
c := parseConstraints(t, test.conf)
|
||||
assert.Equalf(t,
|
||||
test.wantSuccess,
|
||||
c.IncludesStatusSuccess(metadata.Metadata{Curr: metadata.Pipeline{Event: metadata.EventPull}}, true, map[string]string{}),
|
||||
"include success is wrong for when: '%s'", test.conf)
|
||||
assert.Equal(t,
|
||||
test.wantFail,
|
||||
c.IncludesStatusFailure(metadata.Metadata{Curr: metadata.Pipeline{Event: metadata.EventPull}}, true, map[string]string{}),
|
||||
"include fail is wrong for when: '%s'", test.conf)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +200,8 @@ func TestConstraints(t *testing.T) {
|
||||
}
|
||||
|
||||
func parseConstraints(t *testing.T, s string) *When {
|
||||
t.Helper()
|
||||
c := &When{}
|
||||
assert.NoError(t, yaml.Unmarshal([]byte(s), c))
|
||||
require.NoError(t, yaml.Unmarshal([]byte(s), c))
|
||||
return c
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user