mirror of
https://git.fightbot.fun/hxuanyu/BingPaper.git
synced 2026-02-15 10:19:32 +08:00
新增编译脚本和 github 工作流配置文件
This commit is contained in:
67
scripts/build.ps1
Normal file
67
scripts/build.ps1
Normal file
@@ -0,0 +1,67 @@
|
||||
$AppName = "BingPaper"
|
||||
$OutputDir = "output"
|
||||
|
||||
Write-Host "开始构建 $AppName 多平台二进制文件..."
|
||||
|
||||
if (Test-Path $OutputDir) {
|
||||
Remove-Item -Recurse -Force $OutputDir
|
||||
}
|
||||
New-Item -ItemType Directory -Path $OutputDir | Out-Null
|
||||
|
||||
$Platforms = @(
|
||||
"linux/amd64",
|
||||
"linux/arm64",
|
||||
"windows/amd64",
|
||||
"windows/arm64",
|
||||
"darwin/amd64",
|
||||
"darwin/arm64"
|
||||
)
|
||||
|
||||
foreach ($Platform in $Platforms) {
|
||||
$parts = $Platform.Split("/")
|
||||
$OS = $parts[0]
|
||||
$Arch = $parts[1]
|
||||
|
||||
$OutputName = "$AppName-$OS-$Arch"
|
||||
$BinaryName = $OutputName
|
||||
if ($OS -eq "windows") {
|
||||
$BinaryName = "$OutputName.exe"
|
||||
}
|
||||
|
||||
Write-Host "正在编译 $OS/$Arch..."
|
||||
|
||||
$PackageDir = Join-Path $OutputDir $OutputName
|
||||
if (-not (Test-Path $PackageDir)) {
|
||||
New-Item -ItemType Directory -Path $PackageDir | Out-Null
|
||||
}
|
||||
|
||||
$env:GOOS = $OS
|
||||
$env:GOARCH = $Arch
|
||||
$env:CGO_ENABLED = "0"
|
||||
go build -o (Join-Path $PackageDir $BinaryName) main.go
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host " $OS/$Arch 编译成功"
|
||||
|
||||
Copy-Item -Recurse "web" $PackageDir\
|
||||
Copy-Item "config.example.yaml" $PackageDir\
|
||||
Copy-Item "README.md" $PackageDir\
|
||||
|
||||
$CurrentDir = Get-Location
|
||||
Set-Location $OutputDir
|
||||
tar -czf "${OutputName}.tar.gz" $OutputName
|
||||
Remove-Item -Recurse -Force $OutputName
|
||||
Set-Location $CurrentDir
|
||||
|
||||
Write-Host " $OS/$Arch 打包完成: ${OutputName}.tar.gz"
|
||||
} else {
|
||||
Write-Host " $OS/$Arch 编译失败"
|
||||
if (Test-Path $PackageDir) {
|
||||
Remove-Item -Recurse -Force $PackageDir
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "----------------------------------------"
|
||||
Write-Host "多平台打包完成!输出目录: $OutputDir"
|
||||
Get-ChildItem -Recurse $OutputDir
|
||||
Reference in New Issue
Block a user