Skip to content

Commit

Permalink
New build process (#68)
Browse files Browse the repository at this point in the history
Builds centralised to a PowerShell script
AppVeyor now deploys to NuGet and GitHub
  • Loading branch information
Turnerj committed May 26, 2019
1 parent dc477e0 commit f32dc26
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 42 deletions.
98 changes: 59 additions & 39 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,59 @@
version: '0.11.1+{build}'
image: Visual Studio 2017
skip_branch_with_pr: true
branches:
only:
- master
skip_commits:
files:
- '**/*.md'

dotnet_csproj:
patch: true
file: 'src\*.props'
version: '{version}'

build:
verbosity: minimal
services:
- mongodb
install:
- choco install opencover codecov
- ps: .\build\dotnet-install.ps1 -Version 3.0.100-preview5-011568


build_script:
- dotnet build -c Release
- dotnet pack --no-build -c Release /p:PackageOutputPath=..\..\.nupkgs
test_script:
- OpenCover.Console.exe -register:user -target:"%LocalAppData%\Microsoft\dotnet\dotnet.exe" -targetargs:"test tests/MongoFramework.Tests/MongoFramework.Tests.csproj /p:DebugType=Full" -filter:"+[MongoFramework]* -[MongoFramework.Tests]*" -output:".\coverage.xml" -oldstyle
- codecov -f coverage.xml


artifacts:
- path: '.nupkgs\*.nupkg'

- path: '.nupkgs\*.snupkg'

- path: coverage.xml
name: Coverage Report
-
version: '{build}'
image: Visual Studio 2017
skip_tags: true
branches:
only:
- master
skip_commits:
files:
- '**/*.md'

services:
- mongodb
install:
- choco install opencover codecov
- ps: .\build\dotnet-install.ps1 -Version 3.0.100-preview5-011568

build_script:
- ps: .\build.ps1 -CheckCoverage $True

test: false
artifacts:
- path: '.\build-artifacts\*'


-
version: '{build}'
image: Visual Studio 2017
skip_non_tags: true
branches:
only:
- master

services:
- mongodb
install:
- choco install opencover codecov
- ps: .\build\dotnet-install.ps1 -Version 3.0.100-preview5-011568

build_script:
- ps: .\build.ps1 -CreatePackages $True

test: false
artifacts:
- path: '.\build-artifacts\*'

deploy:
- provider: NuGet
artifact: /.*nupkg/
api_key:
secure: eCdbkZMnfQfn//yoFtvyHHVUkoIX1yUfs6qRtOGsRxQq95pDPNMUMD0+XN9itbKp

- provider: GitHub
artifact: /.*nupkg/
draft: true
release: $(APPVEYOR_REPO_TAG_NAME)
description: 'Release Description'
auth_token:
secure: 8WGv8noklaCJAQEBpcs+VShk/Hql5zbyx0VPhMvzUw0RcG7rAd2KxKIh4gazXlBi
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,6 @@ paket-files/
*.sln.iml

# Coderush
/.cr
/.cr

/build-artifacts
2 changes: 2 additions & 0 deletions MongoFramework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{BA1176
.appveyor.yml = .appveyor.yml
.codecov.yml = .codecov.yml
.editorconfig = .editorconfig
.gitignore = .gitignore
build.ps1 = build.ps1
License.txt = License.txt
README.md = README.md
EndProjectSection
Expand Down
64 changes: 64 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[CmdletBinding(PositionalBinding=$false)]
param(
[bool] $RunTests = $true,
[bool] $CheckCoverage,
[bool] $CreatePackages
)

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

Write-Host "Run Parameters:" -ForegroundColor Cyan
Write-Host " RunTests: $RunTests"
Write-Host " CheckCoverage: $CheckCoverage"
Write-Host " CreatePackages: $CreatePackages"
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
if ($LastExitCode -ne 0) {
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 tests/MongoFramework.Tests/MongoFramework.Tests.csproj
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 tests/MongoFramework.Tests/MongoFramework.Tests.csproj /p:DebugType=Full" -filter:"+[MongoFramework]* -[MongoFramework.Tests]*" -output:"$packageOutputFolder\coverage.xml" -oldstyle
if ($LastExitCode -ne 0 -Or -Not $?) {
Write-Host "Failure performing tests with coverage, aborting!" -Foreground "Red"
Exit 1
}
else {
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 "Packing..." -ForegroundColor "Magenta"
dotnet pack --no-build -c Release /p:PackageOutputPath=$packageOutputFolder
Write-Host "Packing complete!" -ForegroundColor "Green"
}
9 changes: 7 additions & 2 deletions src/Directory.build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<Project>

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

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

<RootNamespace>MongoFramework</RootNamespace>

Expand All @@ -24,7 +30,6 @@

<LangVersion>Latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05" PrivateAssets="All" />
</ItemGroup>
Expand Down

0 comments on commit f32dc26

Please sign in to comment.