Files
layue13 05f8fad38a
Gatekeep evals / eval-floor (push) Successful in 8s
Dogfood: run Gatekeep on this repo's PRs
Add .github/workflows/gatekeep-pr.yml with uses: ./ and
OPENROUTER_API_KEY from secrets. Forge-agnostic API helper for Gitea.
2026-10-26 20:40:51 +00:00

88 lines
2.3 KiB
Bash

#!/usr/bin/env bash
# Discover build/test/benchmark entry points from common manifests.
# No Minecraft-hardcoded commands — agent/caller repos vary.
set -euo pipefail
ROOT="${GATEKEEP_ROOT:-.}"
OUT_DIR="$ROOT/.gatekeep/out"
mkdir -p "$OUT_DIR"
json_escape() {
python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))' <<<"$1"
}
entries=()
add() {
local kind="$1" cmd="$2" src="$3"
entries+=("{\"kind\":$(json_escape "$kind"),\"command\":$(json_escape "$cmd"),\"source\":$(json_escape "$src")}")
}
if [[ -f "$ROOT/package.json" ]]; then
# Prefer known script names without requiring jq
for s in test check lint build verify bench benchmark start; do
if python3 - "$ROOT/package.json" "$s" <<'PY'
import json,sys
p=json.load(open(sys.argv[1]))
scripts=p.get("scripts") or {}
sys.exit(0 if sys.argv[2] in scripts else 1)
PY
then
add "npm:$s" "npm run $s" "package.json"
fi
done
fi
if [[ -f "$ROOT/Makefile" ]]; then
for t in test check verify bench benchmark build; do
if grep -qE "^${t}[[:space:]]*:" "$ROOT/Makefile"; then
add "make:$t" "make $t" "Makefile"
fi
done
fi
if [[ -f "$ROOT/gradlew" ]]; then
add "gradle:test" "./gradlew test" "gradlew"
add "gradle:build" "./gradlew build" "gradlew"
fi
if [[ -f "$ROOT/pom.xml" ]]; then
add "mvn:test" "mvn -B test" "pom.xml"
fi
if [[ -f "$ROOT/Cargo.toml" ]]; then
add "cargo:test" "cargo test" "Cargo.toml"
add "cargo:bench" "cargo bench" "Cargo.toml"
fi
if [[ -f "$ROOT/go.mod" ]]; then
add "go:test" "go test ./..." "go.mod"
fi
if [[ -f "$ROOT/pyproject.toml" ]] || [[ -f "$ROOT/pytest.ini" ]]; then
add "pytest" "pytest -q" "python"
fi
# README hints (non-executing notes for the model/verify layer)
readme_hints=""
for f in README.md README.rst docs/README.md; do
if [[ -f "$ROOT/$f" ]]; then
readme_hints+=$(grep -iE '^(#+ ).*(test|build|bench|verify|ci)' "$ROOT/$f" | head -20 || true)
readme_hints+=$'\n'
fi
done
joined=$(IFS=,; echo "${entries[*]}")
discover_json="{\"entries\":[${joined}],\"readme_hints\":$(json_escape "$readme_hints")}"
printf '%s\n' "$discover_json" > "$OUT_DIR/discover.json"
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
{
echo "discover_json<<GATEKEEP_EOF"
echo "$discover_json"
echo "GATEKEEP_EOF"
} >> "$GITHUB_OUTPUT"
fi
echo "Discovered ${#entries[@]} entry point(s)" >&2