-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathpsakefile.ps1
264 lines (211 loc) · 10.3 KB
/
psakefile.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
properties {
# build variables
$configuration = "Release" # build configuration
$script:version = "0.9.0-unstable0005"
$script:nugetVersion = "0.9.0-unstable0005"
# directories
$base_dir = . resolve-path .\
$project_dir = "$base_dir\src\csmacnz.Coveralls"
$app_project = "$project_dir\csmacnz.Coveralls.csproj"
$build_output_dir = "$base_dir\src\csmacnz.Coveralls\bin\$configuration\"
$build_packages_dir = "$base_dir\BuildPackages\"
$test_results_dir = "$base_dir\TestResults\"
$package_dir = "$base_dir\Package\"
$archive_dir = "$package_dir" + "Archive"
$nuget_pack_dir = "$package_dir" + "Pack"
# files
$sln_file = "$base_dir\csmacnz.Coveralls.sln"
}
Include ".\BuildTools\utils.ps1"
task default
task BootstrapNuget {
BootstrapNuget "nuget" $build_packages_dir
}
task InstallCoverity -depends BootstrapNuget {
InstallNugetPackage "PublishCoverity" 0.11.0 $build_packages_dir
}
task InstallGitVersion -depends BootstrapNuget {
InstallNugetPackage "GitVersion.CommandLine" 5.10.1 $build_packages_dir
}
task InstallReSharperCLI -depends BootstrapNuget {
InstallNugetPackage "JetBrains.ReSharper.CommandLineTools" 2022.1.1 $build_packages_dir
}
task GitVersion -depends InstallGitVersion {
$gitVersion = GetGitVersionPath $build_packages_dir
exec { & $gitVersion /output buildserver /updateassemblyinfo }
$json = (& $gitVersion) | ConvertFrom-Json
$script:version = $json.MajorMinorPatch
$script:nugetVersion = $json.NuGetVersionV2
ProjectVersion "$project_dir" $script:nugetVersion
}
task AppVeyorEnvironmentSettings {
if (Test-Path Env:\GitVersion_ClassicVersion) {
$script:version = $env:GitVersion_ClassicVersion
Write-Output "version set to $script:version"
}
elseif (Test-Path Env:\APPVEYOR_BUILD_VERSION) {
$script:version = $env:APPVEYOR_BUILD_VERSION
Write-Output "version set to $script:version"
}
if (Test-Path Env:\GitVersion_NuGetVersionV2) {
$script:nugetVersion = $env:GitVersion_NuGetVersionV2
Write-Output "nuget version set to $script:nugetVersion"
}
elseif (Test-Path Env:\APPVEYOR_BUILD_VERSION) {
$script:nugetVersion = $env:APPVEYOR_BUILD_VERSION
Write-Output "nuget version set to $script:nugetVersion"
}
}
task clean {
if (Test-Path $package_dir) {
Remove-Item $package_dir -r
}
if (Test-Path $test_results_dir) {
Remove-Item $test_results_dir -r
}
if (Test-Path $build_packages_dir) {
Remove-Item $build_packages_dir -r
}
dotnet clean $sln_file
}
task build {
exec { dotnet build -c $configuration $sln_file }
}
task setup-coverity-local {
$env:APPVEYOR_BUILD_FOLDER = "."
$env:APPVEYOR_BUILD_VERSION = $script:version
$env:APPVEYOR_REPO_NAME = "csMACnz/coveralls.net"
"You should have set the COVERITY_TOKEN and COVERITY_EMAIL environment variable already"
$env:APPVEYOR_SCHEDULED_BUILD = "True"
}
task test-coverity -depends setup-coverity-local, coverity
task coverity -depends InstallCoverity -precondition { return $env:APPVEYOR_SCHEDULED_BUILD -eq "True" } {
$coverityFileName = "coveralls.coverity.$script:nugetVersion.zip"
$PublishCoverity = GetCoverityPath $build_packages_dir
& cov-configure --comptype csc --compiler "C:\Program Files\dotnet\dotnet.exe"
& cov-build --dir cov-int dotnet msbuild "/t:Clean;Build" "/p:Configuration=$configuration" $sln_file
if (-not (Test-Path $test_results_dir)) {
mkdir $test_results_dir
}
& $PublishCoverity compress -o $coverityFileName
& $PublishCoverity publish -t $env:COVERITY_TOKEN -e $env:COVERITY_EMAIL -z $coverityFileName -d "AppVeyor scheduled build ($env:APPVEYOR_BUILD_VERSION)." --codeVersion $script:nugetVersion
}
task unit-test {
dotnet test .\src\csmacnz.Coveralls.Tests\csmacnz.Coveralls.Tests.csproj
}
task coverage -depends build, coverage-only
task coverage-only {
if(-not (Test-Path $test_results_dir)) {
mkdir $test_results_dir
}
$coverageOutputFile = "$test_results_dir\Coverage.xml"
$coverageOutDir = "$test_results_dir\Coverage"
$tag = $script:nugetVersion
$coverageResultsZip = "$package_dir\coveralls.coverageResults.$script:nugetVersion.zip"
if(Test-Path $coverageOutDir) {
Remove-Item $coverageOutDir -r
}
if(Test-Path $coverageResultsZip) {
Remove-Item $coverageResultsZip
}
Set-Location "$base_dir\src\csmacnz.Coveralls.Tests"
exec { dotnet test /p:Configuration=Debug /p:CollectCoverage=true '/p:Include="[csmacnz.Coveralls*]*"' '/p:Exclude="[csmacnz.Coveralls.Tests]AutoGeneratedProgram"' '/p:CoverletOutputFormat=\"json,opencover\"' "/p:CoverletOutput=$coverageOutputFile" } "dotnet test failed"
Set-Location $base_dir
dotnet tool restore
exec { dotnet reportgenerator "-targetdir:$coverageOutDir" "-reports:$coverageOutputFile" "-reportTypes:Html" "-tag:$tag" } "report generator failed"
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory("$coverageOutDir", "$coverageResultsZip")
}
task test-coveralls -depends archive, coverage {
exec { & ".\Package\Archive\windows\csmacnz.Coveralls.exe" --opencover -i "$test_results_dir\Coverage.xml" --useRelativePaths --dryrun -o "$test_results_dir\coverallsTestOutput.json" --repoToken "NOTAREALTOKEN" }
}
task coveralls-only -precondition { return -not $env:APPVEYOR_PULL_REQUEST_NUMBER } {
exec { & ".\Package\Archive\windows\csmacnz.Coveralls.exe" --opencover -i "$test_results_dir\Coverage.xml" --treatUploadErrorsAsWarnings --useRelativePaths}
}
task inspect -depends InstallReSharperCLI {
$inspectcode = GetInspectCodePath $build_packages_dir
echo "$inspectcode"
exec { cmd /c $inspectcode /o="$test_results_dir\resharperReport.xml" $sln_file 2`> nul }
[xml]$stats = Get-Content $test_results_dir\resharperReport.xml
$anyErrors = $FALSE;
$errors = $stats.SelectNodes("/Report/IssueTypes/IssueType")
foreach ($errorType in $errors) {
$errorTypeName = $(Get-Culture).TextInfo.ToTitleCase($errorType.Severity.ToLower())
Write-Host "Found InspectCode $errorTypeName(s): $($errorType.Description)"
$issues = $stats.SelectNodes("/Report/Issues/Project/Issue[@TypeId='$($errorType.Id)']")
foreach ($issue in $issues) {
Write-Host "File: $($issue.File) Line: $($issue.Line) Message: $($issue.Message)"
if (($errorType.Severity -eq "ERROR") -and (Get-Command "Add-AppveyorTest" -errorAction SilentlyContinue)) {
Add-AppveyorTest "Resharper Error: $($errorType.Description) Line: $($issue.Line)" -Outcome Failed -FileName "$($issue.File)" -ErrorMessage "$($issue.Message)"
}
elseif (Get-Command "Add-AppveyorMessage" -errorAction SilentlyContinue) {
if ($errorType.Severity -eq "WARNING") {
Add-AppveyorMessage "Resharper Warning: $($errorType.Description) File: $($issue.File) Line: $($issue.Line)" -Category Warning -Details "$($issue.Message)"
}
else {
Add-AppveyorMessage "Resharper $($errorTypeName): $($errorType.Description) File: $($issue.File) Line: $($issue.Line)" -Category Information -Details "$($issue.Message)"
}
}
}
if ($errorType.Severity -eq "ERROR") {
$anyErrors = $TRUE
}
}
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform
$xslt.Load("$base_dir\BuildTools\resharperReport.xslt")
$xslt.Transform("$test_results_dir\resharperReport.xml", "$test_results_dir\resharperReport.html")
if (Get-Command "Push-AppveyorArtifact" -errorAction SilentlyContinue) {
Push-AppveyorArtifact $test_results_dir\resharperReport.xml
Push-AppveyorArtifact $test_results_dir\resharperReport.html
}
if ($anyErrors -eq $TRUE) {
Write-Host "There are Resharper errors in the solution"
throw "Resharper errors in the solution"
}
}
task archive -depends build, archive-only
task archive-only {
$archive_filename_prefix = "$package_dir\coveralls.net.$script:nugetVersion"
$linux_archive_filename = "$archive_filename_prefix-linux.zip"
$windows_archive_filename = "$archive_filename_prefix-windows.zip"
$osx_archive_filename = "$archive_filename_prefix-osx.zip"
if(Test-Path $archive_dir) {
Remove-Item $archive_dir -r
}
if(Test-Path $linux_archive_filename) {
Remove-Item $linux_archive_filename
}
if(Test-Path $windows_archive_filename) {
Remove-Item $windows_archive_filename
}
if(Test-Path $osx_archive_filename) {
Remove-Item $osx_archive_filename
}
mkdir $archive_dir
dotnet publish $app_project -f net6.0 -c $configuration -o "$archive_dir\windows" -r win-x64 --self-contained -p:PublishSingleFile=true
dotnet publish $app_project -f net6.0 -c $configuration -o "$archive_dir\linux" -r linux-x64 --self-contained -p:PublishSingleFile=true
dotnet publish $app_project -f net6.0 -c $configuration -o "$archive_dir\osx" -r osx-x64 --self-contained -p:PublishSingleFile=true
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory("$archive_dir\windows", $windows_archive_filename)
[io.compression.zipfile]::CreateFromDirectory("$archive_dir\linux", $linux_archive_filename)
[io.compression.zipfile]::CreateFromDirectory("$archive_dir\osx", $osx_archive_filename)
}
task pack -depends build, pack-only
task pack-only {
if(Test-Path $nuget_pack_dir) {
Remove-Item $nuget_pack_dir -r
}
dotnet pack --output $package_dir /p:PackageVersion=$script:nugetVersion
}
task integration {
$env:COVERALLSNET_EXEPATH = ""
dotnet test .\src\csmacnz.Coveralls.Tests.Integration\csmacnz.Coveralls.Tests.Integration.csproj
}
task integration-on-package -depends archive-only {
$env:COVERALLSNET_EXEPATH = "$base_dir\Package\Archive\windows\csmacnz.Coveralls.exe"
dotnet test .\src\csmacnz.Coveralls.Tests.Integration\csmacnz.Coveralls.Tests.Integration.csproj
}
task postbuild -depends archive-only, pack-only, coverage-only, coveralls-only, integration, integration-on-package, inspect
task appveyor-install -depends GitVersion
task appveyor-build -depends build
task appveyor-test -depends AppVeyorEnvironmentSettings, postbuild