PowerShell 5.1 的 Invoke-RestMethod 传字符串 body 会按 ISO-8859-1 编码,Release 标题/正文的中文全变成 ?;改为 UTF-8 字节 + charset,并对已有 Release 做 PATCH。build.bat 生成便携版 zip 并把它的 SHA256 补进 SHA256SUMS,发布脚本同时上传 setup 安装包与便携版 zip(Gitea Release 附件实测接受 .exe)。新增 -MetadataOnly 只刷新文案;修 build.bat 读 mygo.json 未指定 UTF8 导致版本号取空的问题。
76 lines
3.5 KiB
Batchfile
76 lines
3.5 KiB
Batchfile
@echo off
|
||
chcp 65001 >nul
|
||
cd /d "%~dp0"
|
||
setlocal
|
||
|
||
rem 构建 ZerOriginToolBox(mygo 单进程版)
|
||
rem build.bat 完整构建:watchdog + 应用 + 便携版 + NSIS 安装包
|
||
rem build.bat quick 快速构建:跳过安装包
|
||
|
||
set SKIP_INSTALLER=
|
||
if /i "%~1"=="quick" set SKIP_INSTALLER=-skip-installer
|
||
|
||
echo [build] 终止旧进程...
|
||
taskkill /f /im ZerOriginTool.exe >nul 2>&1
|
||
taskkill /f /im watchdog.exe >nul 2>&1
|
||
|
||
rem Go 工具链与 mygo 插件都在 GOPATH\bin,确保可直接调用。
|
||
set "GOPATH="
|
||
for /f "tokens=*" %%i in ('go env GOPATH 2^>nul') do set "GOPATH=%%i"
|
||
if not defined GOPATH set "GOPATH=%USERPROFILE%\go"
|
||
set "PATH=%GOPATH%\bin;%PATH%"
|
||
|
||
rem 自更新签名私钥:不进仓库,默认读 mygo keygen 的默认位置。
|
||
rem 带私钥构建会额外产出 <slug>-<version>-<target>.tar.gz、delta 与 update-<target>.json;
|
||
rem 没有私钥时只构建应用,不产出更新文件(mygo 只是警告,不报错)。
|
||
if not defined MYGO_UPDATER_PRIVATE_KEY (
|
||
if exist "%APPDATA%\mygo\update-keys\mygo-update.key" (
|
||
set /p MYGO_UPDATER_PRIVATE_KEY=<"%APPDATA%\mygo\update-keys\mygo-update.key"
|
||
)
|
||
)
|
||
if defined MYGO_UPDATER_PRIVATE_KEY (
|
||
echo [build] 已加载更新签名私钥,将产出签名更新包
|
||
) else (
|
||
echo [build] 未找到更新签名私钥(%APPDATA%\mygo\update-keys\mygo-update.key),只构建不签名
|
||
)
|
||
|
||
echo [build] 编译监督进程 watchdog...
|
||
if not exist resources\windows-amd64 mkdir resources\windows-amd64
|
||
go build -trimpath -ldflags="-s -w -H windowsgui" -o resources\windows-amd64\watchdog.exe .\cmd\watchdog
|
||
if errorlevel 1 goto fail_watchdog
|
||
|
||
echo [build] 打包应用(mygo:可执行文件 + 资源 + 安装包)...
|
||
go tool mygo build -platform windows/amd64 %SKIP_INSTALLER%
|
||
if errorlevel 1 goto fail_mygo
|
||
|
||
echo [build] 生成便携版...
|
||
if not exist portable mkdir portable
|
||
copy /y bin\windows-amd64\ZerOriginTool.exe portable\ZerOriginTool.exe >nul
|
||
copy /y bin\windows-amd64\watchdog.exe portable\watchdog.exe >nul
|
||
|
||
rem 便携版压缩包:新用户下载解压即用。自更新用的 tar.gz 也能解压,但文件名和内容(.mygo-files)
|
||
rem 是给更新器看的,不适合当分发物。
|
||
rem 注意 -Encoding UTF8:mygo.json 是 UTF-8(含中文),不加会被按 GBK 读成乱码导致 ConvertFrom-Json 失败。
|
||
for /f "tokens=*" %%v in ('powershell -NoProfile -Command "(Get-Content mygo.json -Raw -Encoding UTF8 | ConvertFrom-Json).version"') do set "APPVER=%%v"
|
||
if not defined APPVER set "APPVER=0.0.0"
|
||
powershell -NoProfile -Command "Compress-Archive -Path 'portable\ZerOriginTool.exe','portable\watchdog.exe','portable\README.txt' -DestinationPath ('bin\windows-amd64\zerorigin-toolbox-' + $env:APPVER + '-windows-amd64-portable.zip') -Force"
|
||
if errorlevel 1 echo [build] 便携版压缩包生成失败(不影响其他产物)
|
||
|
||
rem 便携版压缩包也记进 bin\SHA256SUMS(mygo 写校验和时 zip 还不存在),方便用户校验下载。
|
||
for /f "tokens=*" %%h in ('powershell -NoProfile -Command "(Get-FileHash (Join-Path 'bin\windows-amd64' ('zerorigin-toolbox-' + $env:APPVER + '-windows-amd64-portable.zip')) -Algorithm SHA256).Hash.ToLower()"') do set "ZIPHASH=%%h"
|
||
if defined ZIPHASH echo %ZIPHASH% zerorigin-toolbox-%APPVER%-windows-amd64-portable.zip>>bin\SHA256SUMS
|
||
|
||
echo [build] 完成,产物:
|
||
dir /b bin\windows-amd64\*.exe
|
||
dir /b bin\windows-amd64\*.zip 2>nul
|
||
echo 便携版:portable\
|
||
exit /b 0
|
||
|
||
:fail_watchdog
|
||
echo [build] watchdog 编译失败!
|
||
exit /b 1
|
||
|
||
:fail_mygo
|
||
echo [build] mygo 打包失败!
|
||
exit /b 1
|