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

Fix schema validation with array syntax for clone and services #2920

Merged
merged 6 commits into from
Dec 7, 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
4 changes: 4 additions & 0 deletions pipeline/frontend/yaml/linter/linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"go.woodpecker-ci.org/woodpecker/pipeline/errors"
"go.woodpecker-ci.org/woodpecker/pipeline/frontend/yaml"
"go.woodpecker-ci.org/woodpecker/pipeline/frontend/yaml/linter"
Expand Down Expand Up @@ -60,6 +61,9 @@ steps:
settings:
repo: foo/bar
foo: bar
services:
- name: redis
image: redis
`,
}, {
Title: "merge maps", Data: `
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 1

clone:
- name: git
image: woodpeckerci/plugin-git
settings:
partial: true
- name: testdata
image: woodpeckerci/plugin-git
settings:
remote: https://gitserver/owner/testdata.git
path: testdata
anbraten marked this conversation as resolved.
Show resolved Hide resolved

steps:
- name: build
image: golang
commands:
- go build
- go test

services:
- name: database
image: mysql
- name: cache
image: redis
82 changes: 71 additions & 11 deletions pipeline/frontend/yaml/linter/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,62 @@
"definitions": {
"clone": {
"description": "Configures the clone step. Read more: https://woodpecker-ci.org/docs/usage/pipeline-syntax#clone",
"type": "object",
"additionalProperties": false,
"properties": {
"git": {
"oneOf": [
{
"type": "object",
"additionalProperties": false,
"properties": {
"image": {
"type": "string"
"git": {
"type": "object",
"properties": {
"image": {
"$ref": "#/definitions/step_image"
},
"settings": {
"$ref": "#/definitions/clone_settings"
}
}
}
}
},
{
"type": "array",
"items": {
"$ref": "#/definitions/step"
},
"minLength": 1
}
]
},
"clone_settings": {
"description": "Change the settings of your clone plugin. Read more: https://woodpecker-ci.org/plugins/Git%20Clone",
"type": "object",
"properties": {
"depth": {
"type": "number",
"description": "If specified, uses git's --depth option to create a shallow clone with a limited number of commits, overwritten by partial"
},
"recursive": {
"type": "boolean",
"default": false,
"description": "Clones submodules recursively"
},
"partial": {
"type": "boolean",
"description": "Only fetch the one commit and it's blob objects to resolve all files, overwrite depth with 1"
},
"lfs": {
"type": "boolean",
"default": true,
"description": "Set this to `false` to disable retrieval of LFS files"
lafriks marked this conversation as resolved.
Show resolved Hide resolved
},
"tags": {
"type": "boolean",
"description": "Fetches tags when set to true, default is false if event is not tag else true"
}
},
"additionalProperties": {
"type": ["boolean", "string", "number", "array", "object"]
}
},
"branches": {
Expand Down Expand Up @@ -664,11 +709,22 @@
},
"services": {
"description": "Read more: https://woodpecker-ci.org/docs/usage/services",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/service"
},
"minProperties": 1
"oneOf": [
{
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/service"
},
"minProperties": 1
},
{
"type": "array",
"items": {
"$ref": "#/definitions/service"
},
"minLength": 1
}
]
},
"service": {
"description": "Read more: https://woodpecker-ci.org/docs/usage/services",
Expand All @@ -677,6 +733,10 @@
"minProperties": 1,
"required": ["image"],
"properties": {
"name": {
"description": "The name of the service. Can be used if using the array style services list.",
lafriks marked this conversation as resolved.
Show resolved Hide resolved
"type": "string"
},
"image": {
"$ref": "#/definitions/step_image"
},
Expand Down
5 changes: 5 additions & 0 deletions pipeline/frontend/yaml/linter/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func TestSchema(t *testing.T) {
testFile: ".woodpecker/test-broken.yml",
fail: true,
},
{
name: "New syntax",
lafriks marked this conversation as resolved.
Show resolved Hide resolved
testFile: ".woodpecker/test-new-syntax.yml",
fail: false,
},
lafriks marked this conversation as resolved.
Show resolved Hide resolved
}

for _, tt := range testTable {
Expand Down