Arun-Sanjay commited on
Commit
ec27586
·
1 Parent(s): 0c42a38

Add scripts/validate-submission.sh — runs the 3 grader checks locally

Browse files

Mirrors the hackathon's automated validator:
1. POST /reset to the live HF Space (must return HTTP 200)
2. docker build of the repo (Dockerfile in root or server/)
3. openenv validate against the repo

Skips docker/openenv steps gracefully when CLIs aren't installed.

Files changed (1) hide show
  1. scripts/validate-submission.sh +97 -0
scripts/validate-submission.sh ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # DispatchPulse pre-submission validator.
3
+ #
4
+ # Runs the same three checks the hackathon's automated grader runs:
5
+ # 1. POST /reset to the live HF Space — must return HTTP 200
6
+ # 2. docker build of the repo (Dockerfile in root, then server/Dockerfile)
7
+ # 3. `openenv validate` against the repo
8
+ #
9
+ # Usage:
10
+ # ./scripts/validate-submission.sh https://<your-space>.hf.space [path/to/repo]
11
+ #
12
+ # Exits non-zero on the first failure.
13
+ set -uo pipefail
14
+
15
+ PING_URL="${1:-}"
16
+ REPO_DIR="${2:-.}"
17
+
18
+ GREEN='\033[0;32m'
19
+ RED='\033[0;31m'
20
+ YELLOW='\033[1;33m'
21
+ RESET='\033[0m'
22
+
23
+ stop_at() {
24
+ echo -e "${RED}validation FAILED at: $1${RESET}" >&2
25
+ exit 1
26
+ }
27
+
28
+ ok() {
29
+ echo -e "${GREEN}OK${RESET} $1"
30
+ }
31
+
32
+ warn() {
33
+ echo -e "${YELLOW}WARN${RESET} $1"
34
+ }
35
+
36
+ if [[ -z "$PING_URL" ]]; then
37
+ echo "Usage: $0 <space_url> [repo_dir]" >&2
38
+ exit 2
39
+ fi
40
+
41
+ # ---------------------------------------------------------------------------
42
+ # Check 1: HF Space deploys
43
+ # ---------------------------------------------------------------------------
44
+ echo
45
+ echo "[1/3] HF Space deploys — POST $PING_URL/reset"
46
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
47
+ -H "Content-Type: application/json" -d '{}' \
48
+ "$PING_URL/reset" --max-time 30 || echo "000")
49
+
50
+ if [[ "$HTTP_CODE" != "200" ]]; then
51
+ stop_at "HF Space /reset returned $HTTP_CODE (expected 200)"
52
+ fi
53
+ ok "HF Space /reset returned 200"
54
+
55
+ # ---------------------------------------------------------------------------
56
+ # Check 2: Docker build
57
+ # ---------------------------------------------------------------------------
58
+ echo
59
+ echo "[2/3] Docker build"
60
+ DOCKER_CONTEXT=""
61
+ if [[ -f "$REPO_DIR/Dockerfile" ]]; then
62
+ DOCKER_CONTEXT="$REPO_DIR"
63
+ echo " using Dockerfile at: $REPO_DIR/Dockerfile"
64
+ elif [[ -f "$REPO_DIR/server/Dockerfile" ]]; then
65
+ DOCKER_CONTEXT="$REPO_DIR/server"
66
+ echo " using Dockerfile at: $REPO_DIR/server/Dockerfile"
67
+ else
68
+ stop_at "no Dockerfile found in $REPO_DIR or $REPO_DIR/server"
69
+ fi
70
+
71
+ if ! command -v docker >/dev/null 2>&1; then
72
+ warn "docker CLI not found locally — skipping docker build (graders will run it)"
73
+ else
74
+ if ! timeout 600 docker build "$DOCKER_CONTEXT" >/tmp/dispatchpulse-docker-build.log 2>&1; then
75
+ echo "--- last 40 lines of docker build log ---" >&2
76
+ tail -40 /tmp/dispatchpulse-docker-build.log >&2
77
+ stop_at "docker build failed"
78
+ fi
79
+ ok "docker build succeeded (log: /tmp/dispatchpulse-docker-build.log)"
80
+ fi
81
+
82
+ # ---------------------------------------------------------------------------
83
+ # Check 3: openenv validate
84
+ # ---------------------------------------------------------------------------
85
+ echo
86
+ echo "[3/3] openenv validate"
87
+ if ! command -v openenv >/dev/null 2>&1; then
88
+ warn "openenv CLI not found locally — skipping (graders will run it)"
89
+ else
90
+ if ! (cd "$REPO_DIR" && openenv validate); then
91
+ stop_at "openenv validate failed"
92
+ fi
93
+ ok "openenv validate passed"
94
+ fi
95
+
96
+ echo
97
+ echo -e "${GREEN}All checks passed.${RESET}"