/
build-new.ps1
139 lines (108 loc) · 5 KB
/
build-new.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
132
133
134
135
136
137
138
139
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$configuration = "Release"
$nuspecDir = Join-Path $scriptPath "NuSpecs"
$isAppVeyor = Test-Path -Path env:\APPVEYOR
$outputLocation = Join-Path $scriptPath "testResults"
$signClientSettings = Join-Path (Join-Path (Get-Item $scriptPath).Parent.Parent.FullName "scripts") "SignClientSettings.json"
$hasSignClientSecret = !([string]::IsNullOrEmpty($env:SignClientSecret))
$signClientAppPath = Join-Path (Join-Path (Join-Path .\Packages "SignClient") "Tools") "SignClient.dll"
#remove any old coverage file
md -Force $outputLocation | Out-Null
$outputPath = (Resolve-Path $outputLocation).Path
$outputFile = Join-Path $outputPath -childpath 'coverage-ix.xml'
Remove-Item $outputPath -Force -Recurse
md -Force $outputLocation | Out-Null
if (!(Test-Path .\nuget.exe)) {
wget "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -outfile .\nuget.exe
}
$msbuild = Get-ItemProperty "hklm:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0"
# TODO: if not found, bail out
$msbuildExe = Join-Path $msbuild.MSBuildToolsPath "msbuild.exe"
# get tools
.\nuget.exe install -excludeversion gitversion.commandline -outputdirectory packages
.\nuget.exe install -excludeversion SignClient -Version 0.5.0-beta3 -pre -outputdirectory packages
.\nuget.exe install -excludeversion OpenCover -outputdirectory packages
.\nuget.exe install -excludeversion ReportGenerator -outputdirectory packages
.\nuget.exe install -excludeversion coveralls.io -outputdirectory packages
#update version
.\packages\gitversion.commandline\tools\gitversion.exe /l console /output buildserver /updateassemblyinfo
$versionObj = .\packages\gitversion.commandline\tools\gitversion.exe | ConvertFrom-Json
$version = $versionObj.MajorMinorPatch
$tag = $versionObj.PreReleaseLabel
$preRelNum = $versionObj.CommitsSinceVersionSourcePadded
if($tag -ne ""){
if($preRelNum -ne "00000") {
$version = "$version-$tag-$preRelNum"
}
else {
$version = "$version-$tag"
}
}
Write-Host "Version: $version"
Write-Host "Restoring packages" -Foreground Green
dotnet restore $scriptPath | out-null
Write-Host "Building projects" -Foreground Green
$projects = gci $scriptPath -Directory `
| Where-Object { ($_.Name -notlike "*DeviceRunner") -and (Test-Path (Join-Path $_.FullName "project.json")) } `
foreach ($project in $projects) {
dotnet build -c "$configuration" $project.FullName
if ($LastExitCode -ne 0) {
Write-Host "Error building project $project" -Foreground Red
if($isAppVeyor) {
$host.SetShouldExit($LastExitCode)
}
}
}
Write-Host "Building Packages" -Foreground Green
$nuspecs = ls $nuspecDir\*.nuspec | Select -ExpandProperty FullName
New-Item -ItemType Directory -Force -Path .\artifacts
foreach ($nuspec in $nuspecs) {
.\nuget pack $nuspec -symbols -Version $version -Properties "Configuration=$configuration" -MinClientVersion 2.12 -outputdirectory .\artifacts
if ($LastExitCode -ne 0) {
Write-Host "Error packing NuGet $nuspec" -Foreground Red
if($isAppVeyor) {
$host.SetShouldExit($LastExitCode)
}
}
}
if($hasSignClientSecret) {
Write-Host "Signing Packages" -Foreground Green
$nupgks = ls .\artifacts\*Interact*.nupkg | Select -ExpandProperty FullName
foreach ($nupkg in $nupgks) {
Write-Host "Submitting $nupkg for signing"
dotnet $signClientAppPath 'zip' -c $signClientSettings -i $nupkg -s $env:SignClientSecret -n 'Ix.NET' -d 'Interactive Extensions for .NET' -u 'http://reactivex.io/'
if ($LastExitCode -ne 0) {
Write-Host "Error signing $nupkg" -Foreground Red
if($isAppVeyor) {
$host.SetShouldExit($LastExitCode)
}
}
Write-Host "Finished signing $nupkg"
}
} else {
Write-Host "Client Secret not found, not signing packages"
}
Write-Host "Running tests" -Foreground Green
$testDirectory = Join-Path $scriptPath "Tests"
# Execute OpenCover with a target of "dotnet test"
.\packages\OpenCover\tools\OpenCover.Console.exe -register:user -oldStyle -mergeoutput -target:dotnet.exe -targetdir:"$testDirectory" -targetargs:"test $testDirectory -c $configuration -notrait SkipCI=true" -output:"$outputFile" -skipautoprops -returntargetcode "-excludebyattribute:System.Diagnostics.DebuggerNonUserCodeAttribute;System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute" -nodefaultfilters -hideskipped:All -filter:"+[*]* -[*.Tests]* -[Tests]* -[xunit.*]* -[FluentAssertions.*]* -[FluentAssertions]*"
if ($LastExitCode -ne 0) {
Write-Host "Error with tests" -Foreground Red
if($isAppVeyor) {
$host.SetShouldExit($LastExitCode)
}
}
# Either display or publish the results
if ($env:CI -eq 'True')
{
.\packages\coveralls.io\tools\coveralls.net.exe --opencover "$outputFile" --full-sources
}
else
{
.\packages\ReportGenerator\tools\ReportGenerator.exe -reports:"$outputFile" -targetdir:"$outputPath"
&$outPutPath/index.htm
}
if ($env:CI -ne 'True') {
Write-Host "Reverting AssemblyInfo's" -Foreground Green
gci $scriptPath -re -in AssemblyInfo.cs | %{ git checkout $_ }
}