-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.ps1
58 lines (46 loc) · 1.84 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
# Enables simple cross-compilation and packaging of Go applications via Windows.
#
# Author: Matthew Hartstonge
# Written: 2017-10-12
# Creates binaries packaged and ready to go in a distibution folder
function main() {
$operatingSystems = ("windows", "darwin", "linux", "openbsd", "freebsd", "solaris")
$architechtures = ("amd64")
$packagePath = "github.com\MatthewHartstonge\b64secrets"
$appName = "b64secrets"
$distPath = "./dist"
# Obtain the version from the user. A.K.A: "don't piss around trying to understand what you think the user wants via Git, just ask..."
$version = Read-Host -Prompt "Enter release version: "
# Create dist directory, assuming it doesn't already exist
$distPathExists = Test-Path $distPath
if (!$distPathExists) {
New-Item -Path "./dist" -ItemType "directory"
}
foreach ($os in $operatingSystems) {
foreach ($arch in $architechtures) {
# Build that fabulous idea
$binaryFp = buildGoApp -OS $os -Arch $arch -AppName $appName -PackagePath $packagePath -DestinationPath $distPath
# zip that sucker
$zipName = "$appname-$version-$os-$arch"
zipFile -FilePath $binaryFp -Destination $distPath -FileName $zipName
# Make sure to clean up after yourself
Remove-Item -Path $binaryFp
}
}
}
# buildGoApp creates a go binary in DestinationPath
function buildGoApp($OS, $Arch, $AppName, $PackagePath, $DestinationPath) {
$env:GOOS = $OS
$env:GOARCH = $Arch
$out = $DestinationPath + "/" + $AppName
if ($os -eq "windows") {
$out = $out + ".exe"
}
go build -o $out $PackagePath
return $out
}
# zipFile will create a zip of a given file, and give it the provided name.
function zipFile($FilePath, $Destination, $FileName) {
Compress-Archive -Path $FilePath -CompressionLevel "Optimal" -DestinationPath "$Destination/$FileName.zip"
}
main