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

Add json schema and cli lint command #342

Merged
merged 28 commits into from
Sep 27, 2021
Merged

Conversation

anbraten
Copy link
Member

@anbraten anbraten commented Sep 23, 2021

addresses #275
preparation for #276

Changes

  • add json schema file
  • add tests to validate sample pipeline files
  • add new command lint to cli to test a directory or single file to use correct schema

woodpecker-cli lint ./pipeline/schema/.woodpecker/

Sample output from `woodpecker-cli lint ./pipeline/schema/.woodpecker/`
# test-branches-exclude-include.yml
❌ Config is invalid
In branches: Must validate one and only one schema (oneOf)
In branches: Invalid type. Expected: array, given: object

# test-branches.yml
❌ Config is invalid
In branches: Must validate one and only one schema (oneOf)
In branches: Invalid type. Expected: array, given: object

# test-clone-skip.yml
❌ Config is invalid
In (root): Additional property skip_clone is not allowed

# test-clone.yml
✅ Config is valid

# test-matrix.yml
✅ Config is valid

# test-multi.yml
❌ Config is invalid
In (root): Additional property depends_on is not allowed

# test-plugin.yml
❌ Config is invalid
In (root): pipeline is required

# test-run-on.yml
❌ Config is invalid
In (root): Additional property run_on is not allowed

# test-service.yml
✅ Config is valid

# test-step.yml
❌ Config is invalid
In pipeline.detached: commands is required
In pipeline.volume.volumes: Invalid type. Expected: string, given: array

# test-when.yml
✅ Config is valid

# test-workspace.yml
✅ Config is valid

ref: SchemaStore/schemastore#1845

@anbraten anbraten changed the title Add json schema Add json schema and cli lint command Sep 24, 2021
@anbraten anbraten added the feature add new functionality label Sep 24, 2021
@anbraten anbraten removed the wip label Sep 24, 2021
@anbraten anbraten marked this pull request as ready for review September 24, 2021 10:06
@anbraten anbraten requested a review from 6543 September 24, 2021 12:51
@anbraten anbraten added this to the 0.15.0 milestone Sep 24, 2021
@6543
Copy link
Member

6543 commented Sep 26, 2021

@anbraten please resolve conflict

@6543
Copy link
Member

6543 commented Sep 26, 2021

./cli/release/linux/amd64/woodpecker-cli lint .woodpecker/
# docs.yml
✅ Config is valid

# helm.yml
✅ Config is valid

# main.yml
❌ Config is invalid
In pipeline.build-cli.commands: Invalid type. Expected: array, given: string

commands is either string array or string

@anbraten
Copy link
Member Author

That's an error in the schema file. I didn't know / saw that a command is allowed to be just a single string instead of an array with a single item. I will adjust the schema.

@6543
Copy link
Member

6543 commented Sep 26, 2021

one question are all schema in pipeline/schema/.woodpecker/ valid by purpose?

@anbraten
Copy link
Member Author

one question are all schema in pipeline/schema/.woodpecker/ valid by purpose?

Yes atm I only added valid configs for all possible options as the impossible options are infinitely large. Schemastore seems to have some negative tests for their hosted schemas. I can try to add something similar.

@6543

This comment has been minimized.

@6543 6543 enabled auto-merge (squash) September 26, 2021 23:30
@6543 6543 merged commit 0fa271f into woodpecker-ci:master Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation docu & docs feature add new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants