Files
oto-enterprise-os-dtp/ci/validate_json.sh
T

42 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# ============================================================================
# validate_json.sh · OTO Enterprise OS DTP
# ----------------------------------------------------------------------------
# Valide que tous les fichiers .json suivis sont bien formés (parse strict).
# Les schémas JSON (version.schema.json, projets_master.schema.json) sont le
# contrat de données Faisabilité ↔ Publiciste : un JSON cassé bloque le
# pipeline en aval → on l'attrape ici.
# Dépendances : bash, git, python3. Aucun réseau requis.
# ============================================================================
set -uo pipefail
# shellcheck source=ci/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" || exit 3
cd_repo_root # racine du dépôt, ou ROUGE honnête si hors arbre git (cf. lib.sh)
FAIL=0
mapfile -t files < <(git ls-files '*.json')
if [[ "${#files[@]}" -eq 0 ]]; then
echo "Aucun fichier .json suivi — rien à valider."
exit 0
fi
for f in "${files[@]}"; do
if python3 -c "import json,sys; json.load(open(sys.argv[1]))" "$f" 2>/tmp/jsonerr; then
printf ' \033[32m✓\033[0m %s\n' "$f"
# Si un $schema est déclaré, contrôle que 'draft' est reconnu (info seule).
else
printf ' \033[31m✗\033[0m %s\n' "$f"
sed 's/^/ /' /tmp/jsonerr
FAIL=1
fi
done
echo
if [[ "$FAIL" -eq 0 ]]; then
echo -e "\033[32m✅ Tous les JSON sont bien formés.\033[0m"
else
echo -e "\033[31m❌ JSON invalide détecté.\033[0m"
fi
exit "$FAIL"