From f45f064bdb4fabcef21a0628fbf633981f25a1d3 Mon Sep 17 00:00:00 2001 From: vsoch Date: Mon, 22 Jan 2024 16:48:47 -0700 Subject: [PATCH] ci: add schema validation and drafts Signed-off-by: vsoch --- .github/requirements.txt | 1 + .github/validate.py | 50 ++++++++++++++++++++++++++ .github/workflows/check-compspecs.yaml | 18 ++++++++++ README.md | 2 +- archspec/compspec.json | 14 ++++++++ definition-schema.json | 28 +++++++++++++++ schema.json | 33 +++++++++++++++++ supercontainers/compspec.json | 34 ++++++++++++++++++ 8 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 .github/requirements.txt create mode 100644 .github/validate.py create mode 100644 .github/workflows/check-compspecs.yaml create mode 100644 archspec/compspec.json create mode 100644 definition-schema.json create mode 100644 schema.json create mode 100644 supercontainers/compspec.json diff --git a/.github/requirements.txt b/.github/requirements.txt new file mode 100644 index 0000000..d89304b --- /dev/null +++ b/.github/requirements.txt @@ -0,0 +1 @@ +jsonschema diff --git a/.github/validate.py b/.github/validate.py new file mode 100644 index 0000000..981b965 --- /dev/null +++ b/.github/validate.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import sys +import os +import re +import json +import jsonschema + +here = os.path.abspath(__file__) +root = os.path.dirname(os.path.dirname(here)) + +schema_file = os.path.join(root, "definition-schema.json") + +def recursive_find(base, pattern="compspec.json"): + """ + Find all compspec.json below a root + """ + for root, _, filenames in os.walk(base): + for filename in filenames: + fullpath = os.path.join(root, filename) + if re.search(pattern, fullpath): + yield fullpath + + +def read_json(filename): + with open(filename, "r") as fd: + content = json.loads(fd.read()) + return content + + +def main(root): + """ + Validate the format of WIP prototype specs. + """ + root = os.path.abspath(root) + if not os.path.exists(root): + sys.exit(f"{root} does not exist.") + specs = recursive_find(root) + + schema = read_json(schema_file) + for spec_file in specs: + print(f"⭐️ Validating spec {spec_file}") + spec = read_json(spec_file) + jsonschema.validate(spec, schema=schema) + + +if __name__ == "__main__": + if len(sys.argv) > 1: + root = sys.argv[1] + main(root) diff --git a/.github/workflows/check-compspecs.yaml b/.github/workflows/check-compspecs.yaml new file mode 100644 index 0000000..2694aea --- /dev/null +++ b/.github/workflows/check-compspecs.yaml @@ -0,0 +1,18 @@ +name: check compatibility specs + +on: + workflow_dispatch: + pull_request: [] + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + - name: Run Validation + run: | + sudo apt-get update && sudo apt-get install -y python3 python3-pip python3-setuptools wget + sudo pip3 install -r .github/requirements.txt + python3 .github/validate.py . + diff --git a/README.md b/README.md index e148e69..66f4f56 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is a prototype repository for compatibility specifications that are being w ## JSON Schema Specifications - - [schema.json]schema.json) is used to validate the format of a json defining compatibiilty. + - [schema.json](schema.json) is used to validate the format of a json defining compatibiilty. - [definition-schema.json](definition-schema.json) is to validate the format of the keys for each namespace (in the subdirectories here) Both of the above are based on [Proposal C](https://github.com/opencontainers/wg-image-compatibility/pull/8) of the Image Compatibility working group, and everything is subject to change. This repository is for prototyping only. diff --git a/archspec/compspec.json b/archspec/compspec.json new file mode 100644 index 0000000..922c98f --- /dev/null +++ b/archspec/compspec.json @@ -0,0 +1,14 @@ +{ + "compatibilities": { + "version": "0.0.0", + "io.archspec.cpu": { + "annotations": [ + "family", + "model", + "target", + "vendor" + ] + } + } +} + diff --git a/definition-schema.json b/definition-schema.json new file mode 100644 index 0000000..b2e7561 --- /dev/null +++ b/definition-schema.json @@ -0,0 +1,28 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Schema for the definitions of the known labels", + "type": "object", + "additionalProperties": false, + "properties": { + "compatibilities": { + "type": "object", + "properties": { + "version": { + "$comment": "Version of the metadata namespace", + "type": "string" + }, + "patternProperties": { + "([\\w]*)": { + "annotations": { + "$comment": "Acceptable keys for a given namespace.", + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + } + } +} diff --git a/schema.json b/schema.json new file mode 100644 index 0000000..bdf64a6 --- /dev/null +++ b/schema.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Schema for the definitions of the known labels", + "type": "object", + "additionalProperties": false, + "properties": { + "compatibilities": { + "type": "object", + "properties": { + "version": { + "$comment": "Version of the metadata namespace", + "type": "string" + }, + "patternProperties": { + "([\\w]*)": { + "annotations": { + "$comment": "Key value pairs for a given namespace.", + "type": "array", + "items": { + "type": "object", + "patternProperties": { + "\\w[\\w-]*": { + "type": "string" + } + } + } + } + } + } + } + } + } +} diff --git a/supercontainers/compspec.json b/supercontainers/compspec.json new file mode 100644 index 0000000..19c49a0 --- /dev/null +++ b/supercontainers/compspec.json @@ -0,0 +1,34 @@ +{ + "compatibilities": { + "version": "0.0.0", + "org.supercontainers.mpi": { + "annotations": [ + "implementation", + "portability.optimization", + "porability.mode" + ] + }, + "org.supercontainers.hardware.gpu": { + "annotations": [ + "driver.version", + "cuda.version", + "architecture" + ] + }, + "org.supercontainers.communication": { + "annotations": [ + "framework" + ] + }, + "org.supercontainers.openmpi": { + "annotations": [ + "version" + ] + }, + "org.supercontainers.libfabric": { + "annotations": [ + "abi.version" + ] + } + } +}