-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathbuild.ps1
89 lines (70 loc) · 1.83 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
87
88
89
### Build Script
param(
[switch]
$Publish,
[string]
$NuGetApiKey
)
$VersionPrefix = "1"
$VersionSuffix = "0.0.0"
$SlnPath = "src\Parquet.sln"
$AssemblyVersion = "$VersionPrefix.0.0.0"
$PackageVersion = "$VersionPrefix.$VersionSuffix"
Write-Host "version: $PackageVersion, assembly version: $AssemblyVersion"
function Set-VstsBuildNumber($BuildNumber)
{
Write-Verbose -Verbose "##vso[build.updatebuildnumber]$BuildNumber"
}
function Update-ProjectVersion([string]$RelPath)
{
$xml = [xml](Get-Content "$PSScriptRoot\$RelPath")
if($xml.Project.PropertyGroup.Count -eq $null)
{
$pg = $xml.Project.PropertyGroup
}
else
{
$pg = $xml.Project.PropertyGroup[0]
}
$pg.Version = $PackageVersion
$pg.FileVersion = $PackageVersion
$pg.AssemblyVersion = $AssemblyVersion
$xml.Save("$PSScriptRoot\$RelPath")
}
function Exec($Command)
{
Invoke-Expression $Command
if($LASTEXITCODE -ne 0)
{
Write-Error "command failed (error code: $LASTEXITCODE)"
exit 1
}
}
### Start the build
# General validation
if($Publish -and (-not $NuGetApiKey))
{
Write-Error "Please specify nuget key to publish"
exit 1
}
# Update version numbers
Set-VstsBuildNumber $PackageVersion
Update-ProjectVersion "src\Parquet\Parquet.csproj"
# Restore packages
Exec "dotnet restore $SlnPath"
# Build solution
Get-ChildItem *.nupkg -Recurse | Remove-Item -ErrorAction Ignore
Exec "dotnet build $SlnPath -c release"
# Run the tests
Exec "dotnet test src\Parquet.Test\Parquet.Test.csproj"
# publish the nugets
if($Publish.IsPresent)
{
Write-Host "publishing nugets..."
Get-ChildItem *.nupkg -Recurse | % {
$path = $_.FullName
Write-Host "publishing from $path"
Exec "nuget push $path -Source https://www.nuget.org/api/v2/package -ApiKey $NuGetApiKey"
}
}
Write-Host "build succeeded."