-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add YAML validation for configuration files.
For validation, the "on" key in existing YAML files is changed to a literal string. In the YAML spec, on is a keyword which encodes a boolean value, so without relying on a specific implementation the YAML files are technically not encoding an object that complies with the specification. PiperOrigin-RevId: 350172147
- Loading branch information
1 parent
622db84
commit 2a5d3c2
Showing
12 changed files
with
345 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Labeler labels incoming pull requests. | ||
name: "Labeler" | ||
on: | ||
"on": | ||
- pull_request | ||
|
||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"definitions": { | ||
"group": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"description": "The name of the group.", | ||
"type": "string" | ||
}, | ||
"regex": { | ||
"description": "A regular expression for matching paths.", | ||
"type": "string" | ||
}, | ||
"default": { | ||
"description": "Whether the group is enabled by default.", | ||
"type": "boolean" | ||
} | ||
}, | ||
"required": [ | ||
"name", | ||
"regex", | ||
"default" | ||
], | ||
"additionalProperties": false | ||
}, | ||
"regexlist": { | ||
"description": "A list of regular expressions.", | ||
"oneOf": [ | ||
{ | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
}, | ||
"rule": { | ||
"type": "object", | ||
"properties": { | ||
"exclude": { | ||
"description": "A regular expression for paths to exclude.", | ||
"$ref": "#/definitions/regexlist" | ||
}, | ||
"suppress": { | ||
"description": "A regular expression for messages to suppress.", | ||
"$ref": "#/definitions/regexlist" | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
"ruleList": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/definitions/rule" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"properties": { | ||
"groups": { | ||
"description": "A definition of all groups.", | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/group" | ||
}, | ||
"minItems": 1 | ||
}, | ||
"global": { | ||
"description": "A global set of rules.", | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/definitions/rule" | ||
} | ||
}, | ||
"analyzers": { | ||
"description": "A definition of all groups.", | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/definitions/ruleList" | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"groups" | ||
], | ||
"additionalProperties": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
load("//tools:defs.bzl", "go_binary") | ||
|
||
package(licenses = ["notice"]) | ||
|
||
go_binary( | ||
name = "yamltest", | ||
srcs = ["main.go"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@com_github_xeipuuv_gojsonschema//:go_default_library", | ||
"@in_gopkg_yaml_v2//:go_default_library", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Tools for testing yaml files against schemas.""" | ||
|
||
def _yaml_test_impl(ctx): | ||
"""Implementation for yaml_test.""" | ||
runner = ctx.actions.declare_file(ctx.label.name) | ||
ctx.actions.write(runner, "\n".join([ | ||
"#!/bin/bash", | ||
"set -euo pipefail", | ||
"%s -schema=%s -- %s" % ( | ||
ctx.files._tool[0].short_path, | ||
ctx.files.schema[0].short_path, | ||
" ".join([f.short_path for f in ctx.files.srcs]), | ||
), | ||
]), is_executable = True) | ||
return [DefaultInfo( | ||
runfiles = ctx.runfiles(files = ctx.files._tool + ctx.files.schema + ctx.files.srcs), | ||
executable = runner, | ||
)] | ||
|
||
yaml_test = rule( | ||
implementation = _yaml_test_impl, | ||
doc = "Tests a yaml file against a schema.", | ||
attrs = { | ||
"srcs": attr.label_list( | ||
doc = "The input yaml files.", | ||
mandatory = True, | ||
allow_files = True, | ||
), | ||
"schema": attr.label( | ||
doc = "The schema file in JSON schema format.", | ||
allow_single_file = True, | ||
mandatory = True, | ||
), | ||
"_tool": attr.label( | ||
executable = True, | ||
cfg = "host", | ||
default = Label("//tools/yamltest:yamltest"), | ||
), | ||
}, | ||
test = True, | ||
) |
Oops, something went wrong.