From feea82e0ba00f147350ff36a18dde5bd316460d7 Mon Sep 17 00:00:00 2001 From: Bram Suurd <78373894+BramSuurdje@users.noreply.github.com> Date: Tue, 22 Jul 2025 16:00:10 +0200 Subject: [PATCH] Add GitHub Actions workflow to validate JSON files in the frontend directory (#6152) * Add GitHub Actions workflow to validate JSON files in the frontend directory * test new github workflow by invalidating script * Revalidate json script to also test workflow * Refactor GitHub Actions workflow to validate JSON files using Python. * test github workflow * Update description in apache-tomcat.json for clarity and consistency. * Consolidate JSON validation workflow: Migrate test-jsons.yml functionality into frontend-cicd.yml, enhancing CI process by validating JSON files in the public directory with Python. * test to see if workflow fails * test to see if workflow passes * testing * testing to see if workflow runs and works * test again * testing to see if it works --- .github/workflows/frontend-cicd.yml | 81 +++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/.github/workflows/frontend-cicd.yml b/.github/workflows/frontend-cicd.yml index 3f33b0a99..bf7f56c58 100644 --- a/.github/workflows/frontend-cicd.yml +++ b/.github/workflows/frontend-cicd.yml @@ -24,12 +24,87 @@ concurrency: cancel-in-progress: false jobs: - build: - if: github.repository == 'community-scripts/ProxmoxVE' + test-json-files: runs-on: ubuntu-latest defaults: run: - working-directory: frontend # Set default working directory for all run steps + working-directory: frontend + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + + - name: Test JSON files + run: | + python3 << 'EOF' + import json + import glob + import os + import sys + + def test_json_files(): + # Change to the correct directory + json_dir = "public/json" + if not os.path.exists(json_dir): + print(f"❌ Directory not found: {json_dir}") + return False + + # Find all JSON files + pattern = os.path.join(json_dir, "*.json") + json_files = glob.glob(pattern) + + if not json_files: + print(f"⚠️ No JSON files found in {json_dir}") + return True + + print(f"Testing {len(json_files)} JSON files for valid syntax...") + + invalid_files = [] + + for file_path in json_files: + try: + with open(file_path, 'r', encoding='utf-8') as f: + json.load(f) + print(f"✅ Valid JSON: {file_path}") + except json.JSONDecodeError as e: + print(f"❌ Invalid JSON syntax in: {file_path}") + print(f" Error: {e}") + invalid_files.append(file_path) + except Exception as e: + print(f"⚠️ Error reading: {file_path}") + print(f" Error: {e}") + invalid_files.append(file_path) + + print("\n=== JSON Validation Summary ===") + print(f"Total files tested: {len(json_files)}") + print(f"Valid files: {len(json_files) - len(invalid_files)}") + print(f"Invalid files: {len(invalid_files)}") + + if invalid_files: + print("\n❌ Found invalid JSON file(s):") + for file_path in invalid_files: + print(f" - {file_path}") + return False + else: + print("\n✅ All JSON files have valid syntax!") + return True + + if __name__ == "__main__": + success = test_json_files() + sys.exit(0 if success else 1) + EOF + + build: + if: github.repository == 'community-scripts/ProxmoxVE' + needs: test-json-files + runs-on: ubuntu-latest + defaults: + run: + working-directory: frontend steps: - name: Checkout uses: actions/checkout@v4