Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert breaking pipeline changes #2677

Merged
merged 8 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/docs/91-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ Some versions need some changes to the server configuration or the pipeline conf
## next (2.0.0)

- Dropped deprecated `CI_BUILD_*`, `CI_PREV_BUILD_*`, `CI_JOB_*`, `*_LINK`, `CI_SYSTEM_ARCH`, `CI_REPO_REMOTE` built-in environment variables
- Dropped deprecated `pipeline:` keyword in favor of `steps:` in pipeline config
- Dropped deprecated `branches:` filter in favor of global [`when.branch`](./20-usage/20-workflow-syntax.md#branch-1) filter
- Deprecated `platform:` filter in favor of `labels:`, [read more](./20-usage/20-workflow-syntax.md#filter-by-platform)
- Secrets `event` property was renamed to `events` and `image` to `images` as both are lists. The new property `events` / `images` has to be used in the api and as cli argument. The old properties `event` and `image` were removed.
- The secrets `plugin_only` option was removed. Secrets with images are now always only available for plugins using listed by the `images` property. Existing secrets with a list of `images` will now only be available to the listed images if they are used as a plugin.
Expand Down
33 changes: 33 additions & 0 deletions pipeline/frontend/yaml/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
package yaml

import (
"fmt"

"codeberg.org/6543/xyaml"

"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/constraint"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types/base"
)

// ParseBytes parses the configuration from bytes b.
Expand All @@ -28,6 +32,35 @@
return nil, err
}

// support 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

Check warning on line 44 in pipeline/frontend/yaml/parse.go

View check run for this annotation

Codecov / codecov/patch

pipeline/frontend/yaml/parse.go#L37-L44

Added lines #L37 - L44 were not covered by tests
}

// support deprecated pipeline keyword
if len(out.PipelineDontUseIt.ContainerList) != 0 && len(out.Steps.ContainerList) == 0 {
out.Steps.ContainerList = out.PipelineDontUseIt.ContainerList
}

// support deprecated platform filter
if out.PlatformDontUseIt != "" {
if out.Labels == nil {
out.Labels = make(base.SliceOrMap)
}
if _, set := out.Labels["platform"]; !set {
out.Labels["platform"] = out.PlatformDontUseIt
}
out.PlatformDontUseIt = ""
}
out.PipelineDontUseIt.ContainerList = nil

return out, nil
}

Expand Down
42 changes: 42 additions & 0 deletions pipeline/frontend/yaml/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"testing"

"github.com/franela/goblin"
"github.com/stretchr/testify/assert"

"github.com/woodpecker-ci/woodpecker/pipeline/frontend/metadata"
yaml_base_types "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types/base"
Expand Down Expand Up @@ -137,6 +138,47 @@ func TestParse(t *testing.T) {
})
}

func TestParseLegacy(t *testing.T) {
sampleYamlPipelineLegacy := `
platform: linux/amd64

pipeline:
say hello:
image: bash
commands: echo hello
`

sampleYamlPipelineLegacyIgnore := `
platform: windows/amd64
labels:
platform: linux/amd64

steps:
say hello:
image: bash
commands: echo hello

pipeline:
old crap:
image: bash
commands: meh!
`

workflow1, err := ParseString(sampleYamlPipelineLegacy)
if !assert.NoError(t, err) {
t.Fail()
}

workflow2, err := ParseString(sampleYamlPipelineLegacyIgnore)
if !assert.NoError(t, err) {
t.Fail()
}

assert.EqualValues(t, workflow1, workflow2)
assert.Len(t, workflow1.Steps.ContainerList, 1)
assert.EqualValues(t, "say hello", workflow1.Steps.ContainerList[0].Name)
}

var sampleYaml = `
image: hello-world
when:
Expand Down
7 changes: 7 additions & 0 deletions pipeline/frontend/yaml/types/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ type (
Cache base.StringOrSlice `yaml:"cache,omitempty"`
Networks WorkflowNetworks `yaml:"networks,omitempty"`
Volumes WorkflowVolumes `yaml:"volumes,omitempty"`

// Deprecated
PlatformDontUseIt string `yaml:"platform,omitempty"` // TODO: remove after v1.2.x version
// Deprecated
BranchesDontUseIt *constraint.List `yaml:"branches,omitempty"` // TODO: remove after v1.1.x version
// Deprecated
PipelineDontUseIt ContainerList `yaml:"pipeline,omitempty"` // TODO: remove after v1.1.x version
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
}

// Workspace defines a pipeline workspace.
Expand Down
5 changes: 2 additions & 3 deletions pipeline/stepBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ steps:
}
}

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

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