Skip to content

Commit 64161f6

Browse files
Merge pull request #110 from romankurnovskii/problems-27-156-157-158-159-161-163-170
Simplify JSON validation workflow - only check validity, not formatti…
2 parents 1a07892 + cea2def commit 64161f6

File tree

1 file changed

+10
-37
lines changed

1 file changed

+10
-37
lines changed

.github/workflows/pr-json-validation.yml

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,19 @@ jobs:
2222
with:
2323
python-version: "3.11"
2424

25-
- name: Validate JSON syntax
26-
run: |
27-
python3 -m json.tool data/leetcode-problems.json > /dev/null
28-
echo "✓ JSON syntax is valid"
29-
30-
- name: Test normalization script
31-
run: |
32-
# Make script executable
33-
chmod +x scripts/normalize_json.py
34-
35-
# Normalize to a temporary file to compare
36-
python3 scripts/normalize_json.py data/leetcode-problems.json data/leetcode-problems.json.normalized
37-
38-
# Check if the normalized version differs from the original
39-
if ! diff -q data/leetcode-problems.json data/leetcode-problems.json.normalized > /dev/null; then
40-
echo "❌ Error: JSON file is not normalized."
41-
echo "Please run './scripts/normalize_json.py data/leetcode-problems.json' and commit the changes."
42-
echo ""
43-
echo "Diff showing what needs to be normalized:"
44-
diff data/leetcode-problems.json data/leetcode-problems.json.normalized || true
45-
rm data/leetcode-problems.json.normalized
46-
exit 1
47-
else
48-
echo "✓ JSON file is properly normalized"
49-
rm data/leetcode-problems.json.normalized
50-
fi
51-
52-
- name: Verify JSON structure
25+
- name: Validate JSON syntax and structure
5326
run: |
5427
python3 << 'EOF'
5528
import json
5629
import sys
5730
58-
with open('data/leetcode-problems.json', 'r') as f:
59-
data = json.load(f)
31+
# Validate JSON syntax
32+
try:
33+
with open('data/leetcode-problems.json', 'r') as f:
34+
data = json.load(f)
35+
except json.JSONDecodeError as e:
36+
print(f"❌ Error: Invalid JSON syntax - {e}")
37+
sys.exit(1)
6038
6139
# Check if root is a dict
6240
if not isinstance(data, dict):
@@ -71,12 +49,7 @@ jobs:
7149
print(f"❌ Error: Key '{key}' is not a numeric string")
7250
sys.exit(1)
7351
74-
# Check if keys are sorted
75-
keys = [int(k) for k in data.keys()]
76-
if keys != sorted(keys):
77-
print("❌ Error: Keys are not sorted numerically")
78-
sys.exit(1)
79-
52+
print(f"✓ JSON syntax is valid")
8053
print(f"✓ JSON structure is valid ({len(data)} entries)")
81-
print(f"✓ All keys are numeric and sorted")
54+
print(f"✓ All keys are numeric strings")
8255
EOF

0 commit comments

Comments
 (0)