Spaces:
Sleeping
Sleeping
File size: 7,041 Bytes
371efe0 | 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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | @echo off
setlocal EnableExtensions DisableDelayedExpansion
set "SCRIPT_NAME=%~n0"
set "ACTION=%~1"
set "COMMIT_MSG=%~2"
set "SPACE_URL=https://huggingface.co/spaces/kmkarakaya/openLLMbenchmark"
set "SPACE_BRANCH=main"
set "TMP_DIR="
if "%ACTION%"=="" goto :usage
if /I "%ACTION%"=="help" goto :usage
if /I "%ACTION%"=="check" goto :run_check
if /I "%ACTION%"=="github" goto :run_github
if /I "%ACTION%"=="hf" goto :run_hf
if /I "%ACTION%"=="all" goto :run_all
echo [ERROR] Unknown action: %ACTION%
goto :usage_error
:usage
echo Usage:
echo .\devops_helper.bat check
echo .\devops_helper.bat github "commit message"
echo .\devops_helper.bat hf
echo .\devops_helper.bat all "commit message"
echo.
echo Actions:
echo check Runs local preflight checks ^(pytest + frontend typecheck/build + optional docker build^).
echo github Stages all changes, commits, and pushes to origin/current-branch.
echo hf Deploys current HEAD to Hugging Face Space (binary-safe snapshot).
echo all Runs github first, then hf.
echo.
echo Notes:
echo - Run this script from anywhere inside the git repo.
echo - For hf deploy, your working tree must be clean.
exit /b 0
:usage_error
exit /b 1
:ensure_repo
set "REPO_ROOT="
for /f "delims=" %%I in ('git rev-parse --show-toplevel 2^>nul') do set "REPO_ROOT=%%I"
if not defined REPO_ROOT (
echo [ERROR] Not inside a git repository.
exit /b 1
)
cd /d "%REPO_ROOT%"
exit /b 0
:get_current_branch
set "CURRENT_BRANCH="
for /f "delims=" %%I in ('git branch --show-current') do set "CURRENT_BRANCH=%%I"
if not defined CURRENT_BRANCH (
echo [ERROR] Could not detect current branch.
exit /b 1
)
exit /b 0
:is_clean_tree
git diff --quiet
if errorlevel 1 exit /b 1
git diff --cached --quiet
if errorlevel 1 exit /b 1
exit /b 0
:require_clean_tree
call :is_clean_tree
if errorlevel 1 (
echo [ERROR] Working tree must be clean. Commit or stash your changes first.
exit /b 1
)
exit /b 0
:run_check
call :ensure_repo || exit /b 1
if not exist "frontend\package.json" (
echo [ERROR] frontend\package.json not found.
exit /b 1
)
echo [INFO] Running backend tests...
pytest -q || (
echo [ERROR] Backend tests failed.
exit /b 1
)
pushd frontend || (
echo [ERROR] Could not enter frontend directory.
exit /b 1
)
if not exist "node_modules" (
echo [INFO] Installing frontend dependencies...
if exist "package-lock.json" (
call npm ci
) else (
call npm install
)
if errorlevel 1 (
echo [ERROR] Frontend dependency installation failed.
popd
exit /b 1
)
)
echo [INFO] Running frontend typecheck...
call npm run typecheck || (
echo [ERROR] Frontend typecheck failed.
popd
exit /b 1
)
echo [INFO] Running frontend build...
call npm run build || (
echo [ERROR] Frontend build failed.
popd
exit /b 1
)
popd
where docker >nul 2>&1
if errorlevel 1 (
echo [WARN] Docker is not available on PATH. Skipping Docker build smoke.
) else (
echo [INFO] Running Docker build smoke...
docker build -t openllmbenchmark:preflight . || (
echo [ERROR] Docker build failed.
exit /b 1
)
)
echo [OK] Preflight checks completed.
exit /b 0
:run_github
call :ensure_repo || exit /b 1
call :get_current_branch || exit /b 1
call :is_clean_tree
if errorlevel 1 (
if "%COMMIT_MSG%"=="" (
echo [ERROR] Commit message is required when there are local changes.
echo Example: %SCRIPT_NAME% github "Fix scoring edge cases"
exit /b 1
)
echo [INFO] Staging all changes...
git add -A || exit /b 1
echo [INFO] Creating commit...
git commit -m "%COMMIT_MSG%" || exit /b 1
) else (
echo [INFO] Working tree is clean. Nothing to commit.
)
echo [INFO] Pushing to origin/%CURRENT_BRANCH%...
git push origin %CURRENT_BRANCH% || exit /b 1
echo [OK] GitHub push completed.
exit /b 0
:run_hf
call :ensure_repo || exit /b 1
call :get_current_branch || exit /b 1
call :require_clean_tree || exit /b 1
for /f "delims=" %%I in ('git rev-parse HEAD') do set "SOURCE_SHA=%%I"
if not exist "README.md" (
echo [ERROR] README.md not found at repo root.
exit /b 1
)
if not exist "Dockerfile" (
echo [ERROR] Dockerfile not found at repo root.
exit /b 1
)
if not exist "docker\start.sh" (
echo [ERROR] docker\start.sh not found.
exit /b 1
)
if not exist "docker\nginx.conf" (
echo [ERROR] docker\nginx.conf not found.
exit /b 1
)
echo [INFO] Creating clean deployment snapshot for Hugging Face Space...
set "TMP_DIR=%TEMP%\hf_space_deploy_%RANDOM%%RANDOM%%RANDOM%"
mkdir "%TMP_DIR%" || (
echo [ERROR] Could not create temp directory: %TMP_DIR%
exit /b 1
)
git checkout-index -a -f --prefix="%TMP_DIR%\\" >nul
if errorlevel 1 (
echo [ERROR] Failed to export tracked files with git checkout-index.
set "EXIT_CODE=1"
goto :cleanup
)
if exist "%TMP_DIR%\image\README" rmdir /s /q "%TMP_DIR%\image\README"
for %%F in ("%TMP_DIR%\_debug_sidebar*.png") do if exist "%%~fF" del /f /q "%%~fF"
for /r "%TMP_DIR%" %%F in (*.docx) do del /f /q "%%~fF"
pushd "%TMP_DIR%" || (
echo [ERROR] Could not enter temp directory.
set "EXIT_CODE=1"
goto :cleanup
)
git init >nul || (
echo [ERROR] git init failed in temp snapshot.
popd
set "EXIT_CODE=1"
goto :cleanup
)
git config user.name "hf-space-deployer" >nul
git config user.email "hf-space-deployer@local" >nul
git add . || (
echo [ERROR] git add failed in temp snapshot.
popd
set "EXIT_CODE=1"
goto :cleanup
)
git commit -m "HF Space deploy from %CURRENT_BRANCH% - %SOURCE_SHA%" >nul || (
echo [ERROR] git commit failed in temp snapshot.
popd
set "EXIT_CODE=1"
goto :cleanup
)
git remote add hf "%SPACE_URL%" >nul
setlocal EnableDelayedExpansion
set "REMOTE_SHA="
for /f "tokens=1" %%H in ('git ls-remote hf refs/heads/%SPACE_BRANCH%') do if not defined REMOTE_SHA set "REMOTE_SHA=%%H"
if defined REMOTE_SHA (
git push hf HEAD:%SPACE_BRANCH% --force-with-lease=refs/heads/%SPACE_BRANCH%:!REMOTE_SHA!
if errorlevel 1 (
echo [WARN] Lease check failed. Refreshing remote ref and retrying once...
set "REMOTE_SHA="
for /f "tokens=1" %%H in ('git ls-remote hf refs/heads/%SPACE_BRANCH%') do if not defined REMOTE_SHA set "REMOTE_SHA=%%H"
if defined REMOTE_SHA (
git push hf HEAD:%SPACE_BRANCH% --force-with-lease=refs/heads/%SPACE_BRANCH%:!REMOTE_SHA!
) else (
git push hf HEAD:%SPACE_BRANCH% --force
)
)
) else (
git push hf HEAD:%SPACE_BRANCH% --force
)
set "PUSH_EXIT=!ERRORLEVEL!"
endlocal & set "PUSH_EXIT=%PUSH_EXIT%"
popd
if not "%PUSH_EXIT%"=="0" (
echo [ERROR] Hugging Face push failed.
set "EXIT_CODE=1"
goto :cleanup
)
echo [OK] Hugging Face Space deploy completed.
set "EXIT_CODE=0"
goto :cleanup
:run_all
if "%COMMIT_MSG%"=="" (
echo [ERROR] Commit message is required for 'all'.
echo Example: %SCRIPT_NAME% all "Update benchmark UI"
exit /b 1
)
call :run_github
if errorlevel 1 exit /b 1
call :run_hf
exit /b %ERRORLEVEL%
:cleanup
if defined TMP_DIR (
if exist "%TMP_DIR%" rmdir /s /q "%TMP_DIR%"
)
if not defined EXIT_CODE set "EXIT_CODE=1"
exit /b %EXIT_CODE%
|