Skip to content

Commit e17e279

Browse files
authored
Check JSON syntax for pull requests (AliceO2Group#1454)
1 parent a58581c commit e17e279

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: Validate JSON syntax
3+
4+
# Run on any commit or PR that changes any JSON file.
5+
'on':
6+
push:
7+
paths:
8+
- '**.json'
9+
pull_request:
10+
paths:
11+
- '**.json'
12+
13+
permissions: {}
14+
15+
jobs:
16+
json-syntax:
17+
name: validate syntax
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Validate syntax for JSON files
25+
run: |
26+
error=0
27+
readarray -d '' json_files < \
28+
<(find . \( -path ./.git -or -path ./DATA/testing/private \) -prune -false -or -type f -name '*.json' -print0)
29+
for jsonf in "${json_files[@]}"; do
30+
echo "::debug::Checking $jsonf..."
31+
if ! errmsg=$(jq . "$jsonf" 2>&1 >/dev/null); then
32+
error=1
33+
echo "Invalid JSON syntax found in $jsonf:" >&2
34+
printf '::error file=%s,title=%s::%s\n' "$jsonf" 'Invalid JSON syntax' "$errmsg"
35+
fi
36+
done
37+
exit "$error"

0 commit comments

Comments
 (0)