Skip to content

Commit

Permalink
Fail hard on deprecated pipeline keys (#2180)
Browse files Browse the repository at this point in the history
so we can drop it in next minor version complete
  • Loading branch information
6543 authored Aug 9, 2023
1 parent 4bed647 commit 71666f0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
2 changes: 2 additions & 0 deletions docs/docs/91-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 5 additions & 14 deletions pipeline/frontend/yaml/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
Expand Down
16 changes: 10 additions & 6 deletions pipeline/frontend/yaml/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions pipeline/stepBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ steps:
}
}

func TestBranchFilter(t *testing.T) {
func TestRootWhenBranchFilter(t *testing.T) {
t.Parallel()

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

0 comments on commit 71666f0

Please sign in to comment.