27
scripts/pack.ps1
Normal file
27
scripts/pack.ps1
Normal file
@@ -0,0 +1,27 @@
|
||||
# 保存调用进程的 Go 构建环境,脚本结束后恢复。
|
||||
$hasGOOS = Test-Path Env:GOOS
|
||||
$hasGOARCH = Test-Path Env:GOARCH
|
||||
$hasGOFLAGS = Test-Path Env:GOFLAGS
|
||||
$originalGOOS = $env:GOOS
|
||||
$originalGOARCH = $env:GOARCH
|
||||
$originalGOFLAGS = $env:GOFLAGS
|
||||
|
||||
Push-Location (Join-Path $PSScriptRoot '..')
|
||||
try {
|
||||
New-Item -ItemType Directory -Force -Path './build' | Out-Null
|
||||
|
||||
$env:GOOS = 'linux'
|
||||
$env:GOARCH = 'amd64'
|
||||
$env:GOFLAGS = '-buildvcs=false'
|
||||
|
||||
& go build -o './build/ops-files' './cmd/main/main.go'
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "go build 失败,退出码:$LASTEXITCODE"
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if ($hasGOOS) { $env:GOOS = $originalGOOS } else { Remove-Item Env:GOOS }
|
||||
if ($hasGOARCH) { $env:GOARCH = $originalGOARCH } else { Remove-Item Env:GOARCH }
|
||||
if ($hasGOFLAGS) { $env:GOFLAGS = $originalGOFLAGS } else { Remove-Item Env:GOFLAGS }
|
||||
Pop-Location
|
||||
}
|
||||
Reference in New Issue
Block a user