-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathbuild.ps1
67 lines (51 loc) · 2.2 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
[CmdletBinding()]
Param(
[switch] $generateProtos
)
$ErrorActionPreference = "Stop"
function Exec {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, Position = 0)][scriptblock]$Command,
[Parameter(Mandatory = $false, Position = 1)][string]$ErrorMessage = ("Failed executing {0}" -F $Command)
)
. $Command
if ($LASTEXITCODE -ne 0) {
throw ("Exec: " + $ErrorMessage)
}
}
$protobufVersion = "26.0"
$protocTarball = "protoc-$protobufVersion-win64.zip"
$protocUrl = "https://github.com/protocolbuffers/protobuf/releases/download/v$protobufVersion/$protocTarball"
go version
# Required tools
New-Item -Path . -Name "tools" -ItemType "directory" -Force | Out-Null
Push-Location tools
if (-not (Test-Path -LiteralPath "protobuf")) {
Write-Host "Installing protoc $protobufVersion locally..."
Invoke-WebRequest -Uri $protocUrl -OutFile $protocTarball
Expand-Archive -LiteralPath $protocTarball -DestinationPath "protobuf" -Force
Remove-Item $protocTarball
Write-Host "done."
}
Pop-Location
# end
if ($generateProtos) {
Exec { go install google.golang.org/protobuf/cmd/protoc-gen-go@latest } "Cannot run go command"
Exec { go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest } "Cannot run go command"
# We don't check the env variables because Github actions don't set $GOPATH.
$gopath = Exec { go env GOPATH } "Cannot get $$GOPATH"
Write-Host "Generating gRPC code..."
Get-ChildItem -Path "protos\*.proto" | ForEach-Object {
$file = Get-ChildItem $_
$baseName = $file.BaseName
Write-Host "Compiling $baseName.proto ..."
New-Item -Path .\protos -Name $baseName -ItemType "directory" -Force | Out-Null
Exec { tools\protobuf\bin\protoc --proto_path=$pwd\protos --go_out=.\protos\$baseName --go-grpc_out=.\protos\$baseName --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --plugin=protoc-gen-go=$gopath\bin\protoc-gen-go.exe --plugin=protoc-gen-go-grpc=$gopath\bin\protoc-gen-go-grpc.exe $file } "Cannot run protoc"
Write-Host "done."
}
Write-Host "Code generation completed."
}
Write-Host "Compiling project..."
go build -v .\esdb .\samples
Write-Host "done."