Skip to content

Commit 0d59e9b

Browse files
committed
Updated build script
1 parent f8f46ff commit 0d59e9b

File tree

7 files changed

+84
-54
lines changed

7 files changed

+84
-54
lines changed

.appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '{build}'
1+
version: 'Build {build}'
22
image: Visual Studio 2017
33
skip_branch_with_pr: true
44

@@ -8,7 +8,7 @@ install:
88

99

1010
build_script:
11-
- ps: .\build.appveyor.ps1 -IsTagBuild ([System.Convert]::ToBoolean($env:APPVEYOR_REPO_TAG))
11+
- ps: .\build.appveyor.ps1
1212

1313
test: false
1414
artifacts:

.codecov.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
comment: off
2-
ignore:
3-
- "*.ps1"
1+
comment: off

InfinityCrawler.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{F0B4D0
1111
.gitignore = .gitignore
1212
build.appveyor.ps1 = build.appveyor.ps1
1313
build.ps1 = build.ps1
14+
buildconfig.json = buildconfig.json
1415
License.txt = License.txt
1516
README.md = README.md
1617
EndProjectSection

build.appveyor.ps1

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1-
[CmdletBinding(PositionalBinding=$false)]
2-
param(
3-
[bool] $IsTagBuild
4-
)
1+
Write-Host "Initialising AppVeyor build..." -ForegroundColor "Magenta"
52

3+
$baseBuildVersion = git describe --tags --abbrev=0
4+
if ($baseBuildVersion -contains "fatal") {
5+
$baseBuildVersion = "0.0.0"
6+
}
67

7-
Write-Host "Initialising AppVeyor build..." -ForegroundColor "Magenta"
8+
$isTagBuild = $False
9+
$buildMetadata = "$($env:APPVEYOR_REPO_COMMIT.substring(0,7))-$($env:APPVEYOR_BUILD_NUMBER)"
10+
$prereleaseVersion = "dev"
11+
12+
if ($env:APPVEYOR_REPO_TAG -ne "false") {
13+
$baseBuildVersion = $env:APPVEYOR_REPO_TAG_NAME
14+
$prereleaseVersion = $False
15+
$isTagBuild = $True
16+
}
17+
elseif ($env:APPVEYOR_PULL_REQUEST_NUMBER) {
18+
$prereleaseVersion = "PR$($env:APPVEYOR_PULL_REQUEST_NUMBER)"
19+
}
20+
21+
$buildVersion = "$baseBuildVersion+$buildMetadata"
22+
if ($prereleaseVersion) {
23+
$buildVersion = "$baseBuildVersion-$prereleaseVersion+$buildMetadata"
24+
}
25+
26+
Update-AppveyorBuild -Version $buildVersion
827

9-
if ($IsTagBuild) {
10-
.\build.ps1 -CreatePackages $True
28+
if ($isTagBuild) {
29+
.\build.ps1 -CreatePackages $True -BuildVersion $buildVersion
1130
}
1231
else {
13-
.\build.ps1 -CheckCoverage $True
32+
.\build.ps1 -CheckCoverage $True -BuildVersion $buildVersion
1433
}
1534

1635
Exit $LastExitCode

build.ps1

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,82 @@
11
[CmdletBinding(PositionalBinding=$false)]
22
param(
3-
[bool] $RunTests = $true,
3+
[bool] $RunTests = $true,
44
[bool] $CheckCoverage,
5-
[bool] $CreatePackages
5+
[bool] $CreatePackages,
6+
[string] $BuildVersion
67
)
78

8-
$testProject = "tests/InfinityCrawler.Tests/InfinityCrawler.Tests.csproj"
9-
$testCoverageFilter = "+[InfinityCrawler]* -[InfinityCrawler.Tests]*"
10-
119
$packageOutputFolder = "$PSScriptRoot\build-artifacts"
1210
mkdir -Force $packageOutputFolder | Out-Null
1311

12+
$config = Get-Content "buildconfig.json" | ConvertFrom-Json
13+
14+
if (-not $BuildVersion) {
15+
$lastTaggedVersion = git describe --tags --abbrev=0
16+
if ($lastTaggedVersion -contains "fatal") {
17+
$lastTaggedVersion = "0.0.0"
18+
}
19+
20+
$BuildVersion = $lastTaggedVersion
21+
}
22+
1423
Write-Host "Run Parameters:" -ForegroundColor Cyan
1524
Write-Host " RunTests: $RunTests"
1625
Write-Host " CheckCoverage: $CheckCoverage"
1726
Write-Host " CreatePackages: $CreatePackages"
27+
Write-Host " BuildVersion: $BuildVersion"
28+
Write-Host "Configuration:" -ForegroundColor Cyan
29+
Write-Host " TestProject: $($config.TestProject)"
30+
Write-Host " TestCoverageFilter: $($config.TestCoverageFilter)"
1831
Write-Host "Environment:" -ForegroundColor Cyan
1932
Write-Host " .NET Version:" (dotnet --version)
2033
Write-Host " Artifact Path: $packageOutputFolder"
2134

2235
Write-Host "Building solution..." -ForegroundColor "Magenta"
23-
dotnet build -c Release
36+
dotnet build -c Release /p:Version=$BuildVersion
2437
if ($LastExitCode -ne 0) {
25-
Write-Host "Build failed, aborting!" -Foreground "Red"
26-
Exit 1
38+
Write-Host "Build failed, aborting!" -Foreground "Red"
39+
Exit 1
2740
}
2841
Write-Host "Solution built!" -ForegroundColor "Green"
2942

30-
if ($RunTests -And -Not $CheckCoverage) {
31-
Write-Host "Running tests without coverage..." -ForegroundColor "Magenta"
32-
dotnet test $testProject
33-
if ($LastExitCode -ne 0) {
34-
Write-Host "Tests failed, aborting build!" -Foreground "Red"
35-
Exit 1
36-
}
37-
Write-Host "Tests passed!" -ForegroundColor "Green"
38-
}
39-
elseif ($RunTests -And $CheckCoverage) {
40-
Write-Host "Running tests with coverage..." -ForegroundColor "Magenta"
41-
OpenCover.Console.exe -register:user -target:"%LocalAppData%\Microsoft\dotnet\dotnet.exe" -targetargs:"test $testProject /p:DebugType=Full" -filter:"$testCoverageFilter" -output:"$packageOutputFolder\coverage.xml" -oldstyle
42-
if ($LastExitCode -ne 0 -Or -Not $?) {
43-
Write-Host "Failure performing tests with coverage, aborting!" -Foreground "Red"
44-
Exit 1
45-
}
46-
else {
43+
if ($RunTests) {
44+
if (-Not $CheckCoverage) {
45+
Write-Host "Running tests without coverage..." -ForegroundColor "Magenta"
46+
dotnet test $config.TestProject
47+
if ($LastExitCode -ne 0) {
48+
Write-Host "Tests failed, aborting build!" -Foreground "Red"
49+
Exit 1
50+
}
4751
Write-Host "Tests passed!" -ForegroundColor "Green"
48-
Write-Host "Saving code coverage..." -ForegroundColor "Magenta"
49-
codecov -f "$packageOutputFolder\coverage.xml"
52+
}
53+
else {
54+
Write-Host "Running tests with coverage..." -ForegroundColor "Magenta"
55+
OpenCover.Console.exe -register:user -target:"%LocalAppData%\Microsoft\dotnet\dotnet.exe" -targetargs:"test $($config.TestProject) /p:DebugType=Full" -filter:"$($config.TestCoverageFilter)" -output:"$packageOutputFolder\coverage.xml" -oldstyle
5056
if ($LastExitCode -ne 0 -Or -Not $?) {
51-
Write-Host "Failure saving code coverage!" -Foreground "Red"
57+
Write-Host "Failure performing tests with coverage, aborting!" -Foreground "Red"
58+
Exit 1
5259
}
5360
else {
54-
Write-Host "Coverage saved!" -ForegroundColor "Green"
61+
Write-Host "Tests passed!" -ForegroundColor "Green"
62+
Write-Host "Saving code coverage..." -ForegroundColor "Magenta"
63+
codecov -f "$packageOutputFolder\coverage.xml"
64+
if ($LastExitCode -ne 0 -Or -Not $?) {
65+
Write-Host "Failure saving code coverage!" -Foreground "Red"
66+
}
67+
else {
68+
Write-Host "Coverage saved!" -ForegroundColor "Green"
69+
}
5570
}
5671
}
5772
}
5873

5974
if ($CreatePackages) {
60-
Write-Host "Clearing existing $packageOutputFolder... " -NoNewline
61-
Get-ChildItem $packageOutputFolder | Remove-Item
62-
Write-Host "Packages cleared!" -ForegroundColor "Green"
75+
Write-Host "Clearing existing $packageOutputFolder... " -NoNewline
76+
Get-ChildItem $packageOutputFolder | Remove-Item
77+
Write-Host "Packages cleared!" -ForegroundColor "Green"
6378

64-
Write-Host "Packing..." -ForegroundColor "Magenta"
65-
dotnet pack --no-build -c Release /p:PackageOutputPath=$packageOutputFolder
79+
Write-Host "Packing..." -ForegroundColor "Magenta"
80+
dotnet pack --no-build -c Release /p:Version=$BuildVersion /p:PackageOutputPath=$packageOutputFolder
6681
Write-Host "Packing complete!" -ForegroundColor "Green"
6782
}

buildconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"TestProject": "tests/InfinityCrawler.Tests/InfinityCrawler.Tests.csproj",
3+
"TestCoverageFilter": "+[InfinityCrawler]* -[InfinityCrawler.Tests]*"
4+
}

src/Directory.build.props

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
<Project>
2-
3-
<PropertyGroup>
4-
<BuildNumber Condition="'$(APPVEYOR_BUILD_NUMBER)' != ''">$(APPVEYOR_BUILD_NUMBER)</BuildNumber>
5-
<BuildNumber Condition="'$(APPVEYOR_BUILD_NUMBER)' == ''">0</BuildNumber>
6-
</PropertyGroup>
72

83
<PropertyGroup>
9-
<Version>0.3.0+$(BuildNumber)</Version>
10-
114
<RootNamespace>InfinityCrawler</RootNamespace>
125

136
<Company>Turner Software</Company>

0 commit comments

Comments
 (0)