From 5d1acc330da937df6a1b4546aa6c4f491e59c4dd Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Tue, 31 Oct 2023 13:23:08 +0100 Subject: [PATCH 1/4] Revert "Remove deprecated options parsing (#2480)" This reverts commit 842e8a8e50980106563aba61842cc9a34052896f. --- pipeline/frontend/yaml/parse.go | 24 +++++++++++++++ pipeline/frontend/yaml/parse_test.go | 37 ++++++++++++++++++++++++ pipeline/frontend/yaml/types/workflow.go | 7 +++++ 3 files changed, 68 insertions(+) diff --git a/pipeline/frontend/yaml/parse.go b/pipeline/frontend/yaml/parse.go index eaba5946dfe..78457dad78a 100644 --- a/pipeline/frontend/yaml/parse.go +++ b/pipeline/frontend/yaml/parse.go @@ -15,9 +15,12 @@ package yaml import ( + "fmt" + "codeberg.org/6543/xyaml" "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. @@ -28,6 +31,27 @@ func ParseBytes(b []byte) (*types.Workflow, error) { return nil, err } + // fail hard on deprecated branch filter + if out.BranchesDontUseIt != nil { + return nil, fmt.Errorf("\"branches:\" filter got removed, use \"branch\" in global when filter instead") + } + + // fail hard on deprecated pipeline keyword + if len(out.PipelineDontUseIt.ContainerList) != 0 { + return nil, fmt.Errorf("\"pipeline:\" got removed, use \"steps:\" instead") + } + + // 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 = "" + } + return out, nil } diff --git a/pipeline/frontend/yaml/parse_test.go b/pipeline/frontend/yaml/parse_test.go index cdb18e7e866..da5d75821b1 100644 --- a/pipeline/frontend/yaml/parse_test.go +++ b/pipeline/frontend/yaml/parse_test.go @@ -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" @@ -137,6 +138,42 @@ func TestParse(t *testing.T) { }) } +func TestParseLegacy(t *testing.T) { + sampleYamlPipelineLegacy := ` +platform: linux/amd64 + +steps: + say hello: + image: bash + commands: echo hello +` + + sampleYamlPipelineLegacyIgnore := ` +platform: windows/amd64 +labels: + platform: linux/amd64 + +steps: + say hello: + image: bash + commands: echo hello +` + + 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: diff --git a/pipeline/frontend/yaml/types/workflow.go b/pipeline/frontend/yaml/types/workflow.go index eda777df883..fd3afcf924f 100644 --- a/pipeline/frontend/yaml/types/workflow.go +++ b/pipeline/frontend/yaml/types/workflow.go @@ -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 } // Workspace defines a pipeline workspace. From 7793a7b0ac1bbcd03f2a4754120c02396ef6b3c5 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Tue, 31 Oct 2023 13:26:59 +0100 Subject: [PATCH 2/4] Revert "Fail hard on deprecated pipeline keys (#2180)" This reverts commit 71666f050062c6b4da78ab0e6553c2a1d38f3610. --- docs/docs/91-migrations.md | 2 -- pipeline/frontend/yaml/parse.go | 19 ++++++++++++++----- pipeline/frontend/yaml/parse_test.go | 7 ++++++- pipeline/stepBuilder_test.go | 5 ++--- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/docs/docs/91-migrations.md b/docs/docs/91-migrations.md index 63f00aef968..93aee0012d3 100644 --- a/docs/docs/91-migrations.md +++ b/docs/docs/91-migrations.md @@ -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. diff --git a/pipeline/frontend/yaml/parse.go b/pipeline/frontend/yaml/parse.go index 78457dad78a..ae01c0c5fac 100644 --- a/pipeline/frontend/yaml/parse.go +++ b/pipeline/frontend/yaml/parse.go @@ -19,6 +19,7 @@ import ( "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" ) @@ -31,14 +32,21 @@ func ParseBytes(b []byte) (*types.Workflow, error) { return nil, err } - // fail hard on deprecated branch filter + // support deprecated branch filter if out.BranchesDontUseIt != nil { - return nil, fmt.Errorf("\"branches:\" filter got removed, use \"branch\" in global when filter instead") + 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 } - // fail hard on deprecated pipeline keyword - if len(out.PipelineDontUseIt.ContainerList) != 0 { - return nil, fmt.Errorf("\"pipeline:\" got removed, use \"steps:\" instead") + // 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 @@ -51,6 +59,7 @@ func ParseBytes(b []byte) (*types.Workflow, error) { } out.PlatformDontUseIt = "" } + out.PipelineDontUseIt.ContainerList = nil return out, nil } diff --git a/pipeline/frontend/yaml/parse_test.go b/pipeline/frontend/yaml/parse_test.go index da5d75821b1..2628dab8c18 100644 --- a/pipeline/frontend/yaml/parse_test.go +++ b/pipeline/frontend/yaml/parse_test.go @@ -142,7 +142,7 @@ func TestParseLegacy(t *testing.T) { sampleYamlPipelineLegacy := ` platform: linux/amd64 -steps: +pipeline: say hello: image: bash commands: echo hello @@ -157,6 +157,11 @@ steps: say hello: image: bash commands: echo hello + +pipeline: + old crap: + image: bash + commands: meh! ` workflow1, err := ParseString(sampleYamlPipelineLegacy) diff --git a/pipeline/stepBuilder_test.go b/pipeline/stepBuilder_test.go index c8ad8181496..2b9d1c4d42c 100644 --- a/pipeline/stepBuilder_test.go +++ b/pipeline/stepBuilder_test.go @@ -290,7 +290,7 @@ steps: } } -func TestRootWhenBranchFilter(t *testing.T) { +func TestBranchFilter(t *testing.T) { t.Parallel() b := StepBuilder{ @@ -307,8 +307,7 @@ func TestRootWhenBranchFilter(t *testing.T) { steps: xxx: image: scratch -when: - branch: main +branches: main `)}, {Data: []byte(` steps: From 85653e6f35931f8c1d37c1d93e2e40287f220a45 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Thu, 2 Nov 2023 08:57:36 +0100 Subject: [PATCH 3/4] Update pipeline/frontend/yaml/types/workflow.go Co-authored-by: Anbraten --- pipeline/frontend/yaml/types/workflow.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pipeline/frontend/yaml/types/workflow.go b/pipeline/frontend/yaml/types/workflow.go index fd3afcf924f..9c397e6c122 100644 --- a/pipeline/frontend/yaml/types/workflow.go +++ b/pipeline/frontend/yaml/types/workflow.go @@ -38,11 +38,11 @@ type ( Volumes WorkflowVolumes `yaml:"volumes,omitempty"` // Deprecated - PlatformDontUseIt string `yaml:"platform,omitempty"` // TODO: remove after v1.2.x version + PlatformDontUseIt string `yaml:"platform,omitempty"` // TODO: remove in next major version // Deprecated - BranchesDontUseIt *constraint.List `yaml:"branches,omitempty"` // TODO: remove after v1.1.x version + BranchesDontUseIt *constraint.List `yaml:"branches,omitempty"` // TODO: remove in next major version // Deprecated - PipelineDontUseIt ContainerList `yaml:"pipeline,omitempty"` // TODO: remove after v1.1.x version + PipelineDontUseIt ContainerList `yaml:"pipeline,omitempty"` // TODO: remove in next major version } // Workspace defines a pipeline workspace. From e2c318d55af586cd0d390d2447268dd29210e850 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Thu, 2 Nov 2023 09:08:02 +0100 Subject: [PATCH 4/4] fix typo --- pipeline/schema/schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline/schema/schema.json b/pipeline/schema/schema.json index 9c37bf1929a..1a33688da52 100644 --- a/pipeline/schema/schema.json +++ b/pipeline/schema/schema.json @@ -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" },