-
Notifications
You must be signed in to change notification settings - Fork 79
/
build.ps1
59 lines (48 loc) · 1.54 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function BuildVariants {
param (
$builder,
$ldflags,
$compileflags,
$prefix,
$arch,
$os,
$path
)
foreach ($currentarch in $arch) {
foreach ($currentos in $os) {
$env:GOARCH = $currentarch
$env:GOOS = $currentos
# More sensible naming for x64
$namearch = $currentarch
if ($namearch -eq "amd64") {
$namearch = "x64"
}
$outputfile = "binaries/$prefix-$currentos-$namearch"
if ($currentos -eq "windows") {
$outputfile += ".exe"
}
go build -ldflags "$ldflags" -o $outputfile $compileflags $path
$outputfile = "binaries/$prefix-$currentos-$namearch-obfuscated"
if ($currentos -eq "windows") {
$outputfile += ".exe"
}
garble -seed=random -tiny -literals build -ldflags "$ldflags" -o $outputfile $compileflags $path
if (Get-Command "cyclonedx-gomod" -ErrorAction SilentlyContinue)
{
cyclonedx-gomod app -json -licenses -output $outputfile.bom.json -main $path .
}
}
}
}
Set-Location $PSScriptRoot
$COMMIT = git rev-parse --short HEAD
$VERSION = git describe --tags --exclude latest --exclude devbuild
$DIRTYFILES = git status --porcelain
$BUILDER = "go"
if ("$DIRTYFILES" -ne "") {
$VERSION = "$VERSION-local-changes"
}
Write-Output "Building $VERSION"
$LDFLAGS = "-X main.Version=$VERSION"
# Release
BuildVariants -ldflags "$LDFLAGS -s" -prefix ldapnomnom -path . -arch @("386", "amd64", "arm64") -os @("windows", "darwin", "linux")