Spaces:
Sleeping
Sleeping
File size: 4,377 Bytes
7a2fcb3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | #!/usr/bin/env bash
#
# validate-submission.sh — OpenEnv Submission Validator
#
# Checks that your HF Space is live, Docker image builds, and openenv validate passes.
#
# Run:
# chmod +x scripts/validate-submission.sh
# ./scripts/validate-submission.sh <ping_url> [repo_dir]
#
set -uo pipefail
DOCKER_BUILD_TIMEOUT=600
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
NC='\033[0m'
else
RED='' GREEN='' YELLOW='' BOLD='' NC=''
fi
pass() { echo -e "${GREEN}[PASS]${NC} $1"; }
fail() { echo -e "${RED}[FAIL]${NC} $1"; FAILED=1; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
info() { echo -e "${BOLD}[INFO]${NC} $1"; }
FAILED=0
PING_URL="${1:-}"
REPO_DIR="${2:-.}"
if [ -z "$PING_URL" ]; then
echo "Usage: $0 <ping_url> [repo_dir]"
echo " ping_url Your HuggingFace Space URL (e.g. https://your-space.hf.space)"
echo " repo_dir Path to your repo (default: current directory)"
exit 1
fi
REPO_DIR="$(cd "$REPO_DIR" && pwd)"
echo ""
echo -e "${BOLD}=== OpenEnv Submission Validator ===${NC}"
echo ""
# ---------- Check 1: Required files ----------
info "Checking required files..."
for f in openenv.yaml Dockerfile inference.py; do
if [ -f "$REPO_DIR/$f" ]; then
pass "Found $f"
else
fail "Missing $f"
fi
done
# ---------- Check 2: openenv.yaml ----------
info "Checking openenv.yaml..."
if [ -f "$REPO_DIR/openenv.yaml" ]; then
if grep -q "spec_version" "$REPO_DIR/openenv.yaml"; then
pass "openenv.yaml has spec_version"
else
fail "openenv.yaml missing spec_version"
fi
if grep -q "name:" "$REPO_DIR/openenv.yaml"; then
pass "openenv.yaml has name field"
else
fail "openenv.yaml missing name field"
fi
fi
# ---------- Check 3: inference.py structure ----------
info "Checking inference.py structure..."
if [ -f "$REPO_DIR/inference.py" ]; then
for pattern in 'API_BASE_URL' 'MODEL_NAME' 'HF_TOKEN' 'OpenAI' '"START"' '"STEP"' '"END"'; do
if grep -q "$pattern" "$REPO_DIR/inference.py"; then
pass "inference.py references $pattern"
else
fail "inference.py missing reference to $pattern"
fi
done
fi
# ---------- Check 4: Environment variables ----------
info "Checking environment variables..."
for var in API_BASE_URL MODEL_NAME HF_TOKEN; do
if [ -n "${!var:-}" ]; then
pass "$var is set"
else
warn "$var is not set (required at runtime)"
fi
done
# ---------- Check 5: Docker build ----------
info "Checking Docker build..."
if command -v docker &>/dev/null; then
info "Running docker build (timeout ${DOCKER_BUILD_TIMEOUT}s)..."
if timeout "$DOCKER_BUILD_TIMEOUT" docker build -t openenv-store-test "$REPO_DIR" 2>&1; then
pass "Docker build succeeded"
else
fail "Docker build failed"
fi
else
warn "Docker not found — skipping Docker build check"
fi
# ---------- Check 6: HF Space ping ----------
info "Pinging HF Space at $PING_URL ..."
if command -v curl &>/dev/null; then
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 30 "$PING_URL/health" 2>/dev/null || echo "000")
if [ "$HTTP_CODE" = "200" ]; then
pass "HF Space /health returned 200"
else
fail "HF Space /health returned HTTP $HTTP_CODE (expected 200)"
fi
RESET_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 30 -X POST "$PING_URL/reset" 2>/dev/null || echo "000")
if [ "$RESET_CODE" = "200" ]; then
pass "HF Space /reset returned 200"
else
fail "HF Space /reset returned HTTP $RESET_CODE (expected 200)"
fi
else
warn "curl not found — skipping ping check"
fi
# ---------- Check 7: openenv validate ----------
info "Running openenv validate..."
if command -v openenv &>/dev/null; then
if (cd "$REPO_DIR" && openenv validate .); then
pass "openenv validate passed"
else
fail "openenv validate failed"
fi
elif command -v uv &>/dev/null && [ -f "$REPO_DIR/pyproject.toml" ]; then
if (cd "$REPO_DIR" && uv run --project . openenv validate .); then
pass "openenv validate passed (via uv)"
else
fail "openenv validate failed (via uv)"
fi
else
warn "Neither openenv nor uv found — skipping validate"
fi
# ---------- Summary ----------
echo ""
if [ "$FAILED" -eq 0 ]; then
echo -e "${GREEN}${BOLD}All checks passed!${NC}"
exit 0
else
echo -e "${RED}${BOLD}Some checks failed. Please fix the issues above before submitting.${NC}"
exit 1
fi
|