build.ps1 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. # deepseek-tray 构建脚本:格式检查 -> 静态检查 -> 单元测试 -> 构建
  2. # 版本号唯一维护点(README 的版本历史与此保持一致)
  3. $Version = '2.5.0'
  4. $ErrorActionPreference = 'Stop'
  5. Push-Location $PSScriptRoot
  6. try {
  7. Write-Host ('deepseek-tray v' + $Version) -ForegroundColor Cyan
  8. Write-Host '[1/4] gofmt 检查'
  9. $unformatted = gofmt -l .
  10. if ($unformatted) { throw ('以下文件未格式化: ' + ($unformatted -join ', ')) }
  11. Write-Host '[2/4] go vet'
  12. go vet ./...
  13. if ($LASTEXITCODE -ne 0) { throw 'go vet 失败' }
  14. Write-Host '[3/4] go test'
  15. go test ./...
  16. if ($LASTEXITCODE -ne 0) { throw 'go test 失败' }
  17. Write-Host '[4/4] go build'
  18. go build -trimpath -ldflags "-H=windowsgui -s -w -X main.appVersion=$Version" -o deepseek-tray.exe .
  19. if ($LASTEXITCODE -ne 0) { throw 'go build 失败' }
  20. # 目标 exe 被运行中的实例占用时,Go 会留下 .exe~ 备份(约 5 MB),顺手清理
  21. Get-ChildItem -Filter '*.exe~' -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue
  22. $size = [math]::Round((Get-Item 'deepseek-tray.exe').Length / 1KB, 0)
  23. Write-Host ('构建成功: deepseek-tray.exe (' + $size + ' KB, v' + $Version + ')') -ForegroundColor Green
  24. } finally {
  25. Pop-Location
  26. }