Skip to content

Commit

Permalink
add basic validation for json in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-418 committed Jul 23, 2024
1 parent dd30c33 commit 3df73bc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Validate JSON

on:
workflow_dispatch:
push:
pull_request:

jobs:
validate:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install jq
run: sudo apt-get install jq

- name: Validate JSON
run: ./bin/validate_json .
26 changes: 26 additions & 0 deletions bin/validate_json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <json_dir>"
exit 1
fi
JSON_DIR="$1"
echo "Validating JSON files in directory: "$JSON_DIR" ... "; echo

ERRORS=0
for FILE in $(find "$JSON_DIR" -name "*.json"); do
printf "Checking %s ..." "$FILE"
if jq . "$FILE" > /dev/null 2>&1; then
echo "valid."
else
echo "INVALID!"
(( ERRORS += 1 ))
fi
done

if [ "$ERRORS" -ne 0 ]; then
echo; echo "Validation failed with $ERRORS errors."
exit 2
else
echo; echo "All good!"
fi

0 comments on commit 3df73bc

Please sign in to comment.