forked from newrelic/nri-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin_build.ps1
131 lines (99 loc) · 2.89 KB
/
win_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<#
.SYNOPSIS
This script verifies, tests, builds and packages a New Relic Infrastructure Integration
#>
param (
# Target architecture: amd64 (default) or 386
[ValidateSet("amd64", "386")]
[string]$arch="amd64",
[string]$version="0.0.0",
# Creates a signed installer
[switch]$installer=$false,
# Skip tests
[switch]$skipTests=$false
)
$integration = $(Split-Path -Leaf $PSScriptRoot)
$integrationName = $integration.Replace("nri-", "")
$executable = "nri-$integrationName.exe"
# verifying version number format
$v = $version.Split(".")
if ($v.Length -ne 3) {
echo "-version must follow a numeric major.minor.patch semantic versioning schema (received: $version)"
exit -1
}
$wrong = $v | ? { (-Not [System.Int32]::TryParse($_, [ref]0)) -or ( $_.Length -eq 0) -or ([int]$_ -lt 0)} | % { 1 }
if ($wrong.Length -ne 0) {
echo "-version major, minor and patch must be valid positive integers (received: $version)"
exit -1
}
echo "--- Configuring version $version for artifacts"
.\windows_set_version.ps1 -major $v[0] -minor $v[1] -patch $v[2]
echo "--- Checking dependencies"
echo "Checking Go..."
go version
if (-not $?)
{
echo "Can't find Go"
exit -1
}
echo "Checking MSBuild.exe..."
$msBuild = (Get-ItemProperty hklm:\software\Microsoft\MSBuild\ToolsVersions\4.0).MSBuildToolsPath
if ($msBuild.Length -eq 0) {
echo "Can't find MSBuild tool. .NET Framework 4.0.x must be installed"
exit -1
}
echo $msBuild
$env:GOOS="windows"
$env:GOARCH=$arch
echo "--- Collecting files"
$goFiles = go list ./...
echo "--- Format check"
$wrongFormat = go fmt $goFiles
if ($wrongFormat -and ($wrongFormat.Length -gt 0))
{
echo "ERROR: Wrong format for files:"
echo $wrongFormat
exit -1
}
if (-Not $skipTests) {
echo "--- Running tests"
go test $goFiles
if (-not $?)
{
echo "Failed running tests"
exit -1
}
}
echo "--- Running Build"
go build -v $goFiles
if (-not $?)
{
echo "Failed building files"
exit -1
}
echo "--- Collecting Go main files"
$packages = go list -f "{{.ImportPath}} {{.Name}}" ./... | ConvertFrom-String -PropertyNames Path, Name
$mainPackage = $packages | ? { $_.Name -eq 'main' } | % { $_.Path }
echo "generating $integrationName"
go generate $mainPackage
$fileName = ([io.fileinfo]$mainPackage).BaseName
echo "creating $executable"
go build -ldflags "-X main.buildVersion=$version" -o ".\target\bin\windows_$arch\$executable" $mainPackage
If (-Not $installer) {
exit 0
}
echo "--- Building Installer"
Push-Location -Path "pkg\windows\nri-$arch-installer"
$env:integration = $integration
. $msBuild/MSBuild.exe nri-installer.wixproj
if (-not $?)
{
echo "Failed building installer"
Pop-Location
exit -1
}
echo "Making versioned installed copy"
cd bin\Release
cp "$integration-$arch.msi" "$integration-$arch.$version.msi"
cp "$integration-$arch.msi" "$integration.msi"
Pop-Location