Skip to content

Commit 891d026

Browse files
committed
First workflow2
1 parent 4eac02c commit 891d026

21 files changed

+604
-61
lines changed

.github/workflows/annotate_specification.yml renamed to .github/workflows/annotation_workflow.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: JSON Tests Workflow
1+
name: Specifications Annotation Workflow
22

33
on:
44
pull_request:
@@ -7,11 +7,11 @@ on:
77

88
jobs:
99
run_tests:
10-
name: Run JSON Schema Tests
10+
name: logging annotations
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- name: Checkout Repository
14+
- name: Checkout Repository
1515
uses: actions/checkout@v3
1616

1717
- name: Set up Python
@@ -23,7 +23,7 @@ jobs:
2323
run: pip install PyGithub
2424

2525
- name: Run Python script
26-
run: python json_tests_workflow.py
26+
run: python bin/annotation_workflow.py
2727
env:
2828
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2929
GITHUB_REF: ${{ github.ref }}

.github/workflows/json_tests_workflow.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

bin/annotation_workflow.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from github import Github
2+
import os
3+
import sys
4+
import json
5+
import re
6+
7+
8+
def print_github_action_notice(file_name, message):
9+
print(f"::notice file={file_name}::{message}")
10+
11+
def main():
12+
13+
# Get GITHUB_TOKEN from environment variables automatically
14+
g = Github(os.environ.get('GITHUB_TOKEN'))
15+
16+
# Get repository and pull request number from environment variables
17+
repo_name = os.environ.get('GITHUB_REPOSITORY')
18+
19+
# Extract pull request number from GITHUB_REF if it's a pull request event
20+
event_name = os.environ.get('GITHUB_EVENT_NAME')
21+
if event_name == 'pull_request':
22+
pull_request_number = os.environ.get('GITHUB_REF').split('/')[-2]
23+
else:
24+
print("Not a pull request event.")
25+
sys.exit(1)
26+
27+
if not repo_name or not pull_request_number:
28+
print("Repository name or pull request number not found in environment variables.")
29+
sys.exit(1)
30+
31+
# Get repository object
32+
repo = g.get_repo(repo_name)
33+
34+
# Get the pull request object
35+
pr = repo.get_pull(int(pull_request_number))
36+
37+
# Get the list of changed files in the pull request
38+
changed_files = [file.filename for file in pr.get_files()]
39+
40+
print(changed_files)
41+
# Traverse each file in the 'tests' folder and print JSON content
42+
for file in changed_files:
43+
if file.startswith('tests/'):
44+
# Read the file content
45+
draft = file.split('/')[1]
46+
47+
urls = json.loads(repo.get_contents("specification_urls.json").decoded_content.decode('utf-8'))
48+
49+
branch_name = pr.head.ref
50+
changed_file_content = repo.get_contents(file, ref=branch_name).decoded_content.decode('utf-8')
51+
52+
# Parse JSON content
53+
try:
54+
json_content = json.loads(changed_file_content)
55+
for test in json_content:
56+
if "specification" in test:
57+
for specification_object in test["specification"]:
58+
for spec, section in specification_object.items():
59+
if spec in ["core", "validation", "hyper-schema"]: print_github_action_notice(file, urls[draft][spec] + section)
60+
elif spec in ["quote"]: continue
61+
elif spec in ["ecma262", "perl5"]: print_github_action_notice(file, urls[spec] + section)
62+
elif re.match("^rfc\\d+$", spec): print_github_action_notice(file, urls["rfc"] + spec + ".txt#" + section)
63+
else: print_github_action_notice(file, urls["iso"])
64+
except json.JSONDecodeError as e:
65+
print(f"Error parsing JSON in file '{file}': {e}")
66+
67+
if __name__ == "__main__":
68+
main()

bin/specification_urls.json

Lines changed: 34 additions & 0 deletions
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.",
7+
"validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.",
8+
"hyper-schema": "https://json-schema.org/draft-04/draft-luff-json-hyper-schema-00#rfc.section."
9+
},
10+
"draft6": {
11+
"core": "https://json-schema.org/draft-06/draft-wright-json-schema-01#rfc.section.",
12+
"validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.",
13+
"hyper-schema": "https://json-schema.org/draft-06/draft-wright-json-schema-hyperschema-01#rfc.section."
14+
},
15+
"draft7": {
16+
"core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.",
17+
"validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.",
18+
"hyper-schema": "https://json-schema.org/draft-07/draft-handrews-json-schema-hyperschema-01#rfc.section."
19+
},
20+
"draft2019-09": {
21+
"core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.",
22+
"validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.",
23+
"hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section."
24+
},
25+
"draft2020-12": {
26+
"core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-",
27+
"validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-",
28+
"hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section."
29+
},
30+
"ecma262": "https://262.ecma-international.org/",
31+
"perl5": "https://perldoc.perl.org/perlre#",
32+
"rfc": "https://www.rfc-editor.org/rfc/",
33+
"iso": "https://www.iso.org/obp/ui"
34+
}

