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

Adding CI workflow for annotations of specification property #742

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
40bcb8b
Corrected replaced unevaluated with additoinalProperties
suprith-hub Apr 17, 2024
4eac02c
First workflow
suprith-hub Apr 23, 2024
810d148
First workflow2
suprith-hub Apr 23, 2024
eecc7b7
Merge branch 'main' of https://github.com/Era-cell/JSON-Schema-Test-S…
suprith-hub Apr 23, 2024
3558c2c
Fake add to tests
suprith-hub Apr 23, 2024
ce52852
Python file location changed
suprith-hub Apr 23, 2024
79dc92f
TOKEN
suprith-hub Apr 23, 2024
cbdd175
change day2
suprith-hub Apr 24, 2024
c6b937c
Reading all jsons and spec urls added
suprith-hub Apr 24, 2024
df3bdec
path corrected
suprith-hub Apr 24, 2024
582e12b
logging logs check
suprith-hub Apr 24, 2024
f29d090
Wrong location sepcification
suprith-hub Apr 24, 2024
540a269
Log2
suprith-hub Apr 24, 2024
eb8fd76
Branch name specified
suprith-hub Apr 24, 2024
77527b6
Stupidity corrected
suprith-hub Apr 24, 2024
5f050a0
Final correction1
suprith-hub Apr 24, 2024
96f7683
Final correction2 - file names beautufied
suprith-hub Apr 24, 2024
1c17519
regex correction
suprith-hub Apr 24, 2024
891d026
First workflow2
suprith-hub Apr 23, 2024
7b84fb4
Merge branch 'main' of https://github.com/Era-cell/JSON-Schema-Test-S…
suprith-hub Apr 24, 2024
564e695
Walking through all leaf files
suprith-hub Apr 30, 2024
7b40efe
Base path for neighbouring file?
suprith-hub Apr 30, 2024
e88a2da
Works for all OS
suprith-hub Apr 30, 2024
2b1ffb7
Best practices followed with optimized code
suprith-hub Apr 30, 2024
0b780b2
Corected yaml format
suprith-hub Apr 30, 2024
2367412
Cases for rfc and iso written separately
suprith-hub Apr 30, 2024
3a50900
Clear existin annotations on same PR
suprith-hub Apr 30, 2024
f276661
template library, url loads changes
suprith-hub May 8, 2024
11f8e51
Added installing command in workflow
suprith-hub May 8, 2024
57c7c86
changed install location
suprith-hub May 8, 2024
d8ade40
inside run
suprith-hub May 8, 2024
e4bd755
dumbness2 corrected
suprith-hub May 8, 2024
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
23 changes: 23 additions & 0 deletions .github/workflows/show_specification_annotations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Show Specification Annotations

on:
pull_request:
paths:
- 'tests/**'

jobs:
annotate:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Generate Annotations
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Run Python script
run: |
pip install uritemplate
python bin/annotation_workflow.py
75 changes: 75 additions & 0 deletions bin/annotation_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import json, re
from pathlib import Path
import uritemplate

def github_action_notice(path, url, line):
"""
Return a GitHub action notice with file path, URL, and line number.

Parameters:
path (str): File path.
url (str): URL.
line (int): Line number.
"""
return f"::warning file={path},line={line}::Annotation: {url}"

def find_test_line_number(test_content, test_name):
"""
Find the line number of a test in the JSON content.

Parameters:
test_content (str): JSON content.
test_name (str): Test name.

Returns:
int: Line number of the test.
"""
lines = test_content.split("\n")
for i, line in enumerate(lines, start=1):
if test_name in line:
return i
return 1

def clear_previous_annotations():
"""
Clear previous GitHub action annotations.
"""
print("::remove-matcher owner=me::")

json_file_path = Path("bin/specification_urls.json")
suprith-hub marked this conversation as resolved.
Show resolved Hide resolved

BIN_DIR = Path(__file__).parent
urls = json.loads(BIN_DIR.joinpath("specification_urls.json").read_text())

clear_previous_annotations()

for file_path in Path("tests").rglob("*.json"):

with file_path.open("r", encoding="utf-8") as f:
changed_file_content = f.read()

try:
suprith-hub marked this conversation as resolved.
Show resolved Hide resolved
json_content = json.loads(changed_file_content)
except json.JSONDecodeError:
print(f"::error file={file_path}::Failed to parse JSON content")

for test in json_content:
if "specification" in test:
line_number = find_test_line_number(changed_file_content, test.get("description") )

for specification_object in test["specification"]:
for spec, section in specification_object.items():
draft = file_path.parent.name
if spec in ["quote"]:
continue
elif spec in ["core", "validation", "hyper-schema"]:
template = uritemplate.URITemplate(urls[draft][spec])
elif re.match("^rfc\\d+$", spec):
template = uritemplate.URITemplate(urls["rfc"])
elif re.match("^iso\\d+$", spec):
template = uritemplate.URITemplate(urls["iso"])
else:
template = uritemplate.URITemplate(urls[spec])
url = template.expand(spec=spec, section=section)

print(github_action_notice(file_path, url, line_number))
34 changes: 34 additions & 0 deletions bin/specification_urls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"draft3": {
"core": "https://json-schema.org/draft-03/draft-zyp-json-schema-03.pdf"
},
"draft4": {
"core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04#rfc.section.{section}",
"validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.{section}",
"hyper-schema": "https://json-schema.org/draft-04/draft-luff-json-hyper-schema-00#rfc.section.{section}"
},
"draft6": {
"core": "https://json-schema.org/draft-06/draft-wright-json-schema-01#rfc.section.{section}",
"validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.{section}",
"hyper-schema": "https://json-schema.org/draft-06/draft-wright-json-schema-hyperschema-01#rfc.section.{section}"
},
"draft7": {
"core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.{section}",
"validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.{section}",
"hyper-schema": "https://json-schema.org/draft-07/draft-handrews-json-schema-hyperschema-01#rfc.section.{section}"
},
"draft2019-09": {
"core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.{section}",
"validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.{section}",
"hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section.{section}"
},
"draft2020-12": {
"core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-{section}",
"validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-{section}",
"hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section.{section}"
},
"ecma262": "https://262.ecma-international.org/{section}",
"perl5": "https://perldoc.perl.org/perlre#{section}",
"rfc": "https://www.rfc-editor.org/rfc/{spec}.txt#{section}",
"iso": "https://www.iso.org/obp/ui"
}
3 changes: 1 addition & 2 deletions tests/draft2020-12/additionalProperties.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[
{
"description":
"additionalProperties being false does not allow other properties",
"description": "additionalProperties being false does not allow other properties",

Check warning on line 3 in tests/draft2020-12/additionalProperties.json

View workflow job for this annotation

GitHub Actions / annotate

Annotation: https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-10.3.2.3
"specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema. Boolean \"false\" forbids everything." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
Expand Down Expand Up @@ -43,7 +42,7 @@
]
},
{
"description": "non-ASCII pattern with additionalProperties",

Check warning on line 45 in tests/draft2020-12/additionalProperties.json

View workflow job for this annotation

GitHub Actions / annotate

Annotation: https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-10.3.2.3
"specification": [ { "core":"10.3.2.3"} ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
Expand All @@ -64,7 +63,7 @@
]
},
{
"description": "additionalProperties with schema",

Check warning on line 66 in tests/draft2020-12/additionalProperties.json

View workflow job for this annotation

GitHub Actions / annotate

Annotation: https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-10.3.2.3
"specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
Expand All @@ -90,7 +89,7 @@
]
},
{
"description": "additionalProperties can exist by itself",

Check warning on line 92 in tests/draft2020-12/additionalProperties.json

View workflow job for this annotation

GitHub Actions / annotate

Annotation: https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-10.3.2.3
"specification": [ { "core":"10.3.2.3", "quote": "With no other applicator applying to object instances. This validates all the instance values irrespective of their property names" } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
Expand All @@ -110,7 +109,7 @@
]
},
{
"description": "additionalProperties are allowed by default",

Check warning on line 112 in tests/draft2020-12/additionalProperties.json

View workflow job for this annotation

GitHub Actions / annotate

Annotation: https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-10.3.2.3
"specification": [ { "core":"10.3.2.3", "quote": "Omitting this keyword has the same assertion behavior as an empty schema." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
Expand All @@ -125,7 +124,7 @@
]
},
{
"description": "additionalProperties does not look in applicators",

Check warning on line 127 in tests/draft2020-12/additionalProperties.json

View workflow job for this annotation

GitHub Actions / annotate

Annotation: https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-10.2
"specification":[ { "core": "10.2", "quote": "Subschemas of applicator keywords evaluate the instance completely independently such that the results of one such subschema MUST NOT impact the results of sibling subschemas." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
Expand All @@ -143,7 +142,7 @@
]
},
{
"description": "additionalProperties with null valued instance properties",

Check warning on line 145 in tests/draft2020-12/additionalProperties.json

View workflow job for this annotation

GitHub Actions / annotate

Annotation: https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-10.3.2.3
"specification": [ { "core":"10.3.2.3" } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
Expand Down
Loading