Skip to content

Commit 8a04495

Browse files
committed
Merge branch 'feature-branch' of https://github.com/Era-cell/JSON-Schema-Test-Suite into feature-branch
2 parents 9a2612a + a4fb199 commit 8a04495

File tree

2 files changed

+29
-63
lines changed

2 files changed

+29
-63
lines changed

.github/workflows/annotation_workflow.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,5 @@ jobs:
1919
with:
2020
python-version: '3.x'
2121

22-
- name: Install dependencies
23-
run: pip install PyGithub
24-
2522
- name: Run Python script
2623
run: python bin/annotation_workflow.py
27-
env:
28-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29-
GITHUB_REF: ${{ github.ref }}
30-
GITHUB_REPOSITORY: ${{ github.repository }}
31-

bin/annotation_workflow.py

Lines changed: 29 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,43 @@
1-
from github import Github
2-
import os
3-
import sys
41
import json
2+
import os
53
import re
4+
from pathlib import Path
65

6+
# Function to print GitHub action notice
7+
def print_github_action_notice(file, url):
8+
print(f"::warning file={file},line=1::Annotation: {url}")
79

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)
10+
# Read specification URLs from JSON file
11+
with open("bin/specification_urls.json", "r") as f:
12+
urls = json.load(f)
3313

34-
# Get the pull request object
35-
pr = repo.get_pull(int(pull_request_number))
14+
# Iterate through JSON files in tests folder and subdirectories
15+
for root, dirs, files in os.walk("tests"):
16+
for file_name in files:
17+
if file_name.endswith(".json"):
18+
file_path = os.path.join(root, file_name)
3619

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/'):
4420
# Read the file content
45-
draft = file.split('/')[1]
46-
47-
urls = json.loads(repo.get_contents("bin/specification_urls.json").decoded_content.decode('utf-8'))
48-
49-
50-
branch_name = pr.head.ref
51-
changed_file_content = repo.get_contents(file, ref=branch_name).decoded_content.decode('utf-8')
52-
21+
with open(file_path, 'r', encoding='utf-8') as f:
22+
changed_file_content = f.read()
23+
5324
# Parse JSON content
5425
try:
5526
json_content = json.loads(changed_file_content)
5627
for test in json_content:
5728
if "specification" in test:
5829
for specification_object in test["specification"]:
5930
for spec, section in specification_object.items():
60-
if spec in ["core", "validation", "hyper-schema"]: print_github_action_notice(file, urls[draft][spec] + section)
61-
elif spec in ["quote"]: continue
62-
elif spec in ["ecma262", "perl5"]: print_github_action_notice(file, urls[spec] + section)
63-
elif re.match("^rfc\\d+$"): print_github_action_notice(file, urls["rfc"] + spec + ".txt#" + section)
64-
else: print_github_action_notice(file, urls["iso"])
65-
except json.JSONDecodeError as e:
66-
print(f"Error parsing JSON in file '{file}': {e}")
67-
68-
if __name__ == "__main__":
69-
main()
31+
draft = Path(file_path).parent.name
32+
if spec in ["core", "validation", "hyper-schema"]:
33+
print_github_action_notice(file_path, urls[draft][spec] + section)
34+
elif spec in ["quote"]:
35+
continue
36+
elif spec in ["ecma262", "perl5"]:
37+
print_github_action_notice(file_path, urls[spec] + section)
38+
elif re.match("^rfc\\d+$", spec):
39+
print_github_action_notice(file_path, urls["rfc"] + spec + ".txt#" + section)
40+
else:
41+
print_github_action_notice(file_path, urls["iso"])
42+
except json.JSONDecodeError:
43+
print(f"Failed to parse JSON content for file: {file_path}")

0 commit comments

Comments
 (0)