首次提交
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# 寸进后端打包部署脚本
|
||||
# 用法: .\scripts\build-backend.ps1 [platform]
|
||||
# platform: windows (默认) | linux | all
|
||||
|
||||
param([string]$Platform = "windows")
|
||||
|
||||
$root = Split-Path -Parent $PSScriptRoot
|
||||
$serverDir = Join-Path $root "server"
|
||||
$outputDir = Join-Path $root "build"
|
||||
$version = "1.0.0"
|
||||
$commit = git -C $root rev-parse --short HEAD 2>$null
|
||||
if (-not $commit) { $commit = "dev" }
|
||||
|
||||
$ldflags = "-s -w -X main.version=$version -X main.commit=$commit"
|
||||
|
||||
function Build-Platform {
|
||||
param([string]$GOOS, [string]$GOARCH, [string]$suffix)
|
||||
$outName = "inchstep-api$suffix"
|
||||
$outPath = Join-Path $outputDir $outName
|
||||
|
||||
Write-Host "Building for $GOOS/$GOARCH ..." -ForegroundColor Cyan
|
||||
$env:GOOS = $GOOS
|
||||
$env:GOARCH = $GOARCH
|
||||
$env:CGO_ENABLED = 0
|
||||
|
||||
Push-Location $serverDir
|
||||
$result = & go build -buildvcs=false -ldflags $ldflags -o $outPath ./cmd/api 2>&1
|
||||
Pop-Location
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
$size = (Get-Item $outPath).Length / 1KB
|
||||
Write-Host " OK: $outPath ($([math]::Round($size, 1)) KB)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host " FAIL: $result" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $outputDir | Out-Null
|
||||
|
||||
switch ($Platform) {
|
||||
"windows" { Build-Platform "windows" "amd64" ".exe" }
|
||||
"linux" { Build-Platform "linux" "amd64" "" }
|
||||
"all" {
|
||||
Build-Platform "windows" "amd64" ".exe"
|
||||
Build-Platform "linux" "amd64" ""
|
||||
Build-Platform "linux" "arm64" "-arm64"
|
||||
}
|
||||
default { Build-Platform "windows" "amd64" ".exe" }
|
||||
}
|
||||
|
||||
Write-Host "Build complete. Output directory: $outputDir" -ForegroundColor Green
|
||||
Reference in New Issue
Block a user