This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
build.ps1
81 lines (64 loc) · 2.1 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function Zip-Release {
param (
[string]$sourceDir,
[string]$destFile
)
# While we could use zipfile from system.io.compression.filesystem, this
# uses Windows-style path separators all the time! Fixed in CLR 4.6.1 but
# default Powershell can't access this, PITA. Let's just use the 7z command
$tempdest = [System.IO.Path]::GetTempPath() + [System.IO.Path]::GetRandomFileName() + ".zip"
$zipargs = "a `"$tempdest`" $sourcedir\*"
try {
7z a "$tempdest" "$sourcedir\*" | Out-Null
}
catch {
Remove-Item $tempdest -Force
throw
}
# If successful, move into final location
if (Test-Path $destFile) {
Remove-item $destFile
}
Move-Item $tempdest $destFile
}
$package = "github.com/sinbad/lfs-folderstore"
$archivename = "lfs-folderstore"
# Check dirty repo
git diff --no-patch --exit-code
if ($LASTEXITCODE -ne 0) {
Write-Output "Working copy is not clean (unstaged changes)"
Exit $LASTEXITCODE
}
git diff --no-patch --cached --exit-code
if ($LASTEXITCODE -ne 0) {
Write-Output "Working copy is not clean (staged changes)"
Exit $LASTEXITCODE
}
# Check that the latest tag is present directly on HEAD
$Version = (git describe --exact-match | Out-String).Trim()
if ($LASTEXITCODE -ne 0) {
Write-Output "No version tag on HEAD"
Exit $LASTEXITCODE
}
Write-Output "Building version: $Version"
$BuildConfigs = @{
"windows" = @("amd64", "386");
"linux" = @("amd64", "386");
"darwin" = @("amd64");
}
foreach ($BuildOS in $BuildConfigs.GetEnumerator()) {
foreach ($Arch in $BuildOS.Value) {
Write-Output "- $($BuildOS.Name):$Arch"
$outputdir = "$archivename-$($BuildOS.Name)-$Arch"
mkdir -Force $outputdir | Out-Null
Push-Location $outputdir
$env:GOOS=$($BuildOS.Name)
$env:GOARCH=$Arch
go build -ldflags "-X $package/cmd.Version=$Version" $package
Pop-Location
$zipname = "$outputdir-$Version.zip"
Zip-Release $outputdir $zipname
Remove-Item -Force -Recurse $outputdir
Write-Output " Done: $zipname"
}
}