-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdefault.ps1
178 lines (138 loc) · 6.02 KB
/
default.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
properties {
# build variables
$configuration = "Release" # build configuration
$script:version = "1.0.0"
$script:nugetVersion = "1.0.0"
$script:runCoverity = $false
# directories
$base_dir = . resolve-path .\
$project_dir = "$base_dir\src\BCLExtensions\"
$test_project_dir = "$base_dir\src\BCLExtensions.Tests\"
$build_output_dir = "$base_dir\src\BCLExtensions\bin\$configuration\"
$test_results_dir = "$base_dir\TestResults\"
$build_packages_dir = "$base_dir\BuildPackages\"
$package_dir = "$base_dir\Package\"
$archive_dir = "$package_dir" + "Archive"
# files
$sln_file = "$base_dir\src\BCLExtensions.sln"
}
Include ".\build\utils.ps1"
task default
task BootstrapNuget {
BootstrapNuget "nuget" $build_packages_dir
}
task RestoreNuGetPackages {
exec { dotnet restore $sln_file }
}
task InstallCoveralls -depends BootstrapNuget {
InstallNugetPackage "coveralls.net" 0.6.0 $build_packages_dir
}
task InstallOpenCover -depends BootstrapNuget {
InstallNugetPackage "OpenCover" 4.6.519 $build_packages_dir
}
task InstallCoverity -depends BootstrapNuget {
InstallNugetPackage "PublishCoverity" 0.11.0 $build_packages_dir
}
task InstallGitVersion -depends BootstrapNuget {
InstallNugetPackage "GitVersion.CommandLine" 3.6.5 $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/BCLExtensions"
"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 = "BCLExtensions.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 "$test_results_dir\$coverityFileName"
& $PublishCoverity publish -t "$env:COVERITY_TOKEN" -e "$env:COVERITY_EMAIL" -z "$test_results_dir\$coverityFileName" -d "AppVeyor scheduled build ($env:APPVEYOR_BUILD_VERSION)." --codeVersion "$script:nugetVersion"
}
task coverage -depends build, coverage-only
task coverage-only -depends InstallOpenCover {
if(-not (Test-Path $test_results_dir)) {
mkdir $test_results_dir
}
$opencover = GetOpenCoverPath $build_packages_dir
exec {
Set-Location $test_project_dir
& $opencover -oldstyle -register:user -target:dotnet.exe "-targetargs:xunit -configuration Debug" -filter:"+[BCLExtensions*]* -[BCLExtensions.Tests]AutoGeneratedProgram" -output:"$test_results_dir\BCLExtensionsCoverage.xml"
Set-Location $base_dir
}
}
task test-coveralls -depends coverage, InstallCoveralls {
$coveralls = GetCoverallsPath $build_packages_dir
exec { & $coveralls --opencover -i "$test_results_dir\BCLExtensionsCoverage.xml" --useRelativePaths --dryrun -o "$test_results_dir\coverallsTestOutput.json" --repoToken "NOTAREALTOKEN" }
}
task coveralls -depends InstallCoveralls -precondition { return -not $env:APPVEYOR_PULL_REQUEST_NUMBER }{
$coveralls = GetCoverallsPath $build_packages_dir
exec { & $coveralls --opencover -i "$test_results_dir\BCLExtensionsCoverage.xml" --useRelativePaths --treatUploadErrorsAsWarnings }
}
task codecov {
(New-Object System.Net.WebClient).DownloadFile("https://codecov.io/bash", ".\CodecovUploader.sh")
.\CodecovUploader.sh -t $env:CODECOV_TOKEN -f "$test_results_dir\BCLExtensionsCoverage.xml"
}
task archive -depends build, archive-only
task archive-only {
$archive_filename = "BCLExtensions.$script:nugetVersion.zip"
mkdir $archive_dir
Copy-Item "$build_output_dir\*" "$archive_dir" -Recurse
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory("$archive_dir", "$package_dir\$archive_filename")
}
task pack -depends build, pack-only
task pack-only {
dotnet pack -c $configuration -o $package_dir ".\src\BCLExtensions\BCLExtensions.csproj"
}
task postbuild -depends pack, archive, coverage-only, codecov, coveralls
task appveyor-install -depends GitVersion, RestoreNuGetPackages
task appveyor-build -depends AppVeyorEnvironmentSettings, build
task appveyor-test -depends AppVeyorEnvironmentSettings, postbuild