Skip to content

Commit

Permalink
Merge pull request #41 from getlantern/jay/validate-json
Browse files Browse the repository at this point in the history
add basic validation for json in CI
  • Loading branch information
jay-418 authored Jul 24, 2024
2 parents dd30c33 + 3df73bc commit b0b0fb2
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 b0b0fb2

Please sign in to comment.