Skip to content

Commit 4ebbeaf

Browse files
committed
Merge branch 'Era-cell/main'
* Era-cell/main: dumbness2 corrected inside run changed install location Added installing command in workflow template library, url loads changes Clear existin annotations on same PR Cases for rfc and iso written separately Corected yaml format Best practices followed with optimized code Works for all OS Base path for neighbouring file? Walking through all leaf files First workflow2 regex correction Final correction2 - file names beautufied Final correction1 Stupidity corrected Branch name specified Log2 Wrong location sepcification logging logs check path corrected Reading all jsons and spec urls added change day2 TOKEN Python file location changed Fake add to tests First workflow2 First workflow Corrected replaced unevaluated with additoinalProperties
2 parents c2badb1 + e4bd755 commit 4ebbeaf

File tree

4 files changed

+133
-2
lines changed

4 files changed

+133
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Show Specification Annotations
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'tests/**'
7+
8+
jobs:
9+
annotate:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Generate Annotations
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.x'
19+
20+
- name: Run Python script
21+
run: |
22+
pip install uritemplate
23+
python bin/annotation_workflow.py

bin/annotation_workflow.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import json, re
2+
from pathlib import Path
3+
import uritemplate
4+
5+
def github_action_notice(path, url, line):
6+
"""
7+
Return a GitHub action notice with file path, URL, and line number.
8+
9+
Parameters:
10+
path (str): File path.
11+
url (str): URL.
12+
line (int): Line number.
13+
"""
14+
return f"::warning file={path},line={line}::Annotation: {url}"
15+
16+
def find_test_line_number(test_content, test_name):
17+
"""
18+
Find the line number of a test in the JSON content.
19+
20+
Parameters:
21+
test_content (str): JSON content.
22+
test_name (str): Test name.
23+
24+
Returns:
25+
int: Line number of the test.
26+
"""
27+
lines = test_content.split("\n")
28+
for i, line in enumerate(lines, start=1):
29+
if test_name in line:
30+
return i
31+
return 1
32+
33+
def clear_previous_annotations():
34+
"""
35+
Clear previous GitHub action annotations.
36+
"""
37+
print("::remove-matcher owner=me::")
38+
39+
json_file_path = Path("bin/specification_urls.json")
40+
41+
BIN_DIR = Path(__file__).parent
42+
urls = json.loads(BIN_DIR.joinpath("specification_urls.json").read_text())
43+
44+
clear_previous_annotations()
45+
46+
for file_path in Path("tests").rglob("*.json"):
47+
48+
with file_path.open("r", encoding="utf-8") as f:
49+
changed_file_content = f.read()
50+
51+
try:
52+
json_content = json.loads(changed_file_content)
53+
except json.JSONDecodeError:
54+
print(f"::error file={file_path}::Failed to parse JSON content")
55+
56+
for test in json_content:
57+
if "specification" in test:
58+
line_number = find_test_line_number(changed_file_content, test.get("description") )
59+
60+
for specification_object in test["specification"]:
61+
for spec, section in specification_object.items():
62+
draft = file_path.parent.name
63+
if spec in ["quote"]:
64+
continue
65+
elif spec in ["core", "validation", "hyper-schema"]:
66+
template = uritemplate.URITemplate(urls[draft][spec])
67+
elif re.match("^rfc\\d+$", spec):
68+
template = uritemplate.URITemplate(urls["rfc"])
69+
elif re.match("^iso\\d+$", spec):
70+
template = uritemplate.URITemplate(urls["iso"])
71+
else:
72+
template = uritemplate.URITemplate(urls[spec])
73+
url = template.expand(spec=spec, section=section)
74+
75+
print(github_action_notice(file_path, url, line_number))

bin/specification_urls.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"draft3": {
3+
"core": "https://json-schema.org/draft-03/draft-zyp-json-schema-03.pdf"
4+
},
5+
"draft4": {
6+
"core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04#rfc.section.{section}",
7+
"validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.{section}",
8+
"hyper-schema": "https://json-schema.org/draft-04/draft-luff-json-hyper-schema-00#rfc.section.{section}"
9+
},
10+
"draft6": {
11+
"core": "https://json-schema.org/draft-06/draft-wright-json-schema-01#rfc.section.{section}",
12+
"validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.{section}",
13+
"hyper-schema": "https://json-schema.org/draft-06/draft-wright-json-schema-hyperschema-01#rfc.section.{section}"
14+
},
15+
"draft7": {
16+
"core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.{section}",
17+
"validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.{section}",
18+
"hyper-schema": "https://json-schema.org/draft-07/draft-handrews-json-schema-hyperschema-01#rfc.section.{section}"
19+
},
20+
"draft2019-09": {
21+
"core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.{section}",
22+
"validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.{section}",
23+
"hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section.{section}"
24+
},
25+
"draft2020-12": {
26+
"core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-{section}",
27+
"validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-{section}",
28+
"hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section.{section}"
29+
},
30+
"ecma262": "https://262.ecma-international.org/{section}",
31+
"perl5": "https://perldoc.perl.org/perlre#{section}",
32+
"rfc": "https://www.rfc-editor.org/rfc/{spec}.txt#{section}",
33+
"iso": "https://www.iso.org/obp/ui"
34+
}

tests/draft2020-12/additionalProperties.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[
22
{
3-
"description":
4-
"additionalProperties being false does not allow other properties",
3+
"description": "additionalProperties being false does not allow other properties",
54
"specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema. Boolean \"false\" forbids everything." } ],
65
"schema": {
76
"$schema": "https://json-schema.org/draft/2020-12/schema",

0 commit comments

Comments
 (0)