CoolFace
Apppublic

rishithayanidhi/datacenter-cooling-optimization

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
pre_validate.ps1164 linesDownload Raw Back to root
1#!/usr/bin/env pwsh2# Pre-submission validation script for OpenEnv submission3# Tests: 1) HF Space connectivity (or local server), 2) Docker build, 3) openenv validate4 5# Color codes6$GREEN = "`e[32m"7$RED = "`e[31m"8$YELLOW = "`e[33m"9$BOLD = "`e[1m"10$NC = "`e[0m"11 12# Configuration13$REPO_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path14$DOCKER_BUILD_TIMEOUT = 300  # 5 minutes15$HF_SPACE_URL = if ($env:HF_SPACE_URL) { $env:HF_SPACE_URL } else { "http://localhost:8000" }16$PING_URL = "$HF_SPACE_URL"17 18function pass {19    param([string]$message)20    Write-Host "${GREEN}✓${NC} $message" -ForegroundColor Green21}22 23function fail {24    param([string]$message)25    Write-Host "${RED}✗${NC} $message" -ForegroundColor Red26}27 28function hint {29    param([string]$message)30    Write-Host "  ${YELLOW}→${NC} $message" -ForegroundColor Yellow31}32 33function log {34    param([string]$message)35    Write-Host "$message"36}37 38function stop_at {39    param([string]$step)40    Write-Host ""41    Write-Host "${RED}Validation stopped at $step.${NC}" -ForegroundColor Red42    exit 143}44 45Write-Host ""46Write-Host "${BOLD}========================================${NC}"47Write-Host "${BOLD}  OpenEnv Pre-Submission Validation${NC}"48Write-Host "${BOLD}========================================${NC}"49Write-Host ""50 51# Step 1: Check HF Space connectivity52log "${BOLD}Step 1/3: Checking HF Space connectivity (or local server)${NC} ..."53log "  Pinging: $PING_URL/reset"54 55try {56    $response = Invoke-WebRequest -Uri "$PING_URL/reset" -Method POST -TimeoutSec 10 -SkipHttpErrorCheck57    $HTTP_CODE = $response.StatusCode58} catch {59    $HTTP_CODE = "000"60}61 62if ($HTTP_CODE -eq 200) {63    pass "HF Space is live and responds to /reset"64} elseif ($HTTP_CODE -eq "000") {65    fail "HF Space not reachable (connection failed or timed out)"66    hint "Check your network connection and that the Space is running."67    hint "Try: Invoke-WebRequest -Uri '$PING_URL/reset' -Method POST -SkipHttpErrorCheck"68    stop_at "Step 1"69} else {70    fail "HF Space /reset returned HTTP $HTTP_CODE (expected 200)"71    hint "Make sure your Space is running and the URL is correct."72    hint "Try opening $PING_URL in your browser first."73    stop_at "Step 1"74}75 76# Step 2: Check Docker build77log ""78log "${BOLD}Step 2/3: Running docker build${NC} ..."79 80$DOCKER_FOUND = Get-Command docker -ErrorAction SilentlyContinue81if (-not $DOCKER_FOUND) {82    fail "docker command not found"83    hint "Install Docker: https://docs.docker.com/get-docker/"84    stop_at "Step 2"85}86 87# Find Dockerfile88$DOCKERFILE_LOCATION = $null89if (Test-Path "$REPO_DIR/Dockerfile") {90    $DOCKERFILE_LOCATION = "$REPO_DIR"91} elseif (Test-Path "$REPO_DIR/server/Dockerfile") {92    $DOCKERFILE_LOCATION = "$REPO_DIR/server"93} else {94    fail "No Dockerfile found in repo root or server/ directory"95    stop_at "Step 2"96}97 98log "  Found Dockerfile in $DOCKERFILE_LOCATION"99 100# Build Docker image with timeout101$BUILD_OK = $false102$BUILD_OUTPUT = @()103 104try {105    $BUILD_OUTPUT = & docker build $DOCKERFILE_LOCATION 2>&1106    $BUILD_OK = $LASTEXITCODE -eq 0107} catch {108    $BUILD_OUTPUT = $_.ToString()109    $BUILD_OK = $false110}111 112if ($BUILD_OK) {113    pass "Docker build succeeded"114} else {115    fail "Docker build failed"116    ($BUILD_OUTPUT | Select-Object -Last 20) | ForEach-Object { log "  $_" }117    stop_at "Step 2"118}119 120# Step 3: Run openenv validate121log ""122log "${BOLD}Step 3/3: Running openenv validate${NC} ..."123 124$OPENENV_FOUND = Get-Command openenv -ErrorAction SilentlyContinue125if (-not $OPENENV_FOUND) {126    fail "openenv command not found"127    hint "Install it: pip install openenv-core"128    stop_at "Step 3"129}130 131$VALIDATE_OK = $false132$VALIDATE_OUTPUT = @()133 134try {135    Push-Location $REPO_DIR136    $VALIDATE_OUTPUT = & openenv validate 2>&1137    $VALIDATE_OK = $LASTEXITCODE -eq 0138} catch {139    $VALIDATE_OUTPUT = $_.ToString()140    $VALIDATE_OK = $false141} finally {142    Pop-Location143}144 145if ($VALIDATE_OK) {146    pass "openenv validate passed"147    if ($VALIDATE_OUTPUT) {148        log "  $($VALIDATE_OUTPUT -join "`n  ")"149    }150} else {151    fail "openenv validate failed"152    $VALIDATE_OUTPUT | ForEach-Object { log "  $_" }153    stop_at "Step 3"154}155 156Write-Host ""157Write-Host "${BOLD}========================================${NC}"158Write-Host "${GREEN}${BOLD}  All 3/3 checks passed!${NC}"159Write-Host "${GREEN}${BOLD}  Your submission is ready to submit.${NC}"160Write-Host "${BOLD}========================================${NC}"161Write-Host ""162 163exit 0164