Drop VarArgs in steps in favour of settings (#919)

* drop VarArgs in steps in favour of settings
* update unit tests
This commit is contained in:
6543 2022-05-17 16:43:05 +02:00 committed by GitHub
parent eb2118e451
commit 4136df7551
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 26 deletions

View file

@ -60,8 +60,6 @@ type (
Sysctls types.SliceorMap `yaml:"sysctls,omitempty"` Sysctls types.SliceorMap `yaml:"sysctls,omitempty"`
Constraints constraint.Constraints `yaml:"when,omitempty"` Constraints constraint.Constraints `yaml:"when,omitempty"`
Settings map[string]interface{} `yaml:"settings"` Settings map[string]interface{} `yaml:"settings"`
// Deprecated
Vargs map[string]interface{} `yaml:",inline"` // TODO: remove deprecated with v0.16.0
} }
) )
@ -84,20 +82,10 @@ func (c *Containers) UnmarshalYAML(value *yaml.Node) error {
if container.Name == "" { if container.Name == "" {
container.Name = fmt.Sprintf("%v", value.Content[i-1].Value) container.Name = fmt.Sprintf("%v", value.Content[i-1].Value)
} }
c.Containers = append(c.Containers, &container) c.Containers = append(c.Containers, &container)
} }
} }
// TODO drop Vargs in favor of Settings in v0.16.0 release
for _, cc := range c.Containers {
if cc.Settings == nil && cc.Vargs != nil {
cc.Settings = make(map[string]interface{})
}
for k, v := range cc.Vargs {
cc.Settings[k] = v
}
cc.Vargs = nil
}
return nil return nil
} }

View file

@ -62,7 +62,6 @@ when:
settings: settings:
foo: bar foo: bar
baz: false baz: false
deprecated_setting: fallback
`) `)
func TestUnmarshalContainer(t *testing.T) { func TestUnmarshalContainer(t *testing.T) {
@ -119,9 +118,6 @@ func TestUnmarshalContainer(t *testing.T) {
"foo": "bar", "foo": "bar",
"baz": false, "baz": false,
}, },
Vargs: map[string]interface{}{
"deprecated_setting": "fallback",
},
} }
got := Container{} got := Container{}
err := yaml.Unmarshal(containerYaml, &got) err := yaml.Unmarshal(containerYaml, &got)
@ -147,14 +143,13 @@ func TestUnmarshalContainers(t *testing.T) {
}, },
}, },
{ {
from: "test: { name: unit_test, image: node, deprecated_setting: fallback, settings: { normal_setting: true } }", from: "test: { name: unit_test, image: node, settings: { normal_setting: true } }",
want: []*Container{ want: []*Container{
{ {
Name: "unit_test", Name: "unit_test",
Image: "node", Image: "node",
Settings: map[string]interface{}{ Settings: map[string]interface{}{
"deprecated_setting": "fallback", "normal_setting": true,
"normal_setting": true,
}, },
}, },
}, },
@ -163,11 +158,12 @@ func TestUnmarshalContainers(t *testing.T) {
from: `publish-agent: from: `publish-agent:
group: bundle group: bundle
image: print/env image: print/env
repo: woodpeckerci/woodpecker-agent settings:
dockerfile: docker/Dockerfile.agent repo: woodpeckerci/woodpecker-agent
dry_run: true
dockerfile: docker/Dockerfile.agent
tag: [next, latest]
secrets: [docker_username, docker_password] secrets: [docker_username, docker_password]
tag: [next, latest]
dry_run: true
when: when:
branch: ${CI_REPO_DEFAULT_BRANCH} branch: ${CI_REPO_DEFAULT_BRANCH}
event: push`, event: push`,

View file

@ -41,8 +41,8 @@ pipeline:
secrets: secrets:
image: docker image: docker
commands: commands:
- echo $DOCKER_USERNAME - echo $DOCKER_USERNAME
- echo $DOCKER_PASSWORD - echo $DOCKER_PASSWORD
secrets: secrets:
- docker_username - docker_username
- source: docker_prod_password - source: docker_prod_password