fix: normalize bat CRLF line endings; rewrite all-themes builder with git stash + goto pattern
This commit is contained in:
@@ -18,8 +18,6 @@ REM thebet365-player-theme-2.tar -> thebet365-player:theme-2
|
|||||||
REM thebet365-player-theme-3.tar -> thebet365-player:theme-3
|
REM thebet365-player-theme-3.tar -> thebet365-player:theme-3
|
||||||
REM thebet365-player-theme-4.tar -> thebet365-player:theme-4
|
REM thebet365-player-theme-4.tar -> thebet365-player:theme-4
|
||||||
REM thebet365-images-latest.tar -> api:latest + admin:latest
|
REM thebet365-images-latest.tar -> api:latest + admin:latest
|
||||||
REM
|
|
||||||
REM Related: docs\si-tao-zhuti-docker-bushu-renwu.md
|
|
||||||
REM ================================================================
|
REM ================================================================
|
||||||
|
|
||||||
cd /d "%~dp0..\.."
|
cd /d "%~dp0..\.."
|
||||||
@@ -76,13 +74,27 @@ if not defined ORIGINAL_BRANCH (
|
|||||||
)
|
)
|
||||||
echo [INFO] Current branch: %ORIGINAL_BRANCH%
|
echo [INFO] Current branch: %ORIGINAL_BRANCH%
|
||||||
|
|
||||||
REM -- Warn about dirty working tree
|
REM -- Stash any local changes so branch switching works cleanly
|
||||||
|
set "DID_STASH=0"
|
||||||
git diff --quiet 2>nul
|
git diff --quiet 2>nul
|
||||||
set "D1=!ERRORLEVEL!"
|
set "D1=!ERRORLEVEL!"
|
||||||
git diff --cached --quiet 2>nul
|
git diff --cached --quiet 2>nul
|
||||||
set "D2=!ERRORLEVEL!"
|
set "D2=!ERRORLEVEL!"
|
||||||
if not "!D1!"=="0" echo [WARN] Unstaged changes detected. Consider running 'git stash' first.
|
if not "!D1!"=="0" goto do_stash
|
||||||
if not "!D2!"=="0" echo [WARN] Staged changes detected. Consider running 'git stash' first.
|
if not "!D2!"=="0" goto do_stash
|
||||||
|
goto stash_done
|
||||||
|
|
||||||
|
:do_stash
|
||||||
|
echo [INFO] Stashing local changes before branch switching...
|
||||||
|
git stash push -m "build-all-themes auto-stash" >nul 2>&1
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo [WARN] git stash failed. Branch switching may fail if there are conflicts.
|
||||||
|
) else (
|
||||||
|
set "DID_STASH=1"
|
||||||
|
echo [INFO] Changes stashed.
|
||||||
|
)
|
||||||
|
|
||||||
|
:stash_done
|
||||||
|
|
||||||
REM -- Build extra arguments for the base script
|
REM -- Build extra arguments for the base script
|
||||||
set "EXTRA_ARGS="
|
set "EXTRA_ARGS="
|
||||||
@@ -93,7 +105,7 @@ set "FAILED_THEMES="
|
|||||||
set "SUCCESS_COUNT=0"
|
set "SUCCESS_COUNT=0"
|
||||||
|
|
||||||
REM ================================================================
|
REM ================================================================
|
||||||
REM Build each player theme: call :build_theme <branch> <tag>
|
REM Build each player theme
|
||||||
REM ================================================================
|
REM ================================================================
|
||||||
|
|
||||||
call :build_theme main main
|
call :build_theme main main
|
||||||
@@ -104,35 +116,51 @@ call :build_theme theme-4 theme-4
|
|||||||
REM -- Restore original branch
|
REM -- Restore original branch
|
||||||
echo.
|
echo.
|
||||||
echo [INFO] Restoring original branch: %ORIGINAL_BRANCH%
|
echo [INFO] Restoring original branch: %ORIGINAL_BRANCH%
|
||||||
|
cd /d "%ROOT_DIR%"
|
||||||
git checkout %ORIGINAL_BRANCH% >nul 2>&1
|
git checkout %ORIGINAL_BRANCH% >nul 2>&1
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo [WARN] Could not restore branch %ORIGINAL_BRANCH%. Please run: git checkout %ORIGINAL_BRANCH%
|
echo [WARN] Could not restore branch %ORIGINAL_BRANCH%. Run: git checkout %ORIGINAL_BRANCH%
|
||||||
) else (
|
) else (
|
||||||
echo [INFO] Restored to %ORIGINAL_BRANCH%
|
echo [INFO] Restored to %ORIGINAL_BRANCH%
|
||||||
)
|
)
|
||||||
|
|
||||||
REM -- Build api + admin on main branch
|
REM -- Pop stash if we stashed earlier
|
||||||
if "%SKIP_API_ADMIN%"=="0" (
|
if "%DID_STASH%"=="1" (
|
||||||
echo.
|
echo [INFO] Restoring stashed changes...
|
||||||
echo [INFO] Building api + admin (tag: latest) on main branch...
|
git stash pop >nul 2>&1
|
||||||
pushd "%ROOT_DIR%"
|
if errorlevel 1 (
|
||||||
git checkout main >nul 2>&1
|
echo [WARN] git stash pop failed. Run: git stash pop
|
||||||
call docs\docker\build-and-export-images.bat --tag latest!EXTRA_ARGS!
|
|
||||||
set "API_BUILD_ERR=!ERRORLEVEL!"
|
|
||||||
pushd "%ROOT_DIR%"
|
|
||||||
if "!API_BUILD_ERR!" neq "0" (
|
|
||||||
echo [ERROR] api/admin build failed
|
|
||||||
set "FAILED_THEMES=!FAILED_THEMES! api/admin"
|
|
||||||
) else (
|
) else (
|
||||||
set /a SUCCESS_COUNT+=1
|
echo [INFO] Stash restored.
|
||||||
)
|
)
|
||||||
popd
|
|
||||||
popd
|
|
||||||
echo.
|
|
||||||
echo [INFO] Restoring original branch: %ORIGINAL_BRANCH%
|
|
||||||
git checkout %ORIGINAL_BRANCH% >nul 2>&1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
REM -- Build api + admin on main branch
|
||||||
|
if "%SKIP_API_ADMIN%"=="1" goto skip_api_admin
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo [INFO] Building api + admin (tag: latest) on branch main...
|
||||||
|
cd /d "%ROOT_DIR%"
|
||||||
|
git checkout main >nul 2>&1
|
||||||
|
cd /d "%ROOT_DIR%"
|
||||||
|
call docs\docker\build-and-export-images.bat --tag latest!EXTRA_ARGS!
|
||||||
|
set "API_ERR=!ERRORLEVEL!"
|
||||||
|
cd /d "%ROOT_DIR%"
|
||||||
|
if "!API_ERR!"=="0" goto api_ok
|
||||||
|
echo [ERROR] api/admin build failed
|
||||||
|
set "FAILED_THEMES=!FAILED_THEMES! api/admin"
|
||||||
|
goto after_api_admin
|
||||||
|
|
||||||
|
:api_ok
|
||||||
|
set /a SUCCESS_COUNT+=1
|
||||||
|
|
||||||
|
:after_api_admin
|
||||||
|
echo.
|
||||||
|
echo [INFO] Restoring original branch: %ORIGINAL_BRANCH%
|
||||||
|
git checkout %ORIGINAL_BRANCH% >nul 2>&1
|
||||||
|
|
||||||
|
:skip_api_admin
|
||||||
|
|
||||||
REM ================================================================
|
REM ================================================================
|
||||||
REM Summary
|
REM Summary
|
||||||
REM ================================================================
|
REM ================================================================
|
||||||
@@ -141,46 +169,48 @@ echo ================================================================
|
|||||||
echo BUILD SUMMARY
|
echo BUILD SUMMARY
|
||||||
echo ================================================================
|
echo ================================================================
|
||||||
echo Succeeded: !SUCCESS_COUNT! task(s)
|
echo Succeeded: !SUCCESS_COUNT! task(s)
|
||||||
if defined FAILED_THEMES (
|
if not defined FAILED_THEMES goto all_ok
|
||||||
echo Failed: !FAILED_THEMES!
|
|
||||||
echo.
|
echo Failed: !FAILED_THEMES!
|
||||||
echo Tip: Retry failed themes manually:
|
echo.
|
||||||
echo git checkout ^<branch^>
|
echo Tip: Retry failed themes manually:
|
||||||
echo docs\docker\build-and-export-images.bat --service player --tag ^<tag^>
|
echo git checkout ^<branch^>
|
||||||
echo ================================================================
|
echo docs\docker\build-and-export-images.bat --service player --tag ^<tag^>
|
||||||
echo.
|
echo ================================================================
|
||||||
endlocal
|
echo.
|
||||||
exit /b 1
|
endlocal
|
||||||
) else (
|
exit /b 1
|
||||||
echo.
|
|
||||||
echo All done! Output files in project root:
|
:all_ok
|
||||||
echo thebet365-player-main.tar
|
echo.
|
||||||
echo thebet365-player-theme-2.tar
|
echo All done! Output files in project root:
|
||||||
echo thebet365-player-theme-3.tar
|
echo thebet365-player-main.tar
|
||||||
echo thebet365-player-theme-4.tar
|
echo thebet365-player-theme-2.tar
|
||||||
if "%SKIP_API_ADMIN%"=="0" (
|
echo thebet365-player-theme-3.tar
|
||||||
|
echo thebet365-player-theme-4.tar
|
||||||
|
if "%SKIP_API_ADMIN%"=="0" (
|
||||||
echo thebet365-images-latest.tar (api + admin)
|
echo thebet365-images-latest.tar (api + admin)
|
||||||
)
|
|
||||||
echo.
|
|
||||||
echo Server import commands:
|
|
||||||
echo docker load -i thebet365-images-latest.tar
|
|
||||||
echo docker load -i thebet365-player-main.tar
|
|
||||||
echo docker load -i thebet365-player-theme-2.tar
|
|
||||||
echo docker load -i thebet365-player-theme-3.tar
|
|
||||||
echo docker load -i thebet365-player-theme-4.tar
|
|
||||||
echo.
|
|
||||||
echo Start (first multi-theme deploy):
|
|
||||||
echo docker compose -f docker-compose.prod.yml -f docker-compose.themes.yml --env-file .env.docker up -d
|
|
||||||
echo ================================================================
|
|
||||||
echo.
|
|
||||||
)
|
)
|
||||||
|
echo.
|
||||||
|
echo Server import commands:
|
||||||
|
echo docker load -i thebet365-images-latest.tar
|
||||||
|
echo docker load -i thebet365-player-main.tar
|
||||||
|
echo docker load -i thebet365-player-theme-2.tar
|
||||||
|
echo docker load -i thebet365-player-theme-3.tar
|
||||||
|
echo docker load -i thebet365-player-theme-4.tar
|
||||||
|
echo.
|
||||||
|
echo Start (first multi-theme deploy):
|
||||||
|
echo docker compose -f docker-compose.prod.yml -f docker-compose.themes.yml --env-file .env.docker up -d
|
||||||
|
echo ================================================================
|
||||||
|
echo.
|
||||||
endlocal
|
endlocal
|
||||||
exit /b 0
|
exit /b 0
|
||||||
|
|
||||||
|
|
||||||
REM ================================================================
|
REM ================================================================
|
||||||
REM :build_theme <branch> <tag>
|
REM :build_theme <branch> <tag>
|
||||||
REM Switch to the given branch, build player image, tag success/fail
|
REM Switch to branch, build player, mark success/fail.
|
||||||
|
REM Uses cd /d ROOT_DIR instead of pushd to avoid stack issues.
|
||||||
REM ================================================================
|
REM ================================================================
|
||||||
:build_theme
|
:build_theme
|
||||||
set "THEME_BRANCH=%~1"
|
set "THEME_BRANCH=%~1"
|
||||||
@@ -191,31 +221,41 @@ echo ----------------------------------------------------------------
|
|||||||
echo [INFO] Theme: %THEME_BRANCH% (image tag: %THEME_TAG%)
|
echo [INFO] Theme: %THEME_BRANCH% (image tag: %THEME_TAG%)
|
||||||
echo ----------------------------------------------------------------
|
echo ----------------------------------------------------------------
|
||||||
|
|
||||||
REM -- Always operate from the repo root
|
cd /d "%ROOT_DIR%"
|
||||||
pushd "%ROOT_DIR%"
|
|
||||||
|
|
||||||
git checkout %THEME_BRANCH% >nul 2>&1
|
git checkout %THEME_BRANCH% >nul 2>&1
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo [ERROR] Cannot switch to branch %THEME_BRANCH% -- skipping
|
echo [ERROR] Cannot switch to branch %THEME_BRANCH% -- skipping
|
||||||
set "FAILED_THEMES=!FAILED_THEMES! %THEME_BRANCH%"
|
set "FAILED_THEMES=!FAILED_THEMES! %THEME_BRANCH%"
|
||||||
popd
|
|
||||||
exit /b 0
|
exit /b 0
|
||||||
)
|
)
|
||||||
echo [INFO] Switched to %THEME_BRANCH%
|
echo [INFO] Switched to %THEME_BRANCH%
|
||||||
|
|
||||||
|
cd /d "%ROOT_DIR%"
|
||||||
call docs\docker\build-and-export-images.bat --service player --tag %THEME_TAG%!EXTRA_ARGS!
|
call docs\docker\build-and-export-images.bat --service player --tag %THEME_TAG%!EXTRA_ARGS!
|
||||||
set "THEME_BUILD_ERR=!ERRORLEVEL!"
|
set "BUILD_ERR=!ERRORLEVEL!"
|
||||||
|
|
||||||
REM -- Restore working directory after call (child bat changes cwd)
|
cd /d "%ROOT_DIR%"
|
||||||
pushd "%ROOT_DIR%"
|
if "!BUILD_ERR!"=="0" goto build_ok_%THEME_TAG%
|
||||||
|
echo [ERROR] Player build failed for %THEME_BRANCH%
|
||||||
if "!THEME_BUILD_ERR!" neq "0" (
|
set "FAILED_THEMES=!FAILED_THEMES! %THEME_BRANCH%"
|
||||||
echo [ERROR] Player build failed for %THEME_BRANCH%
|
|
||||||
set "FAILED_THEMES=!FAILED_THEMES! %THEME_BRANCH%"
|
|
||||||
) else (
|
|
||||||
echo [OK] thebet365-player:%THEME_TAG% exported successfully
|
|
||||||
set /a SUCCESS_COUNT+=1
|
|
||||||
)
|
|
||||||
popd
|
|
||||||
popd
|
|
||||||
exit /b 0
|
exit /b 0
|
||||||
|
|
||||||
|
:build_ok_main
|
||||||
|
echo [OK] thebet365-player:main exported successfully
|
||||||
|
set /a SUCCESS_COUNT+=1
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:build_ok_theme-2
|
||||||
|
echo [OK] thebet365-player:theme-2 exported successfully
|
||||||
|
set /a SUCCESS_COUNT+=1
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:build_ok_theme-3
|
||||||
|
echo [OK] thebet365-player:theme-3 exported successfully
|
||||||
|
set /a SUCCESS_COUNT+=1
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:build_ok_theme-4
|
||||||
|
echo [OK] thebet365-player:theme-4 exported successfully
|
||||||
|
set /a SUCCESS_COUNT+=1
|
||||||
|
exit /b 0
|
||||||
|
|||||||
Reference in New Issue
Block a user