mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-29 21:31:02 +00:00
Do not filter on linux/amd64 per default (#805)
* Do not filter on linux/amd64 per default & add tests Tasks with no platform would otherwise not perform on runners with different OS/ARCH combos Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at> Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
ecc25395aa
commit
a2315fe931
3 changed files with 102 additions and 3 deletions
|
@ -218,8 +218,5 @@ func (m *Metadata) Environ() map[string]string {
|
|||
var pullRegexp = regexp.MustCompile(`\d+`)
|
||||
|
||||
func (m *Metadata) SetPlatform(platform string) {
|
||||
if platform == "" {
|
||||
platform = "linux/amd64"
|
||||
}
|
||||
m.Sys.Arch = platform
|
||||
}
|
||||
|
|
|
@ -39,6 +39,11 @@ func createFilterFunc(filter rpc.Filter) (queue.Filter, error) {
|
|||
}
|
||||
|
||||
for k, v := range filter.Labels {
|
||||
// if platform is not set ignore that filter
|
||||
if k == "platform" && task.Labels[k] == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if task.Labels[k] != v {
|
||||
return false
|
||||
}
|
||||
|
|
97
server/grpc/filter_test.go
Normal file
97
server/grpc/filter_test.go
Normal file
|
@ -0,0 +1,97 @@
|
|||
// Copyright 2022 Woodpecker Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/woodpecker-ci/woodpecker/pipeline/rpc"
|
||||
"github.com/woodpecker-ci/woodpecker/server/queue"
|
||||
)
|
||||
|
||||
func TestCreateFilterFunc(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type filterTests struct {
|
||||
tsk queue.Task
|
||||
exp bool
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
struc rpc.Filter
|
||||
ft []filterTests
|
||||
}{{
|
||||
struc: rpc.Filter{},
|
||||
ft: []filterTests{{
|
||||
tsk: queue.Task{
|
||||
Labels: map[string]string{"platform": "", "repo": "test/woodpecker"},
|
||||
},
|
||||
exp: true,
|
||||
}, {
|
||||
tsk: queue.Task{
|
||||
Labels: map[string]string{"platform": ""},
|
||||
},
|
||||
exp: true,
|
||||
}},
|
||||
}, {
|
||||
struc: rpc.Filter{
|
||||
Labels: map[string]string{"platform": "abc"},
|
||||
},
|
||||
ft: []filterTests{{
|
||||
tsk: queue.Task{
|
||||
Labels: map[string]string{"platform": "def"},
|
||||
},
|
||||
exp: false,
|
||||
}, {
|
||||
tsk: queue.Task{
|
||||
Labels: map[string]string{"platform": ""},
|
||||
},
|
||||
exp: true,
|
||||
}},
|
||||
}, {
|
||||
struc: rpc.Filter{
|
||||
Expr: "platform = 'abc' OR repo = 'test/woodpecker'",
|
||||
},
|
||||
ft: []filterTests{{
|
||||
tsk: queue.Task{
|
||||
Labels: map[string]string{"platform": "", "repo": "test/woodpecker"},
|
||||
},
|
||||
exp: true,
|
||||
}, {
|
||||
tsk: queue.Task{
|
||||
Labels: map[string]string{"platform": "abc", "repo": "else"},
|
||||
},
|
||||
exp: true,
|
||||
}, {
|
||||
tsk: queue.Task{
|
||||
Labels: map[string]string{"platform": "also", "repo": "else"},
|
||||
},
|
||||
exp: false,
|
||||
}},
|
||||
}}
|
||||
|
||||
for _, test := range tests {
|
||||
fn, err := createFilterFunc(test.struc)
|
||||
if !assert.NoError(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
for _, ft := range test.ft {
|
||||
assert.EqualValues(t, ft.exp, fn(&ft.tsk))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue