-
Notifications
You must be signed in to change notification settings - Fork 39
/
build.ps1
42 lines (34 loc) · 1.07 KB
/
build.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
# Parameters
$targets = "darwin", "linux", "windows"
$archs = "amd64", "arm64"
$appName = "tlm"
# Command-Line Version Argument
$version = $args[0]
if (-not $version) {
Write-Output "Error: Please provide a version number as a command-line argument."
exit 1
}
# Housekeeping
Remove-Item -Recurse -Force "dist" -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path "dist"
# Build Function (Helper)
Function Build-Target($os, $version, $arch) {
$outputName = "${appName}_${version}_${os}_${arch}"
$sha1 = (git rev-parse --short HEAD).Trim()
if ($os -eq "windows") {
$outputName += ".exe"
}
Write-Output "Building for $os/$arch (version: $version) -> $outputName"
# Invokes the Go toolchain (assumes it's in the PATH)
go build -o "dist/$version/$outputName" -ldflags "-X main.sha1ver=$sha1" "main.go"
}
# Build for each target OS
foreach ($os in $targets) {
foreach ($arch in $archs) {
$env:GOOS = $os
$env:GOARCH = $arch
$env:CGO_ENABLED = 0
Build-Target $os $version $arch
}
}
Write-Output "Done!"