Skip to content

Commit

Permalink
json validation strict with py
Browse files Browse the repository at this point in the history
  • Loading branch information
Laserlicht authored Sep 16, 2023
1 parent 9986708 commit 9edf83e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/ignore_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore = [ "./github.json", "./vcmi-1.2.json", "./vcmi-1.3.json" ]
4 changes: 2 additions & 2 deletions .github/update_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import sys
import urllib.request

ignore = [ "./github.json", "./vcmi-1.2.json", "./vcmi-1.3.json" ]
from ignore_json import ignore

for filename in glob.glob(os.path.join('.', '*.json')):
if filename not in ignore:
print(f"Opening: {filename}")
filecontent = open(filename, "r").read()
modlist = json.loads(filecontent)
for mod, data in modlist.items():
url = data["download"]
url = data["download"].replace(" ", "%20")
print(f"Download {mod}: {url}")
try:
response = urllib.request.urlopen(url)
Expand Down
23 changes: 23 additions & 0 deletions .github/validate_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json
import glob
import os
import sys
import urllib.request

from ignore_json import ignore

error = False

for filename in glob.glob(os.path.join('.', '*.json')):
if filename not in ignore:
print(f"Opening: {filename}")
filecontent = open(filename, "r").read()

try:
json.loads(filecontent)
except Exception as err:
print("Error: " + str(err))
sys.exit(os.EX_SOFTWARE)

print("Everything is ok!")
sys.exit(os.EX_OK)
6 changes: 3 additions & 3 deletions .github/validate_mod_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import urllib.request

ignore = [ "./github.json", "./vcmi-1.2.json", "./vcmi-1.3.json" ]
from ignore_json import ignore

error = False

Expand All @@ -14,7 +14,7 @@
filecontent = open(filename, "r").read()
modlist = json.loads(filecontent)
for mod, data in modlist.items():
url = data["mod"]
url = data["mod"].replace(" ", "%20")
print(f"Download {mod}: {url}")
try:
response = urllib.request.urlopen(url)
Expand All @@ -28,7 +28,7 @@
json.loads(filecontent)
except Exception as err:
error = True
print("Error: " + err)
print("Error: " + str(err))
continue
if error:
sys.exit(os.EX_SOFTWARE)
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ on:
workflow_dispatch:

jobs:
check_json:
validate_json:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v2
with:
pattern: "\\.json$"
- name: Validate json
run: |
python3 .github/validate_json.py
validate_mod_json:
needs: check_json
needs: validate_json
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -32,7 +34,7 @@ jobs:
run: |
python3 .github/validate_mod_json.py
update_size:
needs: check_json
needs: validate_json
runs-on: ubuntu-latest
defaults:
run:
Expand Down

0 comments on commit 9edf83e

Please sign in to comment.