From 1c7c87b8f05a093eca5d08927fd0701d33e7e6e7 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 23 Jul 2024 13:06:47 +0200 Subject: [PATCH] Remove deprecated pipeline settings (#3916) --- docs/docs/91-migrations.md | 1 + pipeline/frontend/yaml/linter/linter.go | 39 ---------- pipeline/frontend/yaml/linter/linter_test.go | 4 + .../.woodpecker/test-branches-array.yaml | 7 -- .../test-branches-exclude-include.yaml | 9 --- .../schema/.woodpecker/test-branches.yaml | 7 -- .../schema/.woodpecker/test-platform.yaml | 7 -- .../linter/schema/.woodpecker/test-when.yaml | 3 + .../frontend/yaml/linter/schema/schema.json | 76 ++----------------- .../yaml/linter/schema/schema_test.go | 16 ---- pipeline/frontend/yaml/parse.go | 34 --------- pipeline/frontend/yaml/parse_test.go | 9 ++- pipeline/frontend/yaml/types/workflow.go | 7 -- .../pipeline/stepbuilder/stepBuilder_test.go | 2 +- 14 files changed, 20 insertions(+), 201 deletions(-) delete mode 100644 pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches-array.yaml delete mode 100644 pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches-exclude-include.yaml delete mode 100644 pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches.yaml delete mode 100644 pipeline/frontend/yaml/linter/schema/.woodpecker/test-platform.yaml diff --git a/docs/docs/91-migrations.md b/docs/docs/91-migrations.md index 84a79ac5e..2b2336511 100644 --- a/docs/docs/91-migrations.md +++ b/docs/docs/91-migrations.md @@ -11,6 +11,7 @@ Some versions need some changes to the server configuration or the pipeline conf ## `next` +- Compatibility mode of deprecated `pipeline:`, `platform:` and `branches:` pipeline config options are now removed and pipeline will now fail if still in use. - Deprecated `steps.[name].group` in favor of `steps.[name].depends_on` (see [workflow syntax](./20-usage/20-workflow-syntax.md#depends_on) to learn how to set dependencies) - Removed `WOODPECKER_ROOT_PATH` and `WOODPECKER_ROOT_URL` config variables. Use `WOODPECKER_HOST` with a path instead - Pipelines without a config file will now be skipped instead of failing diff --git a/pipeline/frontend/yaml/linter/linter.go b/pipeline/frontend/yaml/linter/linter.go index 4abc03ba4..8305a9710 100644 --- a/pipeline/frontend/yaml/linter/linter.go +++ b/pipeline/frontend/yaml/linter/linter.go @@ -215,45 +215,6 @@ func (l *Linter) lintDeprecations(config *WorkflowConfig) (err error) { return err } - if parsed.PipelineDoNotUseIt.ContainerList != nil { - err = multierr.Append(err, &errorTypes.PipelineError{ - Type: errorTypes.PipelineErrorTypeDeprecation, - Message: "Please use 'steps:' instead of deprecated 'pipeline:' list", - Data: errors.DeprecationErrorData{ - File: config.File, - Field: "pipeline", - Docs: "https://woodpecker-ci.org/docs/next/migrations#next-200", - }, - IsWarning: true, - }) - } - - if parsed.PlatformDoNotUseIt != "" { - err = multierr.Append(err, &errorTypes.PipelineError{ - Type: errorTypes.PipelineErrorTypeDeprecation, - Message: "Please use labels instead of deprecated 'platform' filters", - Data: errors.DeprecationErrorData{ - File: config.File, - Field: "platform", - Docs: "https://woodpecker-ci.org/docs/next/migrations#next-200", - }, - IsWarning: true, - }) - } - - if parsed.BranchesDoNotUseIt != nil { - err = multierr.Append(err, &errorTypes.PipelineError{ - Type: errorTypes.PipelineErrorTypeDeprecation, - Message: "Please use global when instead of deprecated 'branches' filter", - Data: errors.DeprecationErrorData{ - File: config.File, - Field: "branches", - Docs: "https://woodpecker-ci.org/docs/next/migrations#next-200", - }, - IsWarning: true, - }) - } - for _, step := range parsed.Steps.ContainerList { if step.Group != "" { err = multierr.Append(err, &errorTypes.PipelineError{ diff --git a/pipeline/frontend/yaml/linter/linter_test.go b/pipeline/frontend/yaml/linter/linter_test.go index 5f73d89ac..2a4a891ec 100644 --- a/pipeline/frontend/yaml/linter/linter_test.go +++ b/pipeline/frontend/yaml/linter/linter_test.go @@ -165,6 +165,10 @@ func TestLintErrors(t *testing.T) { from: "steps: { build: { image: golang, settings: { test: 'true' }, environment: [ 'TEST=true' ] } }", want: "Cannot configure both environment and settings", }, + { + from: "{pipeline: { build: { image: golang, settings: { test: 'true' } } }, when: { branch: main, event: push } }", + want: "Additional property pipeline is not allowed", + }, } for _, test := range testdata { diff --git a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches-array.yaml b/pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches-array.yaml deleted file mode 100644 index d530db055..000000000 --- a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches-array.yaml +++ /dev/null @@ -1,7 +0,0 @@ -branches: [main, pages] - -steps: - build: - image: golang - commands: - - go test diff --git a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches-exclude-include.yaml b/pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches-exclude-include.yaml deleted file mode 100644 index 03b534d23..000000000 --- a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches-exclude-include.yaml +++ /dev/null @@ -1,9 +0,0 @@ -branches: - include: main - exclude: [develop, feature/*] - -steps: - build: - image: golang - commands: - - go test diff --git a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches.yaml b/pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches.yaml deleted file mode 100644 index 75b72bbcf..000000000 --- a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-branches.yaml +++ /dev/null @@ -1,7 +0,0 @@ -branches: main - -steps: - build: - image: golang - commands: - - go test diff --git a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-platform.yaml b/pipeline/frontend/yaml/linter/schema/.woodpecker/test-platform.yaml deleted file mode 100644 index 7b4abf027..000000000 --- a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-platform.yaml +++ /dev/null @@ -1,7 +0,0 @@ -platform: linux/amd64 - -steps: - build: - image: golang:latest - commands: - - go test diff --git a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-when.yaml b/pipeline/frontend/yaml/linter/schema/.woodpecker/test-when.yaml index b08385a77..1e163e854 100644 --- a/pipeline/frontend/yaml/linter/schema/.woodpecker/test-when.yaml +++ b/pipeline/frontend/yaml/linter/schema/.woodpecker/test-when.yaml @@ -19,6 +19,9 @@ steps: - echo "test" when: event: push + branch: + include: main + exclude: [develop, feature/*] when-event-array: image: alpine diff --git a/pipeline/frontend/yaml/linter/schema/schema.json b/pipeline/frontend/yaml/linter/schema/schema.json index 5a85cf320..891bc9324 100644 --- a/pipeline/frontend/yaml/linter/schema/schema.json +++ b/pipeline/frontend/yaml/linter/schema/schema.json @@ -20,19 +20,12 @@ "skip_clone": { "type": "boolean" }, - "branches": { - "$ref": "#/definitions/branches" - }, "when": { - "$ref": "#/definitions/pipeline_when" + "$ref": "#/definitions/workflow_when" }, "steps": { "$ref": "#/definitions/step_list" }, - "pipeline": { - "$ref": "#/definitions/step_list", - "description": "deprecated, use steps" - }, "services": { "$ref": "#/definitions/services" }, @@ -42,9 +35,6 @@ "matrix": { "$ref": "#/definitions/matrix" }, - "platform": { - "$ref": "#/definitions/platform" - }, "labels": { "$ref": "#/definitions/labels" }, @@ -128,55 +118,6 @@ "type": ["boolean", "string", "number", "array", "object"] } }, - "branches": { - "description": "deprecated, use when.branch", - "oneOf": [ - { - "type": "array", - "items": { - "type": "string" - }, - "minProperties": 1 - }, - { - "type": "string" - }, - { - "type": "object", - "additionalProperties": false, - "properties": { - "exclude": { - "oneOf": [ - { - "type": "array", - "items": { - "type": "string" - }, - "minLength": 1 - }, - { - "type": "string" - } - ] - }, - "include": { - "oneOf": [ - { - "type": "array", - "items": { - "type": "string" - }, - "minLength": 1 - }, - { - "type": "string" - } - ] - } - } - } - ] - }, "step_list": { "description": "The steps section defines a list of steps which will be executed serially, in the order in which they are defined. Read more: https://woodpecker-ci.org/docs/usage/workflow-syntax#steps", "oneOf": [ @@ -196,22 +137,22 @@ } ] }, - "pipeline_when": { - "description": "Whole pipelines can be skipped based on conditions. Read more: https://woodpecker-ci.org/docs/usage/workflow-syntax#when---global-workflow-conditions", + "workflow_when": { + "description": "Whole workflow can be skipped based on conditions. Read more: https://woodpecker-ci.org/docs/usage/workflow-syntax#when---global-workflow-conditions", "oneOf": [ { "type": "array", "minLength": 1, "items": { - "$ref": "#/definitions/pipeline_when_condition" + "$ref": "#/definitions/workflow_when_condition" } }, { - "$ref": "#/definitions/pipeline_when_condition" + "$ref": "#/definitions/workflow_when_condition" } ] }, - "pipeline_when_condition": { + "workflow_when_condition": { "type": "object", "additionalProperties": false, "properties": { @@ -1120,11 +1061,6 @@ "minLength": 1 } }, - "platform": { - "description": "deprecated, use labels.platform", - "type": "string", - "additionalProperties": false - }, "labels": { "description": "Configures the labels used for the agent selection. Read more: https://woodpecker-ci.org/docs/usage/workflow-syntax#labels", "type": "object", diff --git a/pipeline/frontend/yaml/linter/schema/schema_test.go b/pipeline/frontend/yaml/linter/schema/schema_test.go index be5dfe2ae..2a5526e24 100644 --- a/pipeline/frontend/yaml/linter/schema/schema_test.go +++ b/pipeline/frontend/yaml/linter/schema/schema_test.go @@ -32,18 +32,6 @@ func TestSchema(t *testing.T) { testFile string fail bool }{ - { - name: "Branches", - testFile: ".woodpecker/test-branches.yaml", - }, - { - name: "Branches Array", - testFile: ".woodpecker/test-branches-array.yaml", - }, - { - name: "Branches exclude & include", - testFile: ".woodpecker/test-branches-exclude-include.yaml", - }, { name: "Clone", testFile: ".woodpecker/test-clone.yaml", @@ -84,10 +72,6 @@ func TestSchema(t *testing.T) { name: "Workspace", testFile: ".woodpecker/test-workspace.yaml", }, - { - name: "Platform", - testFile: ".woodpecker/test-platform.yaml", - }, { name: "Labels", testFile: ".woodpecker/test-labels.yaml", diff --git a/pipeline/frontend/yaml/parse.go b/pipeline/frontend/yaml/parse.go index 8607dd537..e9a6255fe 100644 --- a/pipeline/frontend/yaml/parse.go +++ b/pipeline/frontend/yaml/parse.go @@ -15,11 +15,8 @@ package yaml import ( - "fmt" - "codeberg.org/6543/xyaml" - "go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/constraint" "go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/types" ) @@ -30,37 +27,6 @@ func ParseBytes(b []byte) (*types.Workflow, error) { if err != nil { return nil, err } - - // support deprecated branch filter - if out.BranchesDoNotUseIt != nil { - switch { - case out.When.Constraints == nil: - out.When.Constraints = []constraint.Constraint{{Branch: *out.BranchesDoNotUseIt}} - case len(out.When.Constraints) == 1 && out.When.Constraints[0].Branch.IsEmpty(): - out.When.Constraints[0].Branch = *out.BranchesDoNotUseIt - default: - return nil, fmt.Errorf("could not apply deprecated branches filter into global when filter") - } - out.BranchesDoNotUseIt = nil - } - - // support deprecated pipeline keyword - if len(out.PipelineDoNotUseIt.ContainerList) != 0 && len(out.Steps.ContainerList) == 0 { - out.Steps.ContainerList = out.PipelineDoNotUseIt.ContainerList - } - - // support deprecated platform filter - if out.PlatformDoNotUseIt != "" { - if out.Labels == nil { - out.Labels = make(map[string]string) - } - if _, set := out.Labels["platform"]; !set { - out.Labels["platform"] = out.PlatformDoNotUseIt - } - out.PlatformDoNotUseIt = "" - } - out.PipelineDoNotUseIt.ContainerList = nil - return out, nil } diff --git a/pipeline/frontend/yaml/parse_test.go b/pipeline/frontend/yaml/parse_test.go index 5402cd03c..fdd91f767 100644 --- a/pipeline/frontend/yaml/parse_test.go +++ b/pipeline/frontend/yaml/parse_test.go @@ -139,10 +139,11 @@ func TestParse(t *testing.T) { } func TestParseLegacy(t *testing.T) { - sampleYamlPipelineLegacy := ` -platform: linux/amd64 + sampleYamlPipeline := ` +labels: + platform: linux/amd64 -pipeline: +steps: say hello: image: bash commands: echo hello @@ -164,7 +165,7 @@ pipeline: commands: meh! ` - workflow1, err := ParseString(sampleYamlPipelineLegacy) + workflow1, err := ParseString(sampleYamlPipeline) if !assert.NoError(t, err) { return } diff --git a/pipeline/frontend/yaml/types/workflow.go b/pipeline/frontend/yaml/types/workflow.go index 4f291dec3..f1e753b3d 100644 --- a/pipeline/frontend/yaml/types/workflow.go +++ b/pipeline/frontend/yaml/types/workflow.go @@ -34,13 +34,6 @@ type ( // Undocumented Networks WorkflowNetworks `yaml:"networks,omitempty"` Volumes WorkflowVolumes `yaml:"volumes,omitempty"` - - // Deprecated - PlatformDoNotUseIt string `yaml:"platform,omitempty"` // TODO: remove in next major version - // Deprecated - BranchesDoNotUseIt *constraint.List `yaml:"branches,omitempty"` // TODO: remove in next major version - // Deprecated - PipelineDoNotUseIt ContainerList `yaml:"pipeline,omitempty"` // TODO: remove in next major version } // Workspace defines a pipeline workspace. diff --git a/server/pipeline/stepbuilder/stepBuilder_test.go b/server/pipeline/stepbuilder/stepBuilder_test.go index 98cb79129..ae86ba35f 100644 --- a/server/pipeline/stepbuilder/stepBuilder_test.go +++ b/server/pipeline/stepbuilder/stepBuilder_test.go @@ -348,10 +348,10 @@ func TestBranchFilter(t *testing.T) { {Data: []byte(` when: event: push + branch: main steps: xxx: image: scratch -branches: main `)}, {Data: []byte(` when: