Fail hard on deprecated pipeline keys (#2180)

so we can drop it in next minor version complete
This commit is contained in:
6543 2023-08-09 15:33:10 +02:00 committed by GitHub
parent 4bed647000
commit 71666f0500
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 22 deletions

View file

@ -5,6 +5,8 @@ Some versions need some changes to the server configuration or the pipeline conf
## next (1.1.0)
- Drop deprecated `CI_BUILD_*`, `CI_PREV_BUILD_*`, `CI_JOB_*`, `*_LINK`, `CI_SYSTEM_ARCH`, `CI_REPO_REMOTE` built-in environment variables
- Drop deprecated `pipeline:` keyword for steps in yaml config
- Drop deprecated `branches:` keyword for global branch filter
## 1.0.0

View file

@ -5,7 +5,6 @@ import (
"codeberg.org/6543/xyaml"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/constraint"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types"
)
@ -17,23 +16,15 @@ func ParseBytes(b []byte) (*types.Workflow, error) {
return nil, err
}
// support deprecated branch filter
// fail hard on deprecated branch filter
if out.BranchesDontUseIt != nil {
if out.When.Constraints == nil {
out.When.Constraints = []constraint.Constraint{{Branch: *out.BranchesDontUseIt}}
} else if len(out.When.Constraints) == 1 && out.When.Constraints[0].Branch.IsEmpty() {
out.When.Constraints[0].Branch = *out.BranchesDontUseIt
} else {
return nil, fmt.Errorf("could not apply deprecated branches filter into global when filter")
}
out.BranchesDontUseIt = nil
return nil, fmt.Errorf("\"branches:\" filter got removed, use \"branch\" in global when filter")
}
// support deprecated pipeline keyword
if len(out.PipelineDontUseIt.ContainerList) != 0 && len(out.Steps.ContainerList) == 0 {
out.Steps.ContainerList = out.PipelineDontUseIt.ContainerList
// fail hard on deprecated pipeline keyword
if len(out.PipelineDontUseIt.ContainerList) != 0 {
return nil, fmt.Errorf("\"pipeline:\" got removed, user \"steps:\"")
}
out.PipelineDontUseIt.ContainerList = nil
return out, nil
}

View file

@ -125,23 +125,27 @@ func TestParse(t *testing.T) {
}
func TestParseLegacy(t *testing.T) {
// adjust with https://github.com/woodpecker-ci/woodpecker/pull/2181
sampleYamlPipelineLegacy := `
pipeline:
platform: linux/amd64
labels:
platform: linux/arm64
steps:
say hello:
image: bash
commands: echo hello
`
sampleYamlPipelineLegacyIgnore := `
platform: linux/amd64
labels:
platform: linux/arm64
steps:
say hello:
image: bash
commands: echo hello
pipeline:
old crap:
image: bash
commands: meh!
`
workflow1, err := ParseString(sampleYamlPipelineLegacy)

View file

@ -290,7 +290,7 @@ steps:
}
}
func TestBranchFilter(t *testing.T) {
func TestRootWhenBranchFilter(t *testing.T) {
t.Parallel()
b := StepBuilder{
@ -307,7 +307,8 @@ func TestBranchFilter(t *testing.T) {
steps:
xxx:
image: scratch
branches: main
when:
branch: main
`)},
{Data: []byte(`
steps: