This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.ps1
86 lines (73 loc) · 2.05 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
82
83
84
85
86
param(
[string]
[Parameter(Mandatory = $True)]
[ValidateNotNullorEmpty()]
[ValidatePattern('^([0-9]|[1-9][0-9]*)\.([0-9]|[1-9][0-9]*)\.([0-9]|[1-9][0-9]*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$')]
$version,
[switch]
$clean
)
function Clear-Artifacts
{
Write-Host "Cleaning old build products."
Remove-Item * -Include bittray.exe, bittray-*.zip
if (!$?)
{
Write-Host -BackgroundColor red -ForegroundColor white "Failed to remove existing artifacts; see above."
exit 1
}
}
if ($clean -eq $True)
{
Clear-Artifacts
exit 0
}
if ($null -eq (Get-Command "rcedit-x64.exe" -ErrorAction SilentlyContinue))
{
Write-Host -ForegroundColor red "Unable to find rcedit-x64.exe in your PATH."
exit 1
}
Write-Host "Packing bittray version $version" -ForegroundColor green
Clear-Artifacts
Write-Host "go get..."
go get
Write-Host "go vet..."
go vet ./...
if (!$?)
{
Write-Host -BackgroundColor red -ForegroundColor white "'go vet' failed; see above."
exit 1
}
Write-Host "Applying rsrc metadata..."
rsrc -manifest .\bittray.exe.manifest -ico .\bitbucket.ico -arch amd64
Write-Host "go build..."
go build -ldflags="-H=windowsgui"
if (!$?)
{
Write-Host -BackgroundColor red -ForegroundColor white "'go build' failed; see above."
exit 1
}
Write-Host "Validating artifact..."
if (!(Test-Path "bittray.exe" -PathType Leaf))
{
Write-Host -BackgroundColor red -ForegroundColor white "'go build' claims to have succeeded, but there is no artifact?"
exit 1
}
$package = "bittray-$version.zip"
Write-Host "Compressing archive ($package)..."
Compress-Archive -Path .\bittray.exe -CompressionLevel Optimal -DestinationPath $package
if (!$?)
{
Write-Host -BackgroundColor red -ForegroundColor white "Failed to create zip package."
exit 1
}
certUtil -hashfile "$package" sha1
if (!$?)
{
Write-Host -BackgroundColor red -ForegroundColor white "Failed to generate SHA1 integrity checksum."
exit 1
}
else
{
Write-Host -BackgroundColor green -ForegroundColor white "Done!"
}