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

ci: add schema validation and drafts #1

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jsonschema
50 changes: 50 additions & 0 deletions .github/validate.py
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions .github/workflows/check-compspecs.yaml
Original file line number Diff line number Diff line change
@@ -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 .

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions archspec/compspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compatibilities": {
"version": "0.0.0",
"io.archspec.cpu": {
"annotations": [
"family",
"model",
"target",
"vendor"
]
}
}
}

28 changes: 28 additions & 0 deletions definition-schema.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
}
}
33 changes: 33 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
}
}
}
}
34 changes: 34 additions & 0 deletions supercontainers/compspec.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}