Skip to content

Instantly share code, notes, and snippets.

@toolmantim
Last active April 7, 2018 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toolmantim/6ec7b42d4a388965645418e17b600edc to your computer and use it in GitHub Desktop.
Save toolmantim/6ec7b42d4a388965645418e17b600edc to your computer and use it in GitHub Desktop.

Usage example:

$ docker-compose build
$ docker run -it --rm -v /some-local-plugin-path:/plugin:ro buildkite/plugin-example-validator /plugin/schema.yml /plugin/readme.md
🙌 Readme examples validate against the schema
version: '3.2'
services:
validator:
build: .
image: buildkite/plugin-example-validator
FROM ruby:2.5.1-alpine
RUN gem install json-schema
WORKDIR /src
ADD example-validator.rb .
ENTRYPOINT ["ruby", "example-validator.rb"]
require 'json-schema'
schema_path = ARGV[0]
readme_path = ARGV[1]
unless schema_path && readme_path
abort "Usage: example-validator.rb schema readme\n\nExample: example-validator.rb /plugin/schema.yml /plugin/README.md"
end
schema = YAML.load(File.read(schema_path))
readme = File.read(readme_path)
readme.scan(/```yml(.*?)```/m).each do |(yml)|
if plugin_config = yml[/plugins:.*?\n.*?\n(.*)/m, 1]
JSON::Validator.validate!(schema, YAML.load(plugin_config))
end
end
puts "🙌 Readme examples validate against the schema"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment