Skip to content

Commit

Permalink
Add support for YAML config/build files (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Mar 1, 2021
1 parent 76805c6 commit 8bdebc6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path

from jsonschema import Draft7Validator, ValidationError, validators
import yaml


def check_is_default(validator_class):
Expand Down Expand Up @@ -37,13 +38,21 @@ def is_default(validator, properties, instance, schema):
print(f"::error ::Add-on configuration path not found: {path}")
sys.exit(1)

config = path / "config.json"
for file_type in ("json", "yaml", "yml"):
config = path / f"config.{file_type}"
if config.exists():
break

if not config.exists():
print(f"::error ::Add-on configuration file not found: {config}")
print(f"::error ::Add-on configuration file not found in '{path}'")
sys.exit(1)


with open(config) as fp:
configuration = json.load(fp)
if config.suffix == "json":
configuration = json.load(fp)
else:
configuration = yaml.load(fp)

with open("/config.schema.json") as fp:
schema = json.load(fp)
Expand Down Expand Up @@ -122,11 +131,18 @@ def is_default(validator, properties, instance, schema):
)
exit_code = 1

# Checks regarding build.json (if found)
build = path / "build.json"
# Checks regarding build file(if found)
for file_type in ("json", "yaml", "yml"):
build = path / f"build.{file_type}"
if build.exists():
break

if build.exists():
with open(build) as fp:
build_configuration = json.load(fp)
if build.suffix == "json":
build_configuration = json.load(fp)
else:
build_configuration = yaml.load(fp)

with open("/build.schema.json") as fp:
build_schema = json.load(fp)
Expand Down
1 change: 1 addition & 0 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
jsonschema==3.2.0
pyyaml==5.4.1

0 comments on commit 8bdebc6

Please sign in to comment.