InosLihka Claude Sonnet 4.6 commited on
Commit
8a56903
Β·
1 Parent(s): 1a25a1a

restore: validate-submission.sh to scripts/

Browse files

Was accidentally deleted from docs/round1/scripts/ during docs cleanup.
Moved to scripts/ at repo root (more appropriate location).
inference.py at root was never deleted and remains correct for Life Simulator.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. scripts/validate-submission.sh +184 -0
scripts/validate-submission.sh ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ #
3
+ # validate-submission.sh β€” OpenEnv Submission Validator
4
+ #
5
+ # Checks that your HF Space is live, Docker image builds, and openenv validate passes.
6
+ #
7
+ # Prerequisites:
8
+ # - Docker: https://docs.docker.com/get-docker/
9
+ # - openenv-core: pip install openenv-core
10
+ # - curl (usually pre-installed)
11
+ #
12
+ # Run:
13
+ # chmod +x scripts/validate-submission.sh
14
+ # ./scripts/validate-submission.sh <hf_space_url> [repo_dir]
15
+ #
16
+ # Arguments:
17
+ # hf_space_url Your HuggingFace Space URL (e.g. https://InosLihka-rhythm-env.hf.space)
18
+ # repo_dir Path to your repo (default: current directory)
19
+ #
20
+ # Example:
21
+ # ./scripts/validate-submission.sh https://InosLihka-rhythm-env.hf.space .
22
+ #
23
+
24
+ set -uo pipefail
25
+
26
+ DOCKER_BUILD_TIMEOUT=600
27
+ if [ -t 1 ]; then
28
+ RED='\033[0;31m'
29
+ GREEN='\033[0;32m'
30
+ YELLOW='\033[1;33m'
31
+ BOLD='\033[1m'
32
+ NC='\033[0m'
33
+ else
34
+ RED='' GREEN='' YELLOW='' BOLD='' NC=''
35
+ fi
36
+
37
+ run_with_timeout() {
38
+ local secs="$1"; shift
39
+ if command -v timeout &>/dev/null; then
40
+ timeout "$secs" "$@"
41
+ elif command -v gtimeout &>/dev/null; then
42
+ gtimeout "$secs" "$@"
43
+ else
44
+ "$@" &
45
+ local pid=$!
46
+ ( sleep "$secs" && kill "$pid" 2>/dev/null ) &
47
+ local watcher=$!
48
+ wait "$pid" 2>/dev/null
49
+ local rc=$?
50
+ kill "$watcher" 2>/dev/null
51
+ wait "$watcher" 2>/dev/null
52
+ return $rc
53
+ fi
54
+ }
55
+
56
+ portable_mktemp() {
57
+ local prefix="${1:-validate}"
58
+ mktemp "${TMPDIR:-/tmp}/${prefix}-XXXXXX" 2>/dev/null || mktemp
59
+ }
60
+
61
+ CLEANUP_FILES=()
62
+ cleanup() { rm -f "${CLEANUP_FILES[@]+"${CLEANUP_FILES[@]}"}"; }
63
+ trap cleanup EXIT
64
+
65
+ PING_URL="${1:-}"
66
+ REPO_DIR="${2:-.}"
67
+
68
+ if [ -z "$PING_URL" ]; then
69
+ printf "Usage: %s <hf_space_url> [repo_dir]\n" "$0"
70
+ printf "\n"
71
+ printf " hf_space_url e.g. https://InosLihka-rhythm-env.hf.space\n"
72
+ printf " repo_dir Path to repo root (default: current directory)\n"
73
+ exit 1
74
+ fi
75
+
76
+ if ! REPO_DIR="$(cd "$REPO_DIR" 2>/dev/null && pwd)"; then
77
+ printf "Error: directory '%s' not found\n" "${2:-.}"
78
+ exit 1
79
+ fi
80
+ PING_URL="${PING_URL%/}"
81
+ PASS=0
82
+
83
+ log() { printf "[%s] %b\n" "$(date -u +%H:%M:%S)" "$*"; }
84
+ pass() { log "${GREEN}PASSED${NC} -- $1"; PASS=$((PASS + 1)); }
85
+ fail() { log "${RED}FAILED${NC} -- $1"; }
86
+ hint() { printf " ${YELLOW}Hint:${NC} %b\n" "$1"; }
87
+ stop_at() {
88
+ printf "\n"
89
+ printf "${RED}${BOLD}Validation stopped at %s.${NC} Fix the above before continuing.\n" "$1"
90
+ exit 1
91
+ }
92
+
93
+ printf "\n"
94
+ printf "${BOLD}========================================${NC}\n"
95
+ printf "${BOLD} OpenEnv Submission Validator${NC}\n"
96
+ printf "${BOLD}========================================${NC}\n"
97
+ log "Repo: $REPO_DIR"
98
+ log "HF Space: $PING_URL"
99
+ printf "\n"
100
+
101
+ # ── Step 1: Ping HF Space ───────────────────────────────────────────────────
102
+
103
+ log "${BOLD}Step 1/3: Pinging HF Space${NC} ($PING_URL/reset) ..."
104
+
105
+ CURL_OUTPUT=$(portable_mktemp "validate-curl")
106
+ CLEANUP_FILES+=("$CURL_OUTPUT")
107
+ HTTP_CODE=$(curl -s -o "$CURL_OUTPUT" -w "%{http_code}" -X POST \
108
+ -H "Content-Type: application/json" -d '{}' \
109
+ "$PING_URL/reset" --max-time 30 2>"$CURL_OUTPUT" || printf "000")
110
+
111
+ if [ "$HTTP_CODE" = "200" ]; then
112
+ pass "HF Space is live and responds to /reset"
113
+ elif [ "$HTTP_CODE" = "000" ]; then
114
+ fail "HF Space not reachable (connection failed or timed out)"
115
+ hint "Check the Space is running: $PING_URL"
116
+ stop_at "Step 1"
117
+ else
118
+ fail "HF Space /reset returned HTTP $HTTP_CODE (expected 200)"
119
+ hint "Make sure the Space is running and the URL is correct."
120
+ stop_at "Step 1"
121
+ fi
122
+
123
+ # ── Step 2: Docker build ─────────────────────────────────────────────────────
124
+
125
+ log "${BOLD}Step 2/3: Running docker build${NC} ..."
126
+
127
+ if ! command -v docker &>/dev/null; then
128
+ fail "docker command not found"
129
+ hint "Install Docker: https://docs.docker.com/get-docker/"
130
+ stop_at "Step 2"
131
+ fi
132
+
133
+ if [ -f "$REPO_DIR/Dockerfile" ]; then
134
+ DOCKER_CONTEXT="$REPO_DIR"
135
+ elif [ -f "$REPO_DIR/server/Dockerfile" ]; then
136
+ DOCKER_CONTEXT="$REPO_DIR/server"
137
+ else
138
+ fail "No Dockerfile found in repo root or server/ directory"
139
+ stop_at "Step 2"
140
+ fi
141
+
142
+ log " Found Dockerfile in $DOCKER_CONTEXT"
143
+
144
+ BUILD_OK=false
145
+ BUILD_OUTPUT=$(run_with_timeout "$DOCKER_BUILD_TIMEOUT" docker build "$DOCKER_CONTEXT" 2>&1) && BUILD_OK=true
146
+
147
+ if [ "$BUILD_OK" = true ]; then
148
+ pass "Docker build succeeded"
149
+ else
150
+ fail "Docker build failed (timeout=${DOCKER_BUILD_TIMEOUT}s)"
151
+ printf "%s\n" "$BUILD_OUTPUT" | tail -20
152
+ stop_at "Step 2"
153
+ fi
154
+
155
+ # ── Step 3: openenv validate ─────────────────────────────────────────────────
156
+
157
+ log "${BOLD}Step 3/3: Running openenv validate${NC} ..."
158
+
159
+ if ! command -v openenv &>/dev/null; then
160
+ fail "openenv command not found"
161
+ hint "Install it: pip install openenv-core"
162
+ stop_at "Step 3"
163
+ fi
164
+
165
+ VALIDATE_OK=false
166
+ VALIDATE_OUTPUT=$(cd "$REPO_DIR" && openenv validate 2>&1) && VALIDATE_OK=true
167
+
168
+ if [ "$VALIDATE_OK" = true ]; then
169
+ pass "openenv validate passed"
170
+ [ -n "$VALIDATE_OUTPUT" ] && log " $VALIDATE_OUTPUT"
171
+ else
172
+ fail "openenv validate failed"
173
+ printf "%s\n" "$VALIDATE_OUTPUT"
174
+ stop_at "Step 3"
175
+ fi
176
+
177
+ printf "\n"
178
+ printf "${BOLD}========================================${NC}\n"
179
+ printf "${GREEN}${BOLD} All 3/3 checks passed!${NC}\n"
180
+ printf "${GREEN}${BOLD} Your submission is ready.${NC}\n"
181
+ printf "${BOLD}========================================${NC}\n"
182
+ printf "\n"
183
+
184
+ exit 0