-
-
Notifications
You must be signed in to change notification settings - Fork 219
Adding CI workflow for annotations of specification property #742
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
Closed
Closed
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 4eac02c
First workflow
suprith-hub 810d148
First workflow2
suprith-hub eecc7b7
Merge branch 'main' of https://github.com/Era-cell/JSON-Schema-Test-S…
suprith-hub 3558c2c
Fake add to tests
suprith-hub ce52852
Python file location changed
suprith-hub 79dc92f
TOKEN
suprith-hub cbdd175
change day2
suprith-hub c6b937c
Reading all jsons and spec urls added
suprith-hub df3bdec
path corrected
suprith-hub 582e12b
logging logs check
suprith-hub f29d090
Wrong location sepcification
suprith-hub 540a269
Log2
suprith-hub eb8fd76
Branch name specified
suprith-hub 77527b6
Stupidity corrected
suprith-hub 5f050a0
Final correction1
suprith-hub 96f7683
Final correction2 - file names beautufied
suprith-hub 1c17519
regex correction
suprith-hub 891d026
First workflow2
suprith-hub 7b84fb4
Merge branch 'main' of https://github.com/Era-cell/JSON-Schema-Test-S…
suprith-hub 564e695
Walking through all leaf files
suprith-hub 7b40efe
Base path for neighbouring file?
suprith-hub e88a2da
Works for all OS
suprith-hub 2b1ffb7
Best practices followed with optimized code
suprith-hub 0b780b2
Corected yaml format
suprith-hub 2367412
Cases for rfc and iso written separately
suprith-hub 3a50900
Clear existin annotations on same PR
suprith-hub f276661
template library, url loads changes
suprith-hub 11f8e51
Added installing command in workflow
suprith-hub 57c7c86
changed install location
suprith-hub d8ade40
inside run
suprith-hub e4bd755
dumbness2 corrected
suprith-hub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
||
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.