Skip to content

Commit

Permalink
Revert breaking pipeline changes (#2677)
Browse files Browse the repository at this point in the history
Revert #2180 and #2480 so we can release v2.0 without breaking changes
in pipeline config.

After merging #2476 we should apply these changes to a new v2.

After merging this, we should be ready for the 2.0 release.

---------

Co-authored-by: Anbraten <anton@ju60.de>
  • Loading branch information
qwerty287 and anbraten authored Nov 2, 2023
1 parent f270be4 commit c1faa95
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 6 deletions.
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 @@ func ParseBytes(b []byte) (*types.Workflow, error) {
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
}

// 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 in next major version
// Deprecated
BranchesDontUseIt *constraint.List `yaml:"branches,omitempty"` // TODO: remove in next major version
// Deprecated
PipelineDontUseIt ContainerList `yaml:"pipeline,omitempty"` // TODO: remove in next major version
}

// Workspace defines a pipeline workspace.
Expand Down
2 changes: 1 addition & 1 deletion pipeline/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"branches": { "$ref": "#/definitions/branches" },
"when": { "$ref": "#/definitions/pipeline_when" },
"steps": { "$ref": "#/definitions/step_list" },
"pipeline": { "$ref": "#/definitions/step_list", "description": "depricated, use steps" },
"pipeline": { "$ref": "#/definitions/step_list", "description": "deprecated, use steps" },
"services": { "$ref": "#/definitions/services" },
"workspace": { "$ref": "#/definitions/workspace" },
"matrix": { "$ref": "#/definitions/matrix" },
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

0 comments on commit c1faa95

Please sign in to comment.