From a98a808355fdf59bb233b81ad03c34a1d06d7b8f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 6 Jun 2023 16:51:16 +0200 Subject: [PATCH 01/12] WIP: add version to workflow configs --- pipeline/frontend/yaml/error.go | 4 ++++ pipeline/frontend/yaml/parse.go | 30 ++++++++++++++++++++++-- pipeline/frontend/yaml/types/workflow.go | 1 + pipeline/frontend/yaml/version.go | 18 ++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 pipeline/frontend/yaml/version.go diff --git a/pipeline/frontend/yaml/error.go b/pipeline/frontend/yaml/error.go index 26600c636e..5fa6e7c022 100644 --- a/pipeline/frontend/yaml/error.go +++ b/pipeline/frontend/yaml/error.go @@ -16,6 +16,10 @@ package yaml import "errors" +var ( + ErrUnsuportedVersion = errors.New("unsuported yaml version detected") +) + // PipelineParseError is an error that occurs when the pipeline parsing fails. type PipelineParseError struct { Err error diff --git a/pipeline/frontend/yaml/parse.go b/pipeline/frontend/yaml/parse.go index 947f7410a1..5585bb2fbe 100644 --- a/pipeline/frontend/yaml/parse.go +++ b/pipeline/frontend/yaml/parse.go @@ -4,19 +4,29 @@ import ( "fmt" "codeberg.org/6543/xyaml" + "gopkg.in/yaml.v3" + "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml" "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/constraint" "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types" ) // ParseBytes parses the configuration from bytes b. func ParseBytes(b []byte) (*types.Workflow, error) { + yamlVersion, err := checkVersion(b) + if err != nil { + &PipelineParseError{Err: err} + } + out := new(types.Workflow) err := xyaml.Unmarshal(b, out) if err != nil { - return nil, err + return nil, &PipelineParseError{Err: err} } + // make sure detected version is set + out.Version = yamlVersion + // support deprecated branch filter if out.BranchesDontUseIt != nil { if out.When.Constraints == nil { @@ -24,7 +34,7 @@ func ParseBytes(b []byte) (*types.Workflow, error) { } 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") + return nil, &PipelineParseError{Err: fmt.Errorf("could not apply deprecated branches filter into global when filter")} } out.BranchesDontUseIt = nil } @@ -38,3 +48,19 @@ func ParseString(s string) (*types.Workflow, error) { []byte(s), ) } + +func checkVersion(b []byte) (string, error) { + verStr := struct { + Version string `yaml:"version"` + }{} + _ = yaml.Unmarshal(b, &verStr) + // TODO: should we require a version number -> in therms of UX we should not, in terms of strong typisation we should + if verStr == "" { + verStr = Version + } + + if verStr != Version { + return "", ErrUnsuportedVersion + } + return verStr, nil +} diff --git a/pipeline/frontend/yaml/types/workflow.go b/pipeline/frontend/yaml/types/workflow.go index aaf9837813..49cd090146 100644 --- a/pipeline/frontend/yaml/types/workflow.go +++ b/pipeline/frontend/yaml/types/workflow.go @@ -18,6 +18,7 @@ type ( DependsOn []string `yaml:"depends_on,omitempty"` RunsOn []string `yaml:"runs_on,omitempty"` SkipClone bool `yaml:"skip_clone"` + Version string `yaml:"version"` // Undocumented Cache base.StringOrSlice `yaml:"cache,omitempty"` Networks WorkflowNetworks `yaml:"networks,omitempty"` diff --git a/pipeline/frontend/yaml/version.go b/pipeline/frontend/yaml/version.go new file mode 100644 index 0000000000..cbf1b3eb00 --- /dev/null +++ b/pipeline/frontend/yaml/version.go @@ -0,0 +1,18 @@ +// Copyright 2022 Woodpecker Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package yaml + +// Version of this package and it's subpackages +const Version = "1" From 84f72ad985539b3e3e6b21018ca24fb10d63cb11 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Tue, 19 Sep 2023 18:20:01 +0200 Subject: [PATCH 02/12] Update pipeline/frontend/yaml/error.go Co-authored-by: Anbraten --- pipeline/frontend/yaml/error.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pipeline/frontend/yaml/error.go b/pipeline/frontend/yaml/error.go index 01bc14a204..afde72084c 100644 --- a/pipeline/frontend/yaml/error.go +++ b/pipeline/frontend/yaml/error.go @@ -17,8 +17,8 @@ package yaml import "errors" var ( - ErrUnsuportedVersion = errors.New("unsuported yaml version detected") - ErrMissingVersion = errors.New("missing yaml version") + ErrUnsuportedVersion = errors.New("unsuported pipeline config version detected") + ErrMissingVersion = errors.New("missing pipeline config version") ) // PipelineParseError is an error that occurs when the pipeline parsing fails. From 01ff70b33b6bf8a7b99a619493684a54a6dbdcd1 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Tue, 19 Sep 2023 18:32:30 +0200 Subject: [PATCH 03/12] fix tests --- pipeline/frontend/yaml/linter/linter_test.go | 5 +++- pipeline/frontend/yaml/parse_test.go | 4 +++ pipeline/stepBuilder_test.go | 26 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pipeline/frontend/yaml/linter/linter_test.go b/pipeline/frontend/yaml/linter/linter_test.go index 6ffdffdef9..c526640ae2 100644 --- a/pipeline/frontend/yaml/linter/linter_test.go +++ b/pipeline/frontend/yaml/linter/linter_test.go @@ -23,6 +23,7 @@ import ( func TestLint(t *testing.T) { testdatas := []struct{ Title, Data string }{{ Title: "map", Data: ` +version: 1 steps: build: image: docker @@ -44,6 +45,7 @@ services: `, }, { Title: "list", Data: ` +version: 1 steps: - name: build image: docker @@ -62,6 +64,7 @@ steps: `, }, { Title: "merge maps", Data: ` +version: 1 variables: step_template: &base-step image: golang:1.19 @@ -151,7 +154,7 @@ func TestLintErrors(t *testing.T) { } for _, test := range testdata { - conf, err := yaml.ParseString(test.from) + conf, err := yaml.ParseString("version: 1\n"+test.from) if err != nil { t.Fatalf("Cannot unmarshal yaml %q. Error: %s", test.from, err) } diff --git a/pipeline/frontend/yaml/parse_test.go b/pipeline/frontend/yaml/parse_test.go index 0812ee8760..2d421fe979 100644 --- a/pipeline/frontend/yaml/parse_test.go +++ b/pipeline/frontend/yaml/parse_test.go @@ -140,6 +140,7 @@ func TestParse(t *testing.T) { func TestParseLegacy(t *testing.T) { sampleYamlPipelineLegacy := ` +version: 1 platform: linux/amd64 steps: @@ -149,6 +150,7 @@ steps: ` sampleYamlPipelineLegacyIgnore := ` +version: 1 platform: windows/amd64 labels: platform: linux/amd64 @@ -228,6 +230,7 @@ runs_on: ` var simpleYamlAnchors = ` +version: 1 vars: image: &image plugins/slack steps: @@ -236,6 +239,7 @@ steps: ` var sampleVarYaml = ` +version: 1 _slack: &SLACK image: plugins/slack steps: diff --git a/pipeline/stepBuilder_test.go b/pipeline/stepBuilder_test.go index f875f59d32..41be374da9 100644 --- a/pipeline/stepBuilder_test.go +++ b/pipeline/stepBuilder_test.go @@ -47,6 +47,7 @@ func TestGlobalEnvsubst(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Data: []byte(` +version: 1 steps: build: image: ${IMAGE} @@ -82,6 +83,7 @@ func TestMissingGlobalEnvsubst(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Data: []byte(` +version: 1 steps: build: image: ${IMAGE} @@ -114,12 +116,14 @@ bbb`, Link: "", Yamls: []*forge_types.FileMeta{ {Data: []byte(` +version: 1 steps: xxx: image: scratch yyy: ${CI_COMMIT_MESSAGE} `)}, {Data: []byte(` +version: 1 steps: build: image: scratch @@ -149,11 +153,13 @@ func TestMultiPipeline(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Data: []byte(` +version: 1 steps: xxx: image: scratch `)}, {Data: []byte(` +version: 1 steps: build: image: scratch @@ -184,16 +190,19 @@ func TestDependsOn(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Name: "lint", Data: []byte(` +version: 1 steps: build: image: scratch `)}, {Name: "test", Data: []byte(` +version: 1 steps: build: image: scratch `)}, {Data: []byte(` +version: 1 steps: deploy: image: scratch @@ -231,6 +240,7 @@ func TestRunsOn(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Data: []byte(` +version: 1 steps: deploy: image: scratch @@ -268,11 +278,13 @@ func TestPipelineName(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Name: ".woodpecker/lint.yml", Data: []byte(` +version: 1 steps: build: image: scratch `)}, {Name: ".woodpecker/.test.yml", Data: []byte(` +version: 1 steps: build: image: scratch @@ -304,6 +316,7 @@ func TestRootWhenBranchFilter(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Data: []byte(` +version: 1 steps: xxx: image: scratch @@ -311,6 +324,7 @@ when: branch: main `)}, {Data: []byte(` +version: 1 steps: build: image: scratch @@ -344,6 +358,7 @@ func TestRootWhenFilter(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Data: []byte(` +version: 1 when: event: - tester @@ -352,6 +367,7 @@ steps: image: scratch `)}, {Data: []byte(` +version: 1 when: event: - push @@ -360,6 +376,7 @@ steps: image: scratch `)}, {Data: []byte(` +version: 1 steps: build: image: scratch @@ -393,6 +410,7 @@ func TestZeroSteps(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Data: []byte(` +version: 1 skip_clone: true steps: build: @@ -428,6 +446,7 @@ func TestZeroStepsAsMultiPipelineDeps(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Name: "zerostep", Data: []byte(` +version: 1 skip_clone: true steps: build: @@ -436,11 +455,13 @@ steps: image: scratch `)}, {Name: "justastep", Data: []byte(` +version: 1 steps: build: image: scratch `)}, {Name: "shouldbefiltered", Data: []byte(` +version: 1 steps: build: image: scratch @@ -477,6 +498,7 @@ func TestZeroStepsAsMultiPipelineTransitiveDeps(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Name: "zerostep", Data: []byte(` +version: 1 skip_clone: true steps: build: @@ -485,17 +507,20 @@ steps: image: scratch `)}, {Name: "justastep", Data: []byte(` +version: 1 steps: build: image: scratch `)}, {Name: "shouldbefiltered", Data: []byte(` +version: 1 steps: build: image: scratch depends_on: [ zerostep ] `)}, {Name: "shouldbefilteredtoo", Data: []byte(` +version: 1 steps: build: image: scratch @@ -534,6 +559,7 @@ func TestTree(t *testing.T) { Link: "", Yamls: []*forge_types.FileMeta{ {Data: []byte(` +version: 1 steps: build: image: scratch From 8e9379c81a0c704ba63f3127e0f47313e96daabf Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Tue, 19 Sep 2023 18:32:41 +0200 Subject: [PATCH 04/12] format --- pipeline/frontend/yaml/linter/linter_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline/frontend/yaml/linter/linter_test.go b/pipeline/frontend/yaml/linter/linter_test.go index c526640ae2..c7db954ccd 100644 --- a/pipeline/frontend/yaml/linter/linter_test.go +++ b/pipeline/frontend/yaml/linter/linter_test.go @@ -154,7 +154,7 @@ func TestLintErrors(t *testing.T) { } for _, test := range testdata { - conf, err := yaml.ParseString("version: 1\n"+test.from) + conf, err := yaml.ParseString("version: 1\n" + test.from) if err != nil { t.Fatalf("Cannot unmarshal yaml %q. Error: %s", test.from, err) } From fbce04f48f099e0f4f57d4b9c67a6eb028bccf0e Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Tue, 19 Sep 2023 18:36:49 +0200 Subject: [PATCH 05/12] update schema --- .woodpecker/binaries.yml | 2 ++ .woodpecker/docker.yml | 2 ++ .woodpecker/docs.yml | 2 ++ .woodpecker/release.yml | 2 ++ .woodpecker/securityscan.yml | 2 ++ .woodpecker/test.yml | 2 ++ .woodpecker/web.yml | 2 ++ pipeline/schema/.woodpecker/test-branches-array.yml | 2 ++ .../schema/.woodpecker/test-branches-exclude-include.yml | 2 ++ pipeline/schema/.woodpecker/test-branches.yml | 2 ++ pipeline/schema/.woodpecker/test-broken.yml | 2 ++ pipeline/schema/.woodpecker/test-clone-skip.yml | 2 ++ pipeline/schema/.woodpecker/test-clone.yml | 2 ++ pipeline/schema/.woodpecker/test-labels.yml | 2 ++ pipeline/schema/.woodpecker/test-matrix.yml | 2 ++ .../schema/.woodpecker/test-merge-map-and-sequence.yml | 2 ++ pipeline/schema/.woodpecker/test-multi.yml | 2 ++ pipeline/schema/.woodpecker/test-pipeline-when.yml | 2 ++ pipeline/schema/.woodpecker/test-platform.yml | 2 ++ pipeline/schema/.woodpecker/test-plugin.yml | 2 ++ pipeline/schema/.woodpecker/test-run-on.yml | 2 ++ pipeline/schema/.woodpecker/test-service.yml | 2 ++ pipeline/schema/.woodpecker/test-step.yml | 2 ++ pipeline/schema/.woodpecker/test-when.yml | 2 ++ pipeline/schema/.woodpecker/test-workspace.yml | 2 ++ pipeline/schema/schema.json | 7 ++++--- 26 files changed, 54 insertions(+), 3 deletions(-) diff --git a/.woodpecker/binaries.yml b/.woodpecker/binaries.yml index 890cf64b35..353255b18c 100644 --- a/.woodpecker/binaries.yml +++ b/.woodpecker/binaries.yml @@ -1,3 +1,5 @@ +version: 1 + depends_on: - test - web diff --git a/.woodpecker/docker.yml b/.woodpecker/docker.yml index b096dab8ab..edbbc0c8c2 100644 --- a/.woodpecker/docker.yml +++ b/.woodpecker/docker.yml @@ -1,3 +1,5 @@ +version: 1 + when: - event: [pull_request, tag] - event: push diff --git a/.woodpecker/docs.yml b/.woodpecker/docs.yml index aea664e363..f5fb37c4b9 100644 --- a/.woodpecker/docs.yml +++ b/.woodpecker/docs.yml @@ -1,3 +1,5 @@ +version: 1 + when: - event: pull_request - event: push diff --git a/.woodpecker/release.yml b/.woodpecker/release.yml index e998f2f66a..bd5cd439ef 100644 --- a/.woodpecker/release.yml +++ b/.woodpecker/release.yml @@ -1,3 +1,5 @@ +version: 1 + steps: release: image: woodpeckerci/plugin-ready-release-go diff --git a/.woodpecker/securityscan.yml b/.woodpecker/securityscan.yml index a0ccc136fc..a0d781453d 100644 --- a/.woodpecker/securityscan.yml +++ b/.woodpecker/securityscan.yml @@ -1,3 +1,5 @@ +version: 1 + when: - event: [ pull_request, cron ] - event: push diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml index fc4d3f4ca8..ccd770643b 100644 --- a/.woodpecker/test.yml +++ b/.woodpecker/test.yml @@ -1,3 +1,5 @@ +version: 1 + when: - event: [pull_request, tag] - event: push diff --git a/.woodpecker/web.yml b/.woodpecker/web.yml index d933ee8192..8bee5c65f9 100644 --- a/.woodpecker/web.yml +++ b/.woodpecker/web.yml @@ -1,3 +1,5 @@ +version: 1 + when: - event: [pull_request, tag] - event: push diff --git a/pipeline/schema/.woodpecker/test-branches-array.yml b/pipeline/schema/.woodpecker/test-branches-array.yml index d530db0550..32db454dec 100644 --- a/pipeline/schema/.woodpecker/test-branches-array.yml +++ b/pipeline/schema/.woodpecker/test-branches-array.yml @@ -1,3 +1,5 @@ +version: 1 + branches: [main, pages] steps: diff --git a/pipeline/schema/.woodpecker/test-branches-exclude-include.yml b/pipeline/schema/.woodpecker/test-branches-exclude-include.yml index 03b534d235..142788702a 100644 --- a/pipeline/schema/.woodpecker/test-branches-exclude-include.yml +++ b/pipeline/schema/.woodpecker/test-branches-exclude-include.yml @@ -1,3 +1,5 @@ +version: 1 + branches: include: main exclude: [develop, feature/*] diff --git a/pipeline/schema/.woodpecker/test-branches.yml b/pipeline/schema/.woodpecker/test-branches.yml index 75b72bbcf5..38122b5132 100644 --- a/pipeline/schema/.woodpecker/test-branches.yml +++ b/pipeline/schema/.woodpecker/test-branches.yml @@ -1,3 +1,5 @@ +version: 1 + branches: main steps: diff --git a/pipeline/schema/.woodpecker/test-broken.yml b/pipeline/schema/.woodpecker/test-broken.yml index 17d7218655..f716f520a2 100644 --- a/pipeline/schema/.woodpecker/test-broken.yml +++ b/pipeline/schema/.woodpecker/test-broken.yml @@ -1,3 +1,5 @@ +version: 1 + branches: main matri: diff --git a/pipeline/schema/.woodpecker/test-clone-skip.yml b/pipeline/schema/.woodpecker/test-clone-skip.yml index 50c20409c1..2c0ce1dc28 100644 --- a/pipeline/schema/.woodpecker/test-clone-skip.yml +++ b/pipeline/schema/.woodpecker/test-clone-skip.yml @@ -1,3 +1,5 @@ +version: 1 + steps: test: image: alpine diff --git a/pipeline/schema/.woodpecker/test-clone.yml b/pipeline/schema/.woodpecker/test-clone.yml index 81ef330c67..95c6d30503 100644 --- a/pipeline/schema/.woodpecker/test-clone.yml +++ b/pipeline/schema/.woodpecker/test-clone.yml @@ -1,3 +1,5 @@ +version: 1 + clone: git: image: plugins/git:next diff --git a/pipeline/schema/.woodpecker/test-labels.yml b/pipeline/schema/.woodpecker/test-labels.yml index 4de55db773..089454273e 100644 --- a/pipeline/schema/.woodpecker/test-labels.yml +++ b/pipeline/schema/.woodpecker/test-labels.yml @@ -1,3 +1,5 @@ +version: 1 + labels: location: europe weather: sun diff --git a/pipeline/schema/.woodpecker/test-matrix.yml b/pipeline/schema/.woodpecker/test-matrix.yml index 449ab7a57f..ff15e65a31 100644 --- a/pipeline/schema/.woodpecker/test-matrix.yml +++ b/pipeline/schema/.woodpecker/test-matrix.yml @@ -1,3 +1,5 @@ +version: 1 + steps: test: image: golang:${GO_VERSION} diff --git a/pipeline/schema/.woodpecker/test-merge-map-and-sequence.yml b/pipeline/schema/.woodpecker/test-merge-map-and-sequence.yml index acd24e0f34..673db526bf 100644 --- a/pipeline/schema/.woodpecker/test-merge-map-and-sequence.yml +++ b/pipeline/schema/.woodpecker/test-merge-map-and-sequence.yml @@ -1,3 +1,5 @@ +version: 1 + variables: step_template: &base-step image: golang:1.19 diff --git a/pipeline/schema/.woodpecker/test-multi.yml b/pipeline/schema/.woodpecker/test-multi.yml index e5d4fda797..5f1e491f35 100644 --- a/pipeline/schema/.woodpecker/test-multi.yml +++ b/pipeline/schema/.woodpecker/test-multi.yml @@ -1,3 +1,5 @@ +version: 1 + steps: deploy: image: golang diff --git a/pipeline/schema/.woodpecker/test-pipeline-when.yml b/pipeline/schema/.woodpecker/test-pipeline-when.yml index 84f02b403a..ff0af601fc 100644 --- a/pipeline/schema/.woodpecker/test-pipeline-when.yml +++ b/pipeline/schema/.woodpecker/test-pipeline-when.yml @@ -1,3 +1,5 @@ +version: 1 + when: - branch: [main, deploy] event: push diff --git a/pipeline/schema/.woodpecker/test-platform.yml b/pipeline/schema/.woodpecker/test-platform.yml index 7b4abf027f..b3da75a961 100644 --- a/pipeline/schema/.woodpecker/test-platform.yml +++ b/pipeline/schema/.woodpecker/test-platform.yml @@ -1,3 +1,5 @@ +version: 1 + platform: linux/amd64 steps: diff --git a/pipeline/schema/.woodpecker/test-plugin.yml b/pipeline/schema/.woodpecker/test-plugin.yml index db85967b28..6c0bfdbc1d 100644 --- a/pipeline/schema/.woodpecker/test-plugin.yml +++ b/pipeline/schema/.woodpecker/test-plugin.yml @@ -1,3 +1,5 @@ +version: 1 + steps: build: image: golang diff --git a/pipeline/schema/.woodpecker/test-run-on.yml b/pipeline/schema/.woodpecker/test-run-on.yml index 268ac23c7c..ece763d577 100644 --- a/pipeline/schema/.woodpecker/test-run-on.yml +++ b/pipeline/schema/.woodpecker/test-run-on.yml @@ -1,3 +1,5 @@ +version: 1 + steps: build: image: golang diff --git a/pipeline/schema/.woodpecker/test-service.yml b/pipeline/schema/.woodpecker/test-service.yml index 03564e9fca..98dce9f534 100644 --- a/pipeline/schema/.woodpecker/test-service.yml +++ b/pipeline/schema/.woodpecker/test-service.yml @@ -1,3 +1,5 @@ +version: 1 + steps: build: image: golang diff --git a/pipeline/schema/.woodpecker/test-step.yml b/pipeline/schema/.woodpecker/test-step.yml index 3db52b95c8..43a9a2af2f 100644 --- a/pipeline/schema/.woodpecker/test-step.yml +++ b/pipeline/schema/.woodpecker/test-step.yml @@ -1,3 +1,5 @@ +version: 1 + steps: image: image: golang diff --git a/pipeline/schema/.woodpecker/test-when.yml b/pipeline/schema/.woodpecker/test-when.yml index 721c92bf8c..fa40d04d23 100644 --- a/pipeline/schema/.woodpecker/test-when.yml +++ b/pipeline/schema/.woodpecker/test-when.yml @@ -1,3 +1,5 @@ +version: 1 + steps: when-branch: image: alpine diff --git a/pipeline/schema/.woodpecker/test-workspace.yml b/pipeline/schema/.woodpecker/test-workspace.yml index 5ee7ae988d..3ac5202e0f 100644 --- a/pipeline/schema/.woodpecker/test-workspace.yml +++ b/pipeline/schema/.woodpecker/test-workspace.yml @@ -1,3 +1,5 @@ +version: 1 + workspace: base: /go path: src/github.com/octocat/hello-world diff --git a/pipeline/schema/schema.json b/pipeline/schema/schema.json index 8ffa520326..e967b21135 100644 --- a/pipeline/schema/schema.json +++ b/pipeline/schema/schema.json @@ -4,7 +4,7 @@ "$id": "https://woodpecker-ci.org/schema/woodpecker.json", "description": "Schema of a Woodpecker pipeline file. Read more: https://woodpecker-ci.org/docs/usage/pipeline-syntax", "type": "object", - "required": ["steps"], + "required": ["version", "steps"], "additionalProperties": false, "properties": { "$schema": { @@ -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" }, @@ -34,7 +34,8 @@ "type": "array", "minLength": 1, "items": { "type": "string" } - } + }, + "version": { "type": "number" } }, "definitions": { "clone": { From 7e2bfde8b3a07d2c7e114ecf2007e3b35273f3dd Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Wed, 20 Sep 2023 08:08:16 +0200 Subject: [PATCH 06/12] update example yamls --- contrib/woodpecker-test-repo/.woodpecker/demo.yml | 1 + contrib/woodpecker-test-repo/.woodpecker/test.yml | 1 + go.sum | 10 ---------- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/contrib/woodpecker-test-repo/.woodpecker/demo.yml b/contrib/woodpecker-test-repo/.woodpecker/demo.yml index 02824a8dee..cc6ae3bb9b 100644 --- a/contrib/woodpecker-test-repo/.woodpecker/demo.yml +++ b/contrib/woodpecker-test-repo/.woodpecker/demo.yml @@ -1,3 +1,4 @@ +version: 1 steps: demo: image: 'alpine' diff --git a/contrib/woodpecker-test-repo/.woodpecker/test.yml b/contrib/woodpecker-test-repo/.woodpecker/test.yml index 1f41cddc36..b8e568ecec 100644 --- a/contrib/woodpecker-test-repo/.woodpecker/test.yml +++ b/contrib/woodpecker-test-repo/.woodpecker/test.yml @@ -1,3 +1,4 @@ +version: 1 steps: test_1: image: 'alpine' diff --git a/go.sum b/go.sum index a3aaca79e2..11f932c1d4 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,6 @@ github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwF github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g= github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0= github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= -github.com/antonmedv/expr v1.15.1 h1:mxeRIkH8GQJo4MRRFgp0ArlV4AA+0DmcJNXEsG70rGU= -github.com/antonmedv/expr v1.15.1/go.mod h1:0E/6TxnOlRNp81GMzX9QfDPAmHo2Phg00y4JUv1ihsE= github.com/antonmedv/expr v1.15.2 h1:afFXpDWIC2n3bF+kTZE1JvFo+c34uaM3sTqh8z0xfdU= github.com/antonmedv/expr v1.15.2/go.mod h1:0E/6TxnOlRNp81GMzX9QfDPAmHo2Phg00y4JUv1ihsE= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= @@ -581,8 +579,6 @@ google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6 google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= -google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o= -google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/grpc v1.58.1 h1:OL+Vz23DTtrrldqHK49FUOPHyY75rvFqJfXC84NYW58= google.golang.org/grpc v1.58.1/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= @@ -616,16 +612,10 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -k8s.io/api v0.28.1 h1:i+0O8k2NPBCPYaMB+uCkseEbawEt/eFaiRqUx8aB108= -k8s.io/api v0.28.1/go.mod h1:uBYwID+66wiL28Kn2tBjBYQdEU0Xk0z5qF8bIBqk/Dg= k8s.io/api v0.28.2 h1:9mpl5mOb6vXZvqbQmankOfPIGiudghwCoLl1EYfUZbw= k8s.io/api v0.28.2/go.mod h1:RVnJBsjU8tcMq7C3iaRSGMeaKt2TWEUXcpIt/90fjEg= -k8s.io/apimachinery v0.28.1 h1:EJD40og3GizBSV3mkIoXQBsws32okPOy+MkRyzh6nPY= -k8s.io/apimachinery v0.28.1/go.mod h1:X0xh/chESs2hP9koe+SdIAcXWcQ+RM5hy0ZynB+yEvw= k8s.io/apimachinery v0.28.2 h1:KCOJLrc6gu+wV1BYgwik4AF4vXOlVJPdiqn0yAWWwXQ= k8s.io/apimachinery v0.28.2/go.mod h1:RdzF87y/ngqk9H4z3EL2Rppv5jj95vGS/HaFXrLDApU= -k8s.io/client-go v0.28.1 h1:pRhMzB8HyLfVwpngWKE8hDcXRqifh1ga2Z/PU9SXVK8= -k8s.io/client-go v0.28.1/go.mod h1:pEZA3FqOsVkCc07pFVzK076R+P/eXqsgx5zuuRWukNE= k8s.io/client-go v0.28.2 h1:DNoYI1vGq0slMBN/SWKMZMw0Rq+0EQW6/AK4v9+3VeY= k8s.io/client-go v0.28.2/go.mod h1:sMkApowspLuc7omj1FOSUxSoqjr+d5Q0Yc0LOFnYFJY= k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= From cd5449a8b4eb08fe48754062b698f6a0fddee85e Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Mon, 9 Oct 2023 09:43:42 +0200 Subject: [PATCH 07/12] Make version optional (default 1) --- docs/docs/20-usage/10-intro.md | 4 --- docs/docs/20-usage/20-pipeline-syntax.md | 35 ------------------- docs/docs/20-usage/25-workflows.md | 6 ---- docs/docs/20-usage/30-matrix-workflows.md | 5 --- docs/docs/20-usage/35-advanced-yaml-syntax.md | 4 --- docs/docs/20-usage/40-secrets.md | 4 --- docs/docs/20-usage/45-cron.md | 1 - docs/docs/20-usage/50-environment.md | 8 ----- docs/docs/20-usage/60-services.md | 4 --- docs/docs/20-usage/70-volumes.md | 1 - docs/docs/20-usage/90-pipeline-management.md | 3 -- docs/docs/91-migrations.md | 3 +- pipeline/frontend/yaml/error.go | 5 +-- pipeline/frontend/yaml/parse.go | 3 +- pipeline/frontend/yaml/parse_test.go | 16 +++++++++ pipeline/schema/schema.json | 2 +- 16 files changed, 21 insertions(+), 83 deletions(-) diff --git a/docs/docs/20-usage/10-intro.md b/docs/docs/20-usage/10-intro.md index 61c0de8e12..581260cec6 100644 --- a/docs/docs/20-usage/10-intro.md +++ b/docs/docs/20-usage/10-intro.md @@ -32,8 +32,6 @@ Read more at: [https://github.com/go-yaml/yaml](https://github.com/go-yaml/yaml/ Example pipeline configuration: ```yaml -version: 1 - steps: build: image: golang @@ -52,8 +50,6 @@ services: Example pipeline configuration with multiple, serial steps: ```yaml -version: 1 - steps: backend: image: golang diff --git a/docs/docs/20-usage/20-pipeline-syntax.md b/docs/docs/20-usage/20-pipeline-syntax.md index 2e0aa49939..88343975b1 100644 --- a/docs/docs/20-usage/20-pipeline-syntax.md +++ b/docs/docs/20-usage/20-pipeline-syntax.md @@ -2,14 +2,9 @@ The pipeline section defines a list of steps to build, test and deploy your code. Pipeline steps are executed serially, in the order in which they are defined. If a step returns a non-zero exit code, the pipeline immediately aborts and returns a failure status. -:::info -All workflows must set the `version`. Currently, only version 1 is supported, so you'll need to add `version: 1` to every YAML file. -::: - Example steps: ```yaml -version: 1 steps: backend: image: golang @@ -29,7 +24,6 @@ In the above example we define two pipeline steps, `frontend` and `backend`. The Another way to name a step is by using the name keyword: ```yaml -version: 1 steps: - name: backend image: golang @@ -54,17 +48,12 @@ Woodpecker gives the ability to skip individual commits by adding `[SKIP CI]` or git commit -m "updated README [CI SKIP]" ``` -## Version - -Every workflow YAML must define the YAML version it is using. Currently, only version 1 is available, so you need to add `version: 1` to all of your workflows YAMLs. - ## Steps Every step of your pipeline executes arbitrary commands inside a specified container. The defined commands are executed serially. The associated commit of a current pipeline run is checked out with git to a workspace which is mounted to every step of the pipeline as the working directory. ```diff - version: 1 steps: backend: image: golang @@ -80,7 +69,6 @@ The associated commit of a current pipeline run is checked out with git to a wor ```yaml # .woodpecker.yml -version: 1 steps: build: image: debian @@ -99,7 +87,6 @@ Woodpecker pulls the defined image and uses it as environment to execute the pip When using the `local` backend, the `image` entry is used to specify the shell, such as Bash or Fish, that is used to run the commands. ```diff - version: 1 steps: build: + image: golang:1.6 @@ -129,7 +116,6 @@ image: index.docker.io/library/golang:1.7 Woodpecker does not automatically upgrade container images. Example configuration to always pull the latest image when updates are available: ```diff - version: 1 steps: build: image: golang:latest @@ -145,7 +131,6 @@ These credentials are never exposed to your pipeline, which means they cannot be Example configuration using a private image: ```diff - version: 1 steps: build: + image: gcr.io/custom/golang @@ -208,7 +193,6 @@ For this privileged rights are needed only available to admins. In addition this Commands of every pipeline step are executed serially as if you would enter them into your local shell. ```diff - version: 1 steps: backend: image: golang @@ -252,7 +236,6 @@ For more details check the [secrets docs](./40-secrets.md). Some of the pipeline steps may be allowed to fail without causing the whole pipeline to report a failure (e.g., a step executing a linting check). To enable this, add `failure: ignore` to your pipeline step. If Woodpecker encounters an error while executing the step, it will report it as failed but still execute the next steps of the pipeline, if any, without affecting the status of the pipeline. ```diff - version: 1 steps: backend: image: golang @@ -267,7 +250,6 @@ Some of the pipeline steps may be allowed to fail without causing the whole pipe Woodpecker supports defining a list of conditions for a pipeline step by using a `when` block. If at least one of the conditions in the `when` block evaluate to true the step is executed, otherwise it is skipped. A condition can be a check like: ```diff - version: 1 steps: slack: image: plugins/slack @@ -285,7 +267,6 @@ Woodpecker supports defining a list of conditions for a pipeline step by using a Example conditional execution by repository: ```diff - version: 1 steps: slack: image: plugins/slack @@ -304,7 +285,6 @@ Branch conditions are not applied to tags. Example conditional execution by branch: ```diff -version: 1 steps: slack: image: plugins/slack @@ -402,7 +382,6 @@ when: There are use cases for executing pipeline steps on failure, such as sending notifications for failed pipelines. Use the status constraint to execute steps even when the pipeline fails: ```diff -version: 1 steps: slack: image: plugins/slack @@ -536,7 +515,6 @@ Woodpecker supports parallel step execution for same-machine fan-in and fan-out. Example parallel configuration: ```diff - version: 1 steps: backend: + group: build @@ -591,7 +569,6 @@ The workspace defines the shared volume and working directory shared by all pipe The workspace can be customized using the workspace block in the YAML file: ```diff - version: 1 +workspace: + base: /go + path: src/github.com/octocat/hello-world @@ -607,7 +584,6 @@ The workspace can be customized using the workspace block in the YAML file: The base attribute defines a shared base volume available to all pipeline steps. This ensures your source code, dependencies and compiled binaries are persisted and shared between steps. ```diff - version: 1 workspace: + base: /go path: src/github.com/octocat/hello-world @@ -636,7 +612,6 @@ docker run --volume=my-named-volume:/go node:latest The path attribute defines the working directory of your build. This is where your code is cloned and will be the default working directory of every step in your build process. The path must be relative and is combined with your base path. ```diff - version: 1 workspace: base: /go + path: src/github.com/octocat/hello-world @@ -665,7 +640,6 @@ By default each pipeline has at least the `repo=your-user/your-repo-name` label. You can add additional labels as a key value map: ```diff - version: 1 +labels: + location: europe # only agents with `location=europe` or `location=*` will be used + weather: sun @@ -689,7 +663,6 @@ Example: Assuming we have two agents, one `linux/arm` and one `linux/amd64`. Previously this pipeline would have executed on **either agent**, as Woodpecker is not fussy about where it runs the pipelines. By setting the following option it will only be executed on an agent with the platform `linux/arm64`. ```diff -version: 1 +labels: + platform: linux/arm64 @@ -710,7 +683,6 @@ Woodpecker automatically configures a default clone step if not explicitly defin You can manually configure the clone step in your pipeline for customization: ```diff - version: 1 +clone: + git: + image: woodpeckerci/plugin-git @@ -726,7 +698,6 @@ You can manually configure the clone step in your pipeline for customization: Example configuration to override depth: ```diff - version: 1 clone: git: image: woodpeckerci/plugin-git @@ -738,7 +709,6 @@ Example configuration to override depth: Example configuration to use a custom clone plugin: ```diff -version: 1 clone: git: + image: octocat/custom-git-plugin @@ -747,7 +717,6 @@ clone: Example configuration to clone Mercurial repository: ```diff - version: 1 clone: hg: + image: plugins/hg @@ -769,7 +738,6 @@ To use the credentials that cloned the repository to clone it's submodules, upda To use the ssh git url in `.gitmodules` for users cloning with ssh, and also use the https url in Woodpecker, add `submodule_override`: ```diff - version: 1 clone: git: image: woodpeckerci/plugin-git @@ -799,7 +767,6 @@ Woodpecker gives the ability to skip whole pipelines (not just steps #when---con Example conditional execution by repository: ```diff - version: 1 +when: + repo: test/test + @@ -819,7 +786,6 @@ Branch conditions are not applied to tags. Example conditional execution by branch: ```diff - version: 1 +when: + branch: main + @@ -957,7 +923,6 @@ Woodpecker gives the ability to configure privileged mode in the YAML. You can u > Privileged mode is only available to trusted repositories and for security reasons should only be used in private environments. See [project settings](./71-project-settings.md#trusted) to enable trusted mode. ```diff - version: 1 steps: build: image: docker diff --git a/docs/docs/20-usage/25-workflows.md b/docs/docs/20-usage/25-workflows.md index 445ab289ed..57b67003a1 100644 --- a/docs/docs/20-usage/25-workflows.md +++ b/docs/docs/20-usage/25-workflows.md @@ -36,7 +36,6 @@ If you still need to pass artifacts between the workflows you need use some stor .woodpecker/.build.yml ```yaml -version: 1 steps: build: image: debian:stable-slim @@ -48,7 +47,6 @@ steps: .woodpecker/.deploy.yml ```yaml -version: 1 steps: deploy: image: debian:stable-slim @@ -64,7 +62,6 @@ depends_on: .woodpecker/.test.yml ```yaml -version: 1 steps: test: image: debian:stable-slim @@ -79,7 +76,6 @@ depends_on: .woodpecker/.lint.yml ```yaml -version: 1 steps: lint: image: debian:stable-slim @@ -101,7 +97,6 @@ Dependencies between workflows can be set with the `depends_on` element. A workf The name for a `depends_on` entry is the filename without the path, leading dots and without the file extension `.yml` or `.yaml`. If the project config for example uses `.woodpecker/` as path for CI files with a file named `.woodpecker/.lint.yml` the corresponding `depends_on` entry would be `lint`. ```diff -version: 1 steps: deploy: image: debian:stable-slim @@ -117,7 +112,6 @@ steps: Workflows that need to run even on failures should set the `runs_on` tag. ```diff -version: 1 steps: notify: image: debian:stable-slim diff --git a/docs/docs/20-usage/30-matrix-workflows.md b/docs/docs/20-usage/30-matrix-workflows.md index 283b779b2c..0e0e07e5d0 100644 --- a/docs/docs/20-usage/30-matrix-workflows.md +++ b/docs/docs/20-usage/30-matrix-workflows.md @@ -33,7 +33,6 @@ matrix: Matrix variables are interpolated in the YAML using the `${VARIABLE}` syntax, before the YAML is parsed. This is an example YAML file before interpolating matrix parameters: ```yaml -version: 1 matrix: GO_VERSION: - 1.4 @@ -59,7 +58,6 @@ services: Example YAML file after injecting the matrix parameters: ```diff -version: 1 steps: build: - image: golang:${GO_VERSION} @@ -83,7 +81,6 @@ services: ### Example matrix pipeline based on Docker image tag ```yaml -version: 1 matrix: TAG: - 1.7 @@ -101,7 +98,6 @@ steps: ### Example matrix pipeline based on container image ```yaml -version: 1 matrix: IMAGE: - golang:1.7 @@ -119,7 +115,6 @@ steps: ### Example matrix pipeline using multiple platforms ```yaml -version: 1 matrix: platform: - linux/amd64 diff --git a/docs/docs/20-usage/35-advanced-yaml-syntax.md b/docs/docs/20-usage/35-advanced-yaml-syntax.md index 6c3172208d..8adf6ec56e 100644 --- a/docs/docs/20-usage/35-advanced-yaml-syntax.md +++ b/docs/docs/20-usage/35-advanced-yaml-syntax.md @@ -6,7 +6,6 @@ You can use [YAML anchors & aliases](https://yaml.org/spec/1.2.2/#3222-anchors-a To convert this: ```yml -version: 1 steps: test: image: golang:1.18 @@ -19,7 +18,6 @@ steps: Just add a new section called **variables** like this: ```diff - version: 1 +variables: + - &golang_image 'golang:1.18' @@ -37,7 +35,6 @@ Just add a new section called **variables** like this: ## Map merges and overwrites ```yaml -version: 1 variables: - &base-plugin-settings target: dist @@ -68,7 +65,6 @@ steps: ## Sequence merges ```yaml -version: 1 variables: pre_cmds: &pre_cmds - echo start diff --git a/docs/docs/20-usage/40-secrets.md b/docs/docs/20-usage/40-secrets.md index 9e6f95eca9..613a03fdb1 100644 --- a/docs/docs/20-usage/40-secrets.md +++ b/docs/docs/20-usage/40-secrets.md @@ -5,7 +5,6 @@ Woodpecker provides the ability to store named parameters external to the YAML c Secrets are exposed to your pipeline steps and plugins as uppercase environment variables and can therefore be referenced in the commands section of your pipeline. ```diff -version: 1 steps: docker: image: docker @@ -21,7 +20,6 @@ In this example, the secret named `secret_token` would be passed to the pipeline **NOTE:** the `from_secret` syntax only works with the newer `settings` block. ```diff -version: 1 steps: docker: image: my-plugin @@ -34,7 +32,6 @@ steps: Please note parameter expressions are subject to pre-processing. When using secrets in parameter expressions they should be escaped. ```diff -version: 1 steps: docker: image: docker @@ -55,7 +52,6 @@ Secrets are added to the Woodpecker secret store on the UI or with the CLI. There may be scenarios where you are required to store secrets using alternate names. You can map the alternate secret name to the expected name using the below syntax: ```diff -version: 1 steps: docker: image: plugins/docker diff --git a/docs/docs/20-usage/45-cron.md b/docs/docs/20-usage/45-cron.md index 1ead76f8a0..d954cb2ca7 100644 --- a/docs/docs/20-usage/45-cron.md +++ b/docs/docs/20-usage/45-cron.md @@ -7,7 +7,6 @@ To configure cron jobs you need at least push access to the repository. 1. To create a new cron job adjust your pipeline config(s) and add the event filter to all steps you would like to run by the cron job: ```diff - version: 1 steps: sync_locales: image: weblate_sync diff --git a/docs/docs/20-usage/50-environment.md b/docs/docs/20-usage/50-environment.md index 507232f2aa..ddd2765f4c 100644 --- a/docs/docs/20-usage/50-environment.md +++ b/docs/docs/20-usage/50-environment.md @@ -3,7 +3,6 @@ Woodpecker provides the ability to pass environment variables to individual pipeline steps. Note that these can't overwrite any existing, built-in variables. Example pipeline step with custom environment variables: ```diff -version: 1 steps: build: image: golang @@ -19,7 +18,6 @@ steps: Please note that the environment section is not able to expand environment variables. If you need to expand variables they should be exported in the commands section. ```diff -version: 1 steps: build: image: golang @@ -34,7 +32,6 @@ steps: > Please be warned that `${variable}` expressions are subject to pre-processing. If you do not want the pre-processor to evaluate your expression it must be escaped: ```diff -version: 1 steps: build: image: golang @@ -150,7 +147,6 @@ services: These can be used, for example, to manage the image tag used by multiple projects. ```diff -version: 1 steps: build: - image: golang:1.18 @@ -169,7 +165,6 @@ Woodpecker provides the ability to substitute environment variables at runtime. Example commit substitution: ```diff -version: 1 steps: docker: image: plugins/docker @@ -180,7 +175,6 @@ steps: Example tag substitution: ```diff -version: 1 steps: docker: image: plugins/docker @@ -209,7 +203,6 @@ Woodpecker also emulates bash string operations. This gives us the ability to ma Example variable substitution with substring: ```diff -version: 1 steps: docker: image: plugins/docker @@ -220,7 +213,6 @@ steps: Example variable substitution strips `v` prefix from `v.1.0.0`: ```diff -version: 1 steps: docker: image: plugins/docker diff --git a/docs/docs/20-usage/60-services.md b/docs/docs/20-usage/60-services.md index a1ea589897..df2467200b 100644 --- a/docs/docs/20-usage/60-services.md +++ b/docs/docs/20-usage/60-services.md @@ -7,7 +7,6 @@ Services are accessed using custom hostnames. In the example below, the MySQL service is assigned the hostname `database` and is available at `database:3306`. ```diff -version: 1 steps: build: image: golang @@ -44,7 +43,6 @@ services: Service and long running containers can also be included in the pipeline section of the configuration using the detach parameter without blocking other steps. This should be used when explicit control over startup order is required. ```diff -version: 1 steps: build: image: golang @@ -69,7 +67,6 @@ Containers from detached steps will terminate when the pipeline ends. Service containers require time to initialize and begin to accept connections. If you are unable to connect to a service you may need to wait a few seconds or implement a backoff. ```diff -version: 1 steps: test: image: golang @@ -86,7 +83,6 @@ services: ## Complete Pipeline Example ```yml -version: 1 services: database: image: mysql diff --git a/docs/docs/20-usage/70-volumes.md b/docs/docs/20-usage/70-volumes.md index 0e7e1b53c6..297f14ec07 100644 --- a/docs/docs/20-usage/70-volumes.md +++ b/docs/docs/20-usage/70-volumes.md @@ -7,7 +7,6 @@ Volumes are only available to trusted repositories and for security reasons shou ::: ```diff -version: 1 steps: build: image: docker diff --git a/docs/docs/20-usage/90-pipeline-management.md b/docs/docs/20-usage/90-pipeline-management.md index 94da792c93..e160922f3d 100644 --- a/docs/docs/20-usage/90-pipeline-management.md +++ b/docs/docs/20-usage/90-pipeline-management.md @@ -9,7 +9,6 @@ Once your pipeline starts to grow in size, it will become important to keep it D As described in [Advanced YAML syntax](./35-advanced-yaml-syntax.md). ```yml -version: 1 variables: - &golang_image 'golang:1.18' @@ -26,7 +25,6 @@ Note that the `golang_image` alias cannot be used with string interpolation. But Another approach using YAML extensions: ```yml -version: 1 variables: - global_env: &global_env - BASH_VERSION=1.2.3 @@ -56,7 +54,6 @@ steps: One can create a file containing environment variables, and then source it in each step that needs them. ```yml -version: 1 steps: init: image: bash diff --git a/docs/docs/91-migrations.md b/docs/docs/91-migrations.md index 685e29646f..5047e47528 100644 --- a/docs/docs/91-migrations.md +++ b/docs/docs/91-migrations.md @@ -2,13 +2,12 @@ Some versions need some changes to the server configuration or the pipeline configuration files. -## next (2.0.0) +## 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 - Deprecate `platform:` filter in favor of `labels:`, [read more](./20-usage/20-pipeline-syntax.md#filter-by-platform) -- All workflows must define a `version` in its YAML (currently only supporting version 1) ## 1.0.0 diff --git a/pipeline/frontend/yaml/error.go b/pipeline/frontend/yaml/error.go index afde72084c..55f1fdd32c 100644 --- a/pipeline/frontend/yaml/error.go +++ b/pipeline/frontend/yaml/error.go @@ -16,10 +16,7 @@ package yaml import "errors" -var ( - ErrUnsuportedVersion = errors.New("unsuported pipeline config version detected") - ErrMissingVersion = errors.New("missing pipeline config version") -) +var ErrUnsuportedVersion = errors.New("unsuported pipeline config version detected") // PipelineParseError is an error that occurs when the pipeline parsing fails. type PipelineParseError struct { diff --git a/pipeline/frontend/yaml/parse.go b/pipeline/frontend/yaml/parse.go index 963bbb86a6..22e81852a7 100644 --- a/pipeline/frontend/yaml/parse.go +++ b/pipeline/frontend/yaml/parse.go @@ -52,7 +52,8 @@ func checkVersion(b []byte) (int, error) { }{} _ = xyaml.Unmarshal(b, &ver) if ver.Version == 0 { - return 0, ErrMissingVersion + // default: version 1 + return 1, nil } if ver.Version != Version { diff --git a/pipeline/frontend/yaml/parse_test.go b/pipeline/frontend/yaml/parse_test.go index bbc2a38590..917043b79d 100644 --- a/pipeline/frontend/yaml/parse_test.go +++ b/pipeline/frontend/yaml/parse_test.go @@ -87,6 +87,16 @@ func TestParse(t *testing.T) { g.Assert(out.Steps.ContainerList[1].When.Constraints[0].Event.Include).Equal([]string{"success"}) }) + g.It("Should unmarshal with default version", func() { + out, err := ParseString(sampleYamlDefaultVersion) + if err != nil { + g.Fail(err) + } + g.Assert(len(out.Steps.ContainerList)).Equal(1) + g.Assert(out.Steps.ContainerList[0].Name).Equal("notify_success") + g.Assert(out.Steps.ContainerList[0].Image).Equal("xyz") + }) + matchConfig, err := ParseString(sampleYaml) if err != nil { g.Fail(err) @@ -190,6 +200,12 @@ runs_on: - failure ` +var sampleYamlDefaultVersion = ` +steps: + - name: notify_success + image: xyz +` + var simpleYamlAnchors = ` version: 1 vars: diff --git a/pipeline/schema/schema.json b/pipeline/schema/schema.json index e967b21135..e251e9a958 100644 --- a/pipeline/schema/schema.json +++ b/pipeline/schema/schema.json @@ -4,7 +4,7 @@ "$id": "https://woodpecker-ci.org/schema/woodpecker.json", "description": "Schema of a Woodpecker pipeline file. Read more: https://woodpecker-ci.org/docs/usage/pipeline-syntax", "type": "object", - "required": ["version", "steps"], + "required": ["steps"], "additionalProperties": false, "properties": { "$schema": { From a923fc5f988501dac9b58dd83e3e9e0f1e0e3e7a Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Mon, 9 Oct 2023 17:53:40 +0200 Subject: [PATCH 08/12] Update pipeline/schema/schema.json Co-authored-by: Lauris BH --- 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 e251e9a958..9b8d86bc03 100644 --- a/pipeline/schema/schema.json +++ b/pipeline/schema/schema.json @@ -35,7 +35,7 @@ "minLength": 1, "items": { "type": "string" } }, - "version": { "type": "number" } + "version": { "type": "number", "default": 1 } }, "definitions": { "clone": { From 1ac5c0e5612cd088ba5ee46141afa927b2fa08bf Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Thu, 2 Nov 2023 15:07:30 +0100 Subject: [PATCH 09/12] move default version to constant --- pipeline/frontend/yaml/parse.go | 3 ++- shared/constant/constant.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pipeline/frontend/yaml/parse.go b/pipeline/frontend/yaml/parse.go index 22e81852a7..5699392238 100644 --- a/pipeline/frontend/yaml/parse.go +++ b/pipeline/frontend/yaml/parse.go @@ -18,6 +18,7 @@ import ( "codeberg.org/6543/xyaml" "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types" + "github.com/woodpecker-ci/woodpecker/shared/constant" ) // ParseBytes parses the configuration from bytes b. @@ -53,7 +54,7 @@ func checkVersion(b []byte) (int, error) { _ = xyaml.Unmarshal(b, &ver) if ver.Version == 0 { // default: version 1 - return 1, nil + return constant.DefaultPipelineVersion, nil } if ver.Version != Version { diff --git a/shared/constant/constant.go b/shared/constant/constant.go index 3d46ee769b..a6eb50c92b 100644 --- a/shared/constant/constant.go +++ b/shared/constant/constant.go @@ -40,3 +40,5 @@ var TrustedCloneImages = []string{ DefaultCloneImage, "quay.io/woodpeckerci/plugin-git", } + +const DefaultPipelineVersion = 1 From caef4a99c66e6717a504212009e24f1659ff3581 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Thu, 2 Nov 2023 17:27:11 +0100 Subject: [PATCH 10/12] Update parse.go --- pipeline/frontend/yaml/parse.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pipeline/frontend/yaml/parse.go b/pipeline/frontend/yaml/parse.go index 377febc40c..ff4b611dcc 100644 --- a/pipeline/frontend/yaml/parse.go +++ b/pipeline/frontend/yaml/parse.go @@ -21,11 +21,8 @@ import ( "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/constraint" "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types" -<<<<<<< HEAD - "github.com/woodpecker-ci/woodpecker/shared/constant" -======= "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types/base" ->>>>>>> main + "github.com/woodpecker-ci/woodpecker/shared/constant" ) // ParseBytes parses the configuration from bytes b. @@ -72,7 +69,6 @@ func ParseBytes(b []byte) (*types.Workflow, error) { out.PlatformDontUseIt = "" } out.PipelineDontUseIt.ContainerList = nil ->>>>>>> main return out, nil } From aad400fd2553f1eb6e25e9499aba10d5db271e39 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Thu, 2 Nov 2023 17:30:10 +0100 Subject: [PATCH 11/12] fix year --- pipeline/frontend/yaml/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline/frontend/yaml/version.go b/pipeline/frontend/yaml/version.go index 232353aeb9..e48311388a 100644 --- a/pipeline/frontend/yaml/version.go +++ b/pipeline/frontend/yaml/version.go @@ -1,4 +1,4 @@ -// Copyright 2022 Woodpecker Authors +// Copyright 2023 Woodpecker Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From 57cb25dbab5cd9fbbfab429d5d0cd61f34eff6ea Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sat, 4 Nov 2023 10:17:00 +0100 Subject: [PATCH 12/12] fix missing import --- pipeline/frontend/yaml/parse.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pipeline/frontend/yaml/parse.go b/pipeline/frontend/yaml/parse.go index 05eb92e398..f57a973e09 100644 --- a/pipeline/frontend/yaml/parse.go +++ b/pipeline/frontend/yaml/parse.go @@ -15,6 +15,7 @@ package yaml import ( + "errors" "fmt" "codeberg.org/6543/xyaml"