generated from pulumi/pulumi-provider-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
68 lines (57 loc) · 1.96 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
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[ValidateSet("Release", "Debug", IgnoreCase = $false)]
[string]$Configuration = "Release"
)
$ErrorActionPreference = "Stop"
if ($Configuration -eq "Debug") {
$gcflags = @(-gcflags '-N -l')
}
$artifacts = Join-Path $PSScriptRoot "artifacts"
if (!(Test-Path $artifacts)) {
New-Item $artifacts -Type Directory | Out-Null
}
Write-Host "Building Go tools..."
go build -o $artifacts @gcflags `
(Join-Path $PSScriptRoot "cmd\pulumi-resource-knapcode") `
(Join-Path $PSScriptRoot "cmd\pulumi-sdkgen-knapcode")
if ($LASTEXITCODE) { throw "go build failed." }
Write-Host ""
Write-Host "Deleting current SDK..."
$sdk = (Join-Path $PSScriptRoot "sdk")
if (Test-Path $sdk) {
Remove-Item $sdk -Recurse -Force
}
Write-Host ""
Write-Host "Generating SDK..."
$schema = Join-Path $PSScriptRoot "schema.json"
$output = "first run"
while ($output) {
$output = & (Join-Path $artifacts "pulumi-sdkgen-knapcode") $schema $sdk
}
Write-Host ""
Write-Host "Reading version..."
$schemaJson = Get-Content $schema | ConvertFrom-Json
$version = $schemaJson.version
Write-Host ""
Write-Host "Setting dotnet version.txt..."
$version | Set-Content (Join-Path $sdk "dotnet\version.txt") -Encoding ASCII
Write-Host ""
Write-Host "Setting version.go..."
$versionGoPath = Join-Path $PSScriptRoot "pkg\version\version.go"
$versionGo = Get-Content $versionGoPath
$versionGo = $versionGo -replace 'var Version string = "[^"]+"', "var Version string = `"$version`""
$versionGo | Set-Content $versionGoPath -Encoding ASCII
Write-Host ""
Write-Host "Building NuGet package ..."
dotnet build (Join-Path $sdk "dotnet\Pulumi.Knapcode.csproj") `
"/p:Version=$version" `
"/p:PackageOutputPath=$artifacts" `
-c $Configuration
Write-Host ""
Write-Host "Compressing provider plugin..."
tar -C $artifacts `
-cvzf `
(Join-Path $artifacts "pulumi-resource-knapcode-v$version-windows-amd64.tar.gz") `
"pulumi-resource-knapcode.exe"