#!/usr/bin/env bash
# skill-gate 本地门禁：Gitea Actions 没有 runner，靠这个兜底。
# 跳过：SKILL_GATE_SKIP=1 git commit ...（需在提交信息里说明原因）
set -uo pipefail
[ "${SKILL_GATE_SKIP:-0}" = "1" ] && { echo "[skill-gate] skipped by SKILL_GATE_SKIP=1"; exit 0; }
cd "$(git rev-parse --show-toplevel)" || exit 1
fail=0
echo "[skill-gate] validate --strict"
python3 scripts/validate-skills.py --strict || fail=1
echo "[skill-gate] scan"
./scripts/scan-skill.sh >/tmp/skill-gate-scan.log 2>&1 || { fail=1; tail -5 /tmp/skill-gate-scan.log; }
echo "[skill-gate] catalog --check"
python3 scripts/generate-catalog.py --check || fail=1
if [ "$fail" -ne 0 ]; then
  echo "[skill-gate] 未通过：先修复，或用 SKILL_GATE_SKIP=1 并在提交信息里说明原因"
  exit 1
fi
echo "[skill-gate] OK"
