From 526c447cf8dcf6f1be9a494bd276efbcc09d8eb2 Mon Sep 17 00:00:00 2001 From: CrabKing <127689590+Crab-K1ng@users.noreply.github.com> Date: Mon, 3 Aug 2026 09:30:10 +0100 Subject: [PATCH 1/8] add a github workflow to validate json files in pull requests --- .github/workflows/check-json.yml | 28 +++++++++++++++++++ assets/base/scripts/requirements.txt | 1 + assets/base/scripts/validate-lang.py | 40 ++++++++++++++++------------ 3 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/check-json.yml create mode 100644 assets/base/scripts/requirements.txt diff --git a/.github/workflows/check-json.yml b/.github/workflows/check-json.yml new file mode 100644 index 00000000..fafe8342 --- /dev/null +++ b/.github/workflows/check-json.yml @@ -0,0 +1,28 @@ +name: Validate JSON Files + +on: + pull_request: + branches: [ master ] + +jobs: + run-script: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v7 + + - name: Set up Python + uses: actions/setup-python@v7 + with: + python-version: '3.14' + + - name: Cd into scripts + run: cd ./Cosmic-Reach-Localization/assets/base/scripts/ + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Validate JSON files + run: python validate_json.py ../../ --github diff --git a/assets/base/scripts/requirements.txt b/assets/base/scripts/requirements.txt new file mode 100644 index 00000000..a894311c --- /dev/null +++ b/assets/base/scripts/requirements.txt @@ -0,0 +1 @@ +click>=8.4.2 diff --git a/assets/base/scripts/validate-lang.py b/assets/base/scripts/validate-lang.py index 16501fcc..31fbc67c 100644 --- a/assets/base/scripts/validate-lang.py +++ b/assets/base/scripts/validate-lang.py @@ -1,16 +1,17 @@ import json import os +import sys import click def validate_json_from_file(file_path): try: with open(file_path, 'r', encoding='utf-8') as file: json.load(file) - return True, "Success" + return True, None, "Success" except json.JSONDecodeError as e: - return False, str(e) + return False, e.lineno, str(e) except FileNotFoundError: - return False, "File not found" + return False, None, "File not found" def validate_json_in_directory(directory): results = {} @@ -18,25 +19,30 @@ def validate_json_in_directory(directory): for file in files: if file.endswith(".json"): file_path = os.path.join(root, file) - success, reason = validate_json_from_file(file_path) + success, line, reason = validate_json_from_file(file_path) if not success: - results[file_path] = reason + results[file_path] = (line, reason) return results @click.command() @click.argument('directory_path', default='.') -def main(directory_path): - try: - results = validate_json_in_directory(directory_path) - if len(results) == 0: - print("Language files are valid!") - else: - for path, reason in results.items(): - print(path + ": " + reason) - raise ValueError("Found syntax errors.") - except ValueError as ex: - print("Language files are NOT valid!", ex) - exit(1) +@click.option('--github', is_flag=True, default=False, help="Emit GitHub Actions error annotations") +def main(directory_path, github): + results = validate_json_in_directory(directory_path) + if len(results) == 0: + print("Language files are valid!") + else: + for path, (line, reason) in results.items(): + rel_path = os.path.relpath(path) + if github: + if line: + print(f"::error file={rel_path},line={line}::{reason}") + else: + print(f"::error file={rel_path}::{reason}") + else: + print(f"{path}: {reason}") + print("Language files are NOT valid!") + sys.exit(1) if __name__ == "__main__": main() From e4dc7fe5e993cdc5a5166af3d98acae474964ab4 Mon Sep 17 00:00:00 2001 From: CrabKing <127689590+Crab-K1ng@users.noreply.github.com> Date: Mon, 3 Aug 2026 09:31:45 +0100 Subject: [PATCH 2/8] add workflow_dispatch so you can run it manually --- .github/workflows/check-json.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-json.yml b/.github/workflows/check-json.yml index fafe8342..530105bc 100644 --- a/.github/workflows/check-json.yml +++ b/.github/workflows/check-json.yml @@ -3,6 +3,7 @@ name: Validate JSON Files on: pull_request: branches: [ master ] + workflow_dispatch: jobs: run-script: From 6d97cee491de8051be1821f9eafecdcfcc13ee7f Mon Sep 17 00:00:00 2001 From: CrabKing <127689590+Crab-K1ng@users.noreply.github.com> Date: Mon, 3 Aug 2026 09:35:43 +0100 Subject: [PATCH 3/8] update path --- .github/workflows/check-json.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-json.yml b/.github/workflows/check-json.yml index 530105bc..47969532 100644 --- a/.github/workflows/check-json.yml +++ b/.github/workflows/check-json.yml @@ -18,7 +18,7 @@ jobs: python-version: '3.14' - name: Cd into scripts - run: cd ./Cosmic-Reach-Localization/assets/base/scripts/ + run: cd /assets/base/scripts/ - name: Install dependencies run: | From 36ffb6267b4a9250aaa67c18d3b369daa8c554ad Mon Sep 17 00:00:00 2001 From: CrabKing <127689590+Crab-K1ng@users.noreply.github.com> Date: Mon, 3 Aug 2026 09:39:29 +0100 Subject: [PATCH 4/8] remove cd and use full path --- .github/workflows/check-json.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-json.yml b/.github/workflows/check-json.yml index 47969532..b73f1a44 100644 --- a/.github/workflows/check-json.yml +++ b/.github/workflows/check-json.yml @@ -17,13 +17,10 @@ jobs: with: python-version: '3.14' - - name: Cd into scripts - run: cd /assets/base/scripts/ - - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt + pip install -r Cosmic-Reach-Localization/assets/base/scripts/requirements.txt - name: Validate JSON files - run: python validate_json.py ../../ --github + run: python Cosmic-Reach-Localization/assets/base/scripts/validate_json.py Cosmic-Reach-Localization/assets/base/lang/ --github From b70b22f499f14b81cbe5f49944893bae6a70671f Mon Sep 17 00:00:00 2001 From: CrabKing <127689590+Crab-K1ng@users.noreply.github.com> Date: Mon, 3 Aug 2026 09:42:45 +0100 Subject: [PATCH 5/8] add debug ls --- .github/workflows/check-json.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-json.yml b/.github/workflows/check-json.yml index b73f1a44..a0a61e4d 100644 --- a/.github/workflows/check-json.yml +++ b/.github/workflows/check-json.yml @@ -17,6 +17,8 @@ jobs: with: python-version: '3.14' + - run: ls + - name: Install dependencies run: | python -m pip install --upgrade pip From e789ac56d84f12f89492dbde8d613e8e91469446 Mon Sep 17 00:00:00 2001 From: CrabKing <127689590+Crab-K1ng@users.noreply.github.com> Date: Mon, 3 Aug 2026 09:44:01 +0100 Subject: [PATCH 6/8] fix path and remove debug ls --- .github/workflows/check-json.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-json.yml b/.github/workflows/check-json.yml index a0a61e4d..3deef42f 100644 --- a/.github/workflows/check-json.yml +++ b/.github/workflows/check-json.yml @@ -17,12 +17,10 @@ jobs: with: python-version: '3.14' - - run: ls - - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r Cosmic-Reach-Localization/assets/base/scripts/requirements.txt + pip install -r /assets/base/scripts/requirements.txt - name: Validate JSON files - run: python Cosmic-Reach-Localization/assets/base/scripts/validate_json.py Cosmic-Reach-Localization/assets/base/lang/ --github + run: python /assets/base/scripts/validate_json.py Cosmic-Reach-Localization/assets/base/lang/ --github From 924670ac45367e0603c1d03be052103adc1e1b6a Mon Sep 17 00:00:00 2001 From: CrabKing <127689590+Crab-K1ng@users.noreply.github.com> Date: Mon, 3 Aug 2026 09:46:18 +0100 Subject: [PATCH 7/8] fix path again --- .github/workflows/check-json.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-json.yml b/.github/workflows/check-json.yml index 3deef42f..b32fe653 100644 --- a/.github/workflows/check-json.yml +++ b/.github/workflows/check-json.yml @@ -20,7 +20,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r /assets/base/scripts/requirements.txt + pip install -r assets/base/scripts/requirements.txt - name: Validate JSON files - run: python /assets/base/scripts/validate_json.py Cosmic-Reach-Localization/assets/base/lang/ --github + run: python assets/base/scripts/validate_json.py Cosmic-Reach-Localization/assets/base/lang/ --github From 022690414242cace6c4bcee6c0ff5836c79f4e67 Mon Sep 17 00:00:00 2001 From: CrabKing <127689590+Crab-K1ng@users.noreply.github.com> Date: Mon, 3 Aug 2026 09:50:08 +0100 Subject: [PATCH 8/8] fix path again again --- .github/workflows/check-json.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-json.yml b/.github/workflows/check-json.yml index b32fe653..1f2f6d5d 100644 --- a/.github/workflows/check-json.yml +++ b/.github/workflows/check-json.yml @@ -23,4 +23,4 @@ jobs: pip install -r assets/base/scripts/requirements.txt - name: Validate JSON files - run: python assets/base/scripts/validate_json.py Cosmic-Reach-Localization/assets/base/lang/ --github + run: python assets/base/scripts/validate-lang.py assets/base/lang/ --github