fix: workflow to validate JSON files #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Verify JSON Syntax | |
| on: | |
| pull_request: | |
| branches: ["master"] | |
| jobs: | |
| validate-json: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Find and validate all JSON files | |
| run: | | |
| echo "🔍 Scanning repository for JSON files..." | |
| ERRORS=0 | |
| FILES=0 | |
| while IFS= read -r -d '' file; do | |
| FILES=$((FILES + 1)) | |
| if python3 -c "import json, sys; json.load(open(sys.argv[1]))" "$file" 2>/dev/null; then | |
| echo "$file" | |
| else | |
| echo "INVALID JSON: $file" | |
| python3 -c " | |
| import json, sys | |
| try: | |
| json.load(open(sys.argv[1])) | |
| except json.JSONDecodeError as e: | |
| print(f' Error: {e}') | |
| " "$file" | |
| ERRORS=$((ERRORS + 1)) | |
| fi | |
| done < <(find . -name "*.json" \ | |
| -not -path "./.git/*" \ | |
| -not -path "./node_modules/*" \ | |
| -print0) | |
| echo "" | |
| echo "──────────────────────────────────" | |
| echo "Scanned : $FILES file(s)" | |
| echo "Errors : $ERRORS file(s)" | |
| echo "──────────────────────────────────" | |
| if [ "$ERRORS" -gt 0 ]; then | |
| echo "::error::$ERRORS JSON file(s) failed validation." | |
| exit 1 | |
| else | |
| echo "All JSON files are valid." | |
| fi |