#!/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<> "$GITHUB_OUTPUT" fi echo "Discovered ${#entries[@]} entry point(s)" >&2