111 lines
2.9 KiB
Batchfile
111 lines
2.9 KiB
Batchfile
@echo off
|
|
setlocal EnableExtensions EnableDelayedExpansion
|
|
cd /d "%~dp0"
|
|
|
|
set "SELF_CONTAINED=false"
|
|
if /I "%~1"=="--self-contained" (
|
|
set "SELF_CONTAINED=true"
|
|
shift
|
|
)
|
|
|
|
set "OUTPUT_ROOT=%~f1"
|
|
if "%~1"=="" set "OUTPUT_ROOT=%~dp0dist"
|
|
set "PROJECT=%~dp0Zcbot.WindowsNode\Zcbot.WindowsNode.csproj"
|
|
set "RUNTIME_ID=win-x64"
|
|
|
|
if not exist "%PROJECT%" (
|
|
echo [ERR] Windows Node project was not found: %PROJECT%
|
|
goto :failed
|
|
)
|
|
where.exe dotnet.exe >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo [ERR] .NET SDK was not found in PATH.
|
|
goto :failed
|
|
)
|
|
where.exe tar.exe >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo [ERR] Windows tar.exe was not found.
|
|
goto :failed
|
|
)
|
|
where.exe certutil.exe >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo [ERR] Windows certutil.exe was not found.
|
|
goto :failed
|
|
)
|
|
|
|
set "VERSION="
|
|
for /f "usebackq tokens=*" %%V in (`dotnet msbuild "%PROJECT%" -nologo -getProperty:Version`) do (
|
|
if not "%%V"=="" set "VERSION=%%V"
|
|
)
|
|
if not defined VERSION (
|
|
echo [ERR] Could not read the Windows Node version.
|
|
goto :failed
|
|
)
|
|
|
|
set "PACKAGE_NAME=zcbot-windows-node-!VERSION!-!RUNTIME_ID!"
|
|
set "PUBLISH_DIR=!OUTPUT_ROOT!\!PACKAGE_NAME!"
|
|
set "ARCHIVE_PATH=!OUTPUT_ROOT!\!PACKAGE_NAME!.zip"
|
|
set "HASH_PATH=!ARCHIVE_PATH!.sha256"
|
|
|
|
if not exist "!OUTPUT_ROOT!" mkdir "!OUTPUT_ROOT!"
|
|
if errorlevel 1 goto :failed
|
|
if exist "!PUBLISH_DIR!" rmdir /s /q "!PUBLISH_DIR!"
|
|
if exist "!ARCHIVE_PATH!" del /f /q "!ARCHIVE_PATH!"
|
|
if exist "!HASH_PATH!" del /f /q "!HASH_PATH!"
|
|
|
|
echo [INFO] Publishing !PACKAGE_NAME! (self-contained=!SELF_CONTAINED!)
|
|
dotnet publish "%PROJECT%" --configuration Release --runtime !RUNTIME_ID! --self-contained !SELF_CONTAINED! --output "!PUBLISH_DIR!"
|
|
if errorlevel 1 (
|
|
echo [ERR] dotnet publish failed.
|
|
goto :failed
|
|
)
|
|
|
|
for %%F in (
|
|
"Zcbot.WindowsNode.exe"
|
|
"install-windows-node.bat"
|
|
"adapters\origin.plot@v2\adapter.json"
|
|
"adapters\origin.plot@v2\worker.py"
|
|
"adapters\origin.plot@v2\requirements.txt"
|
|
"adapters\origin.plot@v2\origin.plot.v2.json"
|
|
) do (
|
|
if not exist "!PUBLISH_DIR!\%%~F" (
|
|
echo [ERR] Published package is incomplete: %%~F
|
|
goto :failed
|
|
)
|
|
)
|
|
|
|
tar.exe -a -c -f "!ARCHIVE_PATH!" -C "!OUTPUT_ROOT!" "!PACKAGE_NAME!"
|
|
if errorlevel 1 (
|
|
echo [ERR] Failed to create the ZIP package.
|
|
goto :failed
|
|
)
|
|
|
|
set "SHA256="
|
|
for /f "tokens=*" %%H in ('certutil.exe -hashfile "!ARCHIVE_PATH!" SHA256 ^| findstr.exe /R /C:"^[0-9A-Fa-f][0-9A-Fa-f ]*[0-9A-Fa-f]$"') do (
|
|
set "SHA256=%%H"
|
|
)
|
|
set "SHA256=!SHA256: =!"
|
|
if not defined SHA256 (
|
|
echo [ERR] Failed to calculate the ZIP SHA-256.
|
|
goto :failed
|
|
)
|
|
>"!HASH_PATH!" echo !SHA256! !PACKAGE_NAME!.zip
|
|
|
|
echo [OK] Package: !ARCHIVE_PATH!
|
|
echo [OK] SHA256: !SHA256!
|
|
echo [INFO] Extract the ZIP and double-click install-windows-node.bat.
|
|
goto :finish_ok
|
|
|
|
:failed
|
|
echo.
|
|
echo [ERR] Windows Node packaging failed.
|
|
echo [INFO] Press any key to close this window.
|
|
pause >nul
|
|
exit /b 1
|
|
|
|
:finish_ok
|
|
echo.
|
|
echo [INFO] Press any key to close this window.
|
|
pause >nul
|
|
exit /b 0
|