1 $ErrorActionPreference='Stop'
2 trap {
3     write-error $_
4     exit 1
5 }
6 
7 $env:GOPATH = Join-Path -Path $PWD "gopath"
8 $env:PATH = $env:GOPATH + "/bin;C:/go/bin;C:/var/vcap/bosh/bin;" + $env:PATH
9 
10 cd $env:GOPATH/src/github.com/cloudfoundry/gosigar
11 
NeedsToInstallGo()12 function NeedsToInstallGo() {
13     Write-Host "Checking if Go needs to be installed or updated..."
14     if ((Get-Command 'go.exe' -ErrorAction SilentlyContinue) -eq $null) {
15         Write-Host "Go.exe not found, Go will be installed"
16         return $true
17     }
18     $version = "$(go.exe version)"
19     if ($version -match 'go version go1\.[1-7]\.\d windows\/amd64') {
20         Write-Host "Installed version of Go is not supported, Go will be updated"
21         return $true
22     }
23     Write-Host "Found Go version '$version' installed on the system, skipping install"
24     return $false
25 }
26 
27 if (NeedsToInstallGo) {
28     Write-Host "Installing Go 1.8.3"
29 
30     Invoke-WebRequest 'https://storage.googleapis.com/golang/go1.8.3.windows-amd64.msi' `
31         -UseBasicParsing -OutFile go.msi
32 
33     $p = Start-Process -FilePath "msiexec" `
34         -ArgumentList "/passive /norestart /i go.msi" `
35         -Wait -PassThru
36     if ($p.ExitCode -ne 0) {
37         throw "Golang MSI installation process returned error code: $($p.ExitCode)"
38     }
39 
40     Write-Host "Successfully installed go version: $(go version)"
41 }
42 
43 go.exe install github.com/cloudfoundry/gosigar/vendor/github.com/onsi/ginkgo/ginkgo
44 if ($LASTEXITCODE -ne 0) {
45     Write-Host "Error installing ginkgo"
46     Write-Error $_
47     exit 1
48 }
49 
50 ginkgo.exe -r -race -keepGoing -skipPackage=psnotify
51 if ($LASTEXITCODE -ne 0) {
52     Write-Host "Gingko returned non-zero exit code: $LASTEXITCODE"
53     Write-Error $_
54     exit 1
55 }
56