tests/draft-next/additionalProperties.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,73 @@
176176
"valid": false
177177
}
178178
]
179+
},
180+
{
181+
"description": "propertyDependencies with additionalProperties",
182+
"schema": {
183+
"$schema": "https://json-schema.org/draft/next/schema",
184+
"properties" : {"foo2" : {}},
185+
"propertyDependencies": {
186+
"foo" : {},
187+
"foo2": {
188+
"bar": {
189+
"properties": {
190+
"buz": {}
191+
}
192+
}
193+
}
194+
},
195+
"additionalProperties": false
196+
},
197+
"tests": [
198+
{
199+
"description": "additionalProperties doesn't consider propertyDependencies properties" ,
200+
"data": {"foo": ""},
201+
"valid": false
202+
},
203+
{
204+
"description": "additionalProperties can't see buz even when foo2 is present",
205+
"data": {"foo2": "bar", "buz": ""},
206+
"valid": false
207+
},
208+
{
209+
"description": "additionalProperties can't see buz",
210+
"data": {"buz": ""},
211+
"valid": false
212+
}
213+
]
214+
},
215+
{
216+
"description": "dependentSchemas with additionalProperties",
217+
"schema": {
218+
"$schema": "https://json-schema.org/draft/next/schema",
219+
"properties": {"foo2": {}},
220+
"dependentSchemas": {
221+
"foo": {},
222+
"foo2": {
223+
"properties": {
224+
"bar": {}
225+
}
226+
}
227+
},
228+
"additionalProperties": false
229+
},
230+
"tests": [
231+
{
232+
"description": "additionalProperties doesn't consider dependentSchemas",
233+
"data": {"foo": ""},
234+
"valid": false
235+
},
236+
{
237+
"description": "additionalProperties can't see bar",
238+
"data": {"bar": ""},
239+
"valid": false
240+
},
241+
{
242+
"description": "additionalProperties can't see bar even when foo2 is present",
243+
"data": {"foo2": "", "bar": ""},
244+
"valid": false
245+
}
246+
]
179247
}
180248
]

tests/draft-next/dynamicRef.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,5 +642,60 @@
642642
"valid": false
643643
}
644644
]
645+
},
646+
{
647+
"description": "$dynamicRef skips over intermediate resources - direct reference",
648+
"schema": {
649+
"$schema": "https://json-schema.org/draft/next/schema",
650+
"$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main",
651+
"type": "object",
652+
"properties": {
653+
"bar-item": {
654+
"$ref": "item"
655+
}
656+
},
657+
"$defs": {
658+
"bar": {
659+
"$id": "bar",
660+
"type": "array",
661+
"items": {
662+
"$ref": "item"
663+
},
664+
"$defs": {
665+
"item": {
666+
"$id": "item",
667+
"type": "object",
668+
"properties": {
669+
"content": {
670+
"$dynamicRef": "#content"
671+
}
672+
},
673+
"$defs": {
674+
"defaultContent": {
675+
"$dynamicAnchor": "content",
676+
"type": "integer"
677+
}
678+
}
679+
},
680+
"content": {
681+
"$dynamicAnchor": "content",
682+
"type": "string"
683+
}
684+
}
685+
}
686+
}
687+
},
688+
"tests": [
689+
{
690+
"description": "integer property passes",
691+
"data": { "bar-item": { "content": 42 } },
692+
"valid": true
693+
},
694+
{
695+
"description": "string property fails",
696+
"data": { "bar-item": { "content": "value" } },
697+
"valid": false
698+
}
699+
]
645700
}
646701
]

tests/draft-next/oneOf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
}
221221
]
222222
},
223-
{
223+
{
224224
"description": "oneOf with missing optional property",
225225
"schema": {
226226
"$schema": "https://json-schema.org/draft/next/schema",
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[
2+
{
3+
"description": "$dynamicRef skips over intermediate resources - pointer reference across resource boundary",
4+
"schema": {
5+
"$schema": "https://json-schema.org/draft/next/schema",
6+
"$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/optional/main",
7+
"type": "object",
8+
"properties": {
9+
"bar-item": {
10+
"$ref": "bar#/$defs/item"
11+
}
12+
},
13+
"$defs": {
14+
"bar": {
15+
"$id": "bar",
16+
"type": "array",
17+
"items": {
18+
"$ref": "item"
19+
},
20+
"$defs": {
21+
"item": {
22+
"$id": "item",
23+
"type": "object",
24+
"properties": {
25+
"content": {
26+
"$dynamicRef": "#content"
27+
}
28+
},
29+
"$defs": {
30+
"defaultContent": {
31+
"$dynamicAnchor": "content",
32+
"type": "integer"
33+
}
34+
}
35+
},
36+
"content": {
37+
"$dynamicAnchor": "content",
38+
"type": "string"
39+
}
40+
}
41+
}
42+
}
43+
},
44+
"tests": [
45+
{
46+
"description": "integer property passes",
47+
"data": { "bar-item": { "content": 42 } },
48+
"valid": true
49+
},
50+
{
51+
"description": "string property fails",
52+
"data": { "bar-item": { "content": "value" } },
53+
"valid": false
54+
}
55+
]
56+
}]

0 commit comments

Comments
 (0)