Skip to content
Permalink
Browse files

Updated build script

  • Loading branch information...
Turnerj committed Aug 18, 2019
1 parent f8f46ff commit 0d59e9bb660cc4ff2a6ef5f476d523f986b680f6
Showing with 84 additions and 54 deletions.
  1. +2 −2 .appveyor.yml
  2. +1 −3 .codecov.yml
  3. +1 −0 InfinityCrawler.sln
  4. +27 −8 build.appveyor.ps1
  5. +49 −34 build.ps1
  6. +4 −0 buildconfig.json
  7. +0 −7 src/Directory.build.props
@@ -1,4 +1,4 @@
version: '{build}'
version: 'Build {build}'
image: Visual Studio 2017
skip_branch_with_pr: true

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


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

test: false
artifacts:
@@ -1,3 +1 @@
comment: off
ignore:
- "*.ps1"
comment: off
@@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{F0B4D0
.gitignore = .gitignore
build.appveyor.ps1 = build.appveyor.ps1
build.ps1 = build.ps1
buildconfig.json = buildconfig.json
License.txt = License.txt
README.md = README.md
EndProjectSection
@@ -1,16 +1,35 @@
[CmdletBinding(PositionalBinding=$false)]
param(
[bool] $IsTagBuild
)
Write-Host "Initialising AppVeyor build..." -ForegroundColor "Magenta"

$baseBuildVersion = git describe --tags --abbrev=0
if ($baseBuildVersion -contains "fatal") {
$baseBuildVersion = "0.0.0"
}

Write-Host "Initialising AppVeyor build..." -ForegroundColor "Magenta"
$isTagBuild = $False
$buildMetadata = "$($env:APPVEYOR_REPO_COMMIT.substring(0,7))-$($env:APPVEYOR_BUILD_NUMBER)"
$prereleaseVersion = "dev"

if ($env:APPVEYOR_REPO_TAG -ne "false") {
$baseBuildVersion = $env:APPVEYOR_REPO_TAG_NAME
$prereleaseVersion = $False
$isTagBuild = $True
}
elseif ($env:APPVEYOR_PULL_REQUEST_NUMBER) {
$prereleaseVersion = "PR$($env:APPVEYOR_PULL_REQUEST_NUMBER)"
}

$buildVersion = "$baseBuildVersion+$buildMetadata"
if ($prereleaseVersion) {
$buildVersion = "$baseBuildVersion-$prereleaseVersion+$buildMetadata"
}

Update-AppveyorBuild -Version $buildVersion

if ($IsTagBuild) {
.\build.ps1 -CreatePackages $True
if ($isTagBuild) {
.\build.ps1 -CreatePackages $True -BuildVersion $buildVersion
}
else {
.\build.ps1 -CheckCoverage $True
.\build.ps1 -CheckCoverage $True -BuildVersion $buildVersion
}

Exit $LastExitCode
@@ -1,67 +1,82 @@
[CmdletBinding(PositionalBinding=$false)]
param(
[bool] $RunTests = $true,
[bool] $RunTests = $true,
[bool] $CheckCoverage,
[bool] $CreatePackages
[bool] $CreatePackages,
[string] $BuildVersion
)

$testProject = "tests/InfinityCrawler.Tests/InfinityCrawler.Tests.csproj"
$testCoverageFilter = "+[InfinityCrawler]* -[InfinityCrawler.Tests]*"

$packageOutputFolder = "$PSScriptRoot\build-artifacts"
mkdir -Force $packageOutputFolder | Out-Null

$config = Get-Content "buildconfig.json" | ConvertFrom-Json

if (-not $BuildVersion) {
$lastTaggedVersion = git describe --tags --abbrev=0
if ($lastTaggedVersion -contains "fatal") {
$lastTaggedVersion = "0.0.0"
}

$BuildVersion = $lastTaggedVersion
}

Write-Host "Run Parameters:" -ForegroundColor Cyan
Write-Host " RunTests: $RunTests"
Write-Host " CheckCoverage: $CheckCoverage"
Write-Host " CreatePackages: $CreatePackages"
Write-Host " BuildVersion: $BuildVersion"
Write-Host "Configuration:" -ForegroundColor Cyan
Write-Host " TestProject: $($config.TestProject)"
Write-Host " TestCoverageFilter: $($config.TestCoverageFilter)"
Write-Host "Environment:" -ForegroundColor Cyan
Write-Host " .NET Version:" (dotnet --version)
Write-Host " Artifact Path: $packageOutputFolder"

Write-Host "Building solution..." -ForegroundColor "Magenta"
dotnet build -c Release
dotnet build -c Release /p:Version=$BuildVersion
if ($LastExitCode -ne 0) {
Write-Host "Build failed, aborting!" -Foreground "Red"
Exit 1
Write-Host "Build failed, aborting!" -Foreground "Red"
Exit 1
}
Write-Host "Solution built!" -ForegroundColor "Green"

if ($RunTests -And -Not $CheckCoverage) {
Write-Host "Running tests without coverage..." -ForegroundColor "Magenta"
dotnet test $testProject
if ($LastExitCode -ne 0) {
Write-Host "Tests failed, aborting build!" -Foreground "Red"
Exit 1
}
Write-Host "Tests passed!" -ForegroundColor "Green"
}
elseif ($RunTests -And $CheckCoverage) {
Write-Host "Running tests with coverage..." -ForegroundColor "Magenta"
OpenCover.Console.exe -register:user -target:"%LocalAppData%\Microsoft\dotnet\dotnet.exe" -targetargs:"test $testProject /p:DebugType=Full" -filter:"$testCoverageFilter" -output:"$packageOutputFolder\coverage.xml" -oldstyle
if ($LastExitCode -ne 0 -Or -Not $?) {
Write-Host "Failure performing tests with coverage, aborting!" -Foreground "Red"
Exit 1
}
else {
if ($RunTests) {
if (-Not $CheckCoverage) {
Write-Host "Running tests without coverage..." -ForegroundColor "Magenta"
dotnet test $config.TestProject
if ($LastExitCode -ne 0) {
Write-Host "Tests failed, aborting build!" -Foreground "Red"
Exit 1
}
Write-Host "Tests passed!" -ForegroundColor "Green"
Write-Host "Saving code coverage..." -ForegroundColor "Magenta"
codecov -f "$packageOutputFolder\coverage.xml"
}
else {
Write-Host "Running tests with coverage..." -ForegroundColor "Magenta"
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
if ($LastExitCode -ne 0 -Or -Not $?) {
Write-Host "Failure saving code coverage!" -Foreground "Red"
Write-Host "Failure performing tests with coverage, aborting!" -Foreground "Red"
Exit 1
}
else {
Write-Host "Coverage saved!" -ForegroundColor "Green"
Write-Host "Tests passed!" -ForegroundColor "Green"
Write-Host "Saving code coverage..." -ForegroundColor "Magenta"
codecov -f "$packageOutputFolder\coverage.xml"
if ($LastExitCode -ne 0 -Or -Not $?) {
Write-Host "Failure saving code coverage!" -Foreground "Red"
}
else {
Write-Host "Coverage saved!" -ForegroundColor "Green"
}
}
}
}

if ($CreatePackages) {
Write-Host "Clearing existing $packageOutputFolder... " -NoNewline
Get-ChildItem $packageOutputFolder | Remove-Item
Write-Host "Packages cleared!" -ForegroundColor "Green"
Write-Host "Clearing existing $packageOutputFolder... " -NoNewline
Get-ChildItem $packageOutputFolder | Remove-Item
Write-Host "Packages cleared!" -ForegroundColor "Green"

Write-Host "Packing..." -ForegroundColor "Magenta"
dotnet pack --no-build -c Release /p:PackageOutputPath=$packageOutputFolder
Write-Host "Packing..." -ForegroundColor "Magenta"
dotnet pack --no-build -c Release /p:Version=$BuildVersion /p:PackageOutputPath=$packageOutputFolder
Write-Host "Packing complete!" -ForegroundColor "Green"
}
@@ -0,0 +1,4 @@
{
"TestProject": "tests/InfinityCrawler.Tests/InfinityCrawler.Tests.csproj",
"TestCoverageFilter": "+[InfinityCrawler]* -[InfinityCrawler.Tests]*"
}
@@ -1,13 +1,6 @@
<Project>

<PropertyGroup>
<BuildNumber Condition="'$(APPVEYOR_BUILD_NUMBER)' != ''">$(APPVEYOR_BUILD_NUMBER)</BuildNumber>
<BuildNumber Condition="'$(APPVEYOR_BUILD_NUMBER)' == ''">0</BuildNumber>
</PropertyGroup>

<PropertyGroup>
<Version>0.3.0+$(BuildNumber)</Version>

<RootNamespace>InfinityCrawler</RootNamespace>

<Company>Turner Software</Company>

0 comments on commit 0d59e9b

Please sign in to comment.
You can’t perform that action at this time.