forked from antonjefcoate/JustSaying-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.ps1
169 lines (139 loc) · 5.99 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
param(
[Parameter(Mandatory = $false)][string] $Configuration = "Release",
[Parameter(Mandatory = $false)][string] $VersionSuffix = "",
[Parameter(Mandatory = $false)][string] $OutputPath = "",
[Parameter(Mandatory = $false)][switch] $SkipTests,
[Parameter(Mandatory = $false)][switch] $DisableCodeCoverage,
[Parameter(Mandatory = $false)][switch] $EnableIntegrationTests
)
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
$solutionPath = Split-Path $MyInvocation.MyCommand.Definition
$sdkFile = Join-Path $solutionPath "global.json"
$libraryProjects = @(
(Join-Path $solutionPath "JustSaying\JustSaying.csproj"),
(Join-Path $solutionPath "JustSaying.Models\JustSaying.Models.csproj"),
(Join-Path $solutionPath "JustSaying.Extensions.DependencyInjection.Microsoft\JustSaying.Extensions.DependencyInjection.Microsoft.csproj"),
(Join-Path $solutionPath "JustSaying.Extensions.DependencyInjection.StructureMap\JustSaying.Extensions.DependencyInjection.StructureMap.csproj")
)
$testProjects = @(
(Join-Path $solutionPath "JustSaying.UnitTests\JustSaying.UnitTests.csproj")
)
if ($EnableIntegrationTests -eq $true) {
$testProjects += (Join-Path $solutionPath "JustSaying.IntegrationTests\JustSaying.IntegrationTests.csproj");
}
$dotnetVersion = (Get-Content $sdkFile | Out-String | ConvertFrom-Json).sdk.version
if ($OutputPath -eq "") {
$OutputPath = Join-Path "$(Convert-Path "$PSScriptRoot")" "artifacts"
}
if ($null -ne $env:CI) {
if (($VersionSuffix -eq "" -and $env:APPVEYOR_REPO_TAG -eq "false" -and $env:APPVEYOR_BUILD_NUMBER -ne "") -eq $true) {
$ThisVersion = $env:APPVEYOR_BUILD_NUMBER -as [int]
$VersionSuffix = "beta" + $ThisVersion.ToString("0000")
}
}
$installDotNetSdk = $false;
if (($null -eq (Get-Command "dotnet.exe" -ErrorAction SilentlyContinue)) -and ($null -eq (Get-Command "dotnet" -ErrorAction SilentlyContinue))) {
Write-Host "The .NET Core SDK is not installed."
$installDotNetSdk = $true
}
else {
Try {
$installedDotNetVersion = (dotnet --version 2>&1 | Out-String).Trim()
}
Catch {
$installedDotNetVersion = "?"
}
if ($installedDotNetVersion -ne $dotnetVersion) {
Write-Host "The required version of the .NET Core SDK is not installed. Expected $dotnetVersion."
$installDotNetSdk = $true
}
}
if ($installDotNetSdk -eq $true) {
$env:DOTNET_INSTALL_DIR = Join-Path "$(Convert-Path "$PSScriptRoot")" ".dotnetcli"
$sdkPath = Join-Path $env:DOTNET_INSTALL_DIR "sdk\$dotnetVersion"
if (!(Test-Path $sdkPath)) {
if (!(Test-Path $env:DOTNET_INSTALL_DIR)) {
mkdir $env:DOTNET_INSTALL_DIR | Out-Null
}
$installScript = Join-Path $env:DOTNET_INSTALL_DIR "install.ps1"
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor "Tls12"
Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile $installScript -UseBasicParsing
& $installScript -Version "$dotnetVersion" -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath
}
$env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH"
$dotnet = Join-Path "$env:DOTNET_INSTALL_DIR" "dotnet.exe"
}
else {
$dotnet = "dotnet"
}
function DotNetPack {
param([string]$Project)
if ($VersionSuffix) {
& $dotnet pack $Project --output $OutputPath --configuration $Configuration --version-suffix "$VersionSuffix"
}
else {
& $dotnet pack $Project --output $OutputPath --configuration $Configuration
}
if ($LASTEXITCODE -ne 0) {
throw "dotnet pack failed with exit code $LASTEXITCODE"
}
}
function DotNetTest {
param([string]$Project)
if ($DisableCodeCoverage -eq $true) {
& $dotnet test $Project --output $OutputPath
}
else {
if ($installDotNetSdk -eq $true) {
$dotnetPath = $dotnet
}
else {
$dotnetPath = (Get-Command "dotnet.exe").Source
}
$nugetPath = Join-Path $env:USERPROFILE ".nuget\packages"
$propsFile = Join-Path $solutionPath "Directory.Build.props"
$openCoverVersion = (Select-Xml -Path $propsFile -XPath "//PackageReference[@Include='OpenCover']/@Version").Node.'#text'
$openCoverPath = Join-Path $nugetPath "OpenCover\$openCoverVersion\tools\OpenCover.Console.exe"
$reportGeneratorVersion = (Select-Xml -Path $propsFile -XPath "//PackageReference[@Include='ReportGenerator']/@Version").Node.'#text'
$reportGeneratorPath = Join-Path $nugetPath "ReportGenerator\$reportGeneratorVersion\tools\netcoreapp2.0\ReportGenerator.dll"
$coverageOutput = Join-Path $OutputPath "code-coverage.xml"
$reportOutput = Join-Path $OutputPath "coverage"
& $openCoverPath `
`"-target:$dotnetPath`" `
`"-targetargs:test $Project --output $OutputPath`" `
-output:$coverageOutput `
`"-excludebyattribute:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage*`" `
-hideskipped:All `
-mergebyhash `
-mergeoutput `
-oldstyle `
-register:user `
-skipautoprops `
`"-filter:+[JustSaying]* -[*Test*]*`"
& $dotnet `
$reportGeneratorPath `
`"-reports:$coverageOutput`" `
`"-targetdir:$reportOutput`" `
-reporttypes:HTML`;Cobertura `
-verbosity:Warning
}
if ($LASTEXITCODE -ne 0) {
throw "dotnet test failed with exit code $LASTEXITCODE"
}
}
Write-Host "Creating packages..." -ForegroundColor Green
ForEach ($libraryProject in $libraryProjects) {
DotNetPack $libraryProject
}
if (($null -ne $env:CI) -And ($EnableIntegrationTests -eq $true)) {
& docker pull pafortin/goaws
& docker run -d --name goaws -p 4100:4100 pafortin/goaws
$env:AWS_SERVICE_URL = "http://localhost:4100"
}
if ($SkipTests -eq $false) {
Write-Host "Running tests..." -ForegroundColor Green
ForEach ($testProject in $testProjects) {
DotNetTest $testProject
}
}