-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-release.ps1
45 lines (37 loc) · 1.09 KB
/
build-release.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Parameters
$AppName = "m3u8"
$Version = "v1.0.0"
$OutputDir = "release"
$MainPath = ".\cmd\m3u8"
# Target platforms
$Platforms = @(
"linux/amd64",
"linux/arm64",
"windows/amd64",
"darwin/amd64",
"darwin/arm64"
)
# Create release directory
New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null
foreach ($Platform in $Platforms) {
$Parts = $Platform -split '/'
$GOOS = $Parts[0]
$GOARCH = $Parts[1]
# Set output file name
$OutputName = "$AppName-$Version-$GOOS-$GOARCH"
if ($GOOS -eq "windows") {
$OutputName += ".exe"
}
New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null
# Build the binary
Write-Host "Building for $GOOS/$GOARCH..."
$env:GOOS = $GOOS
$env:GOARCH = $GOARCH
$CurrentDir = (Get-Location).Path
& go build -C $CurrentDir -o (Join-Path $OutputDir $OutputName) -ldflags "-s -X main.version=$Version" $MainPath
if ($LASTEXITCODE -ne 0) {
Write-Error "Build failed for $GOOS/$GOARCH"
continue
}
}
Write-Host "Build complete. Files are in the '$OutputDir' directory."