Browse Source

Add shebang, use elif and only run on linux-clang-test

Alexander Wilms 2 years ago
parent
commit
e0089c76ae
2 changed files with 13 additions and 6 deletions
  1. 11 5
      .github/validate_json.py
  2. 2 1
      .github/workflows/github.yml

+ 11 - 5
.github/validate_json.py

@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+
 import re
 from pathlib import Path
 from pprint import pprint
@@ -20,7 +22,7 @@ for path in sorted(Path('.').glob('**/*.json')):
         with open(path_str, 'r') as file:
             if VALIDATION_TYPE == 'json':
                 jstyleson.load(file)
-            if VALIDATION_TYPE == 'json5':
+            elif VALIDATION_TYPE == 'json5':
                 json5.load(file)
             elif VALIDATION_TYPE == 'yaml':
                 file = file.read().replace("\t", "    ")
@@ -33,17 +35,21 @@ for path in sorted(Path('.').glob('**/*.json')):
 
         error_pos = path_str
 
+        # create error position strings for each type of parser
         if hasattr(exc, 'pos'):
+            # 'json'
             # https://stackoverflow.com/a/72850269/2278742
             error_pos = f"{path_str}:{exc.lineno}:{exc.colno}"
             print(error_pos)
-        if hasattr(exc, 'problem_mark'):
+        elif VALIDATION_TYPE == 'json5':
+            # 'json5'
+            pos = re.findall(r'\d+', str(exc))
+            error_pos = f"{path_str}:{pos[0]}:{pos[-1]}"
+        elif hasattr(exc, 'problem_mark'):
+            # 'yaml'
             mark = exc.problem_mark
             error_pos = f"{path_str}:{mark.line+1}:{mark.column+1}"
             print(error_pos)
-        if VALIDATION_TYPE == 'json5':
-            pos = re.findall(r'\d+', str(exc))
-            error_pos = f"{path_str}:{pos[0]}:{pos[-1]}"
 
         errors.append({"error_pos": error_pos, "error_msg": exc})
 

+ 2 - 1
.github/workflows/github.yml

@@ -147,7 +147,8 @@ jobs:
 
     - name: Validate JSON
       # the Python yaml module doesn't seem to work on mac-arm
-      if: ${{ startsWith(matrix.preset, 'linux') }}
+      # also, running it on multiple presets is redundant and slightly increases already long CI built times
+      if: ${{ startsWith(matrix.preset, 'linux-clang-test') }}
       run: |
         pip3 install json5 jstyleson
         python3 .github/validate_json.py