Skip to content

Commit

Permalink
Use cake for all build related and fix code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Krusen committed Aug 5, 2017
1 parent e56100d commit 2cdeb66
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 21 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,9 @@ tools/**
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
*.xsd.cs




/coverage.xml
13 changes: 8 additions & 5 deletions BencodeNET.Tests/BencodeNET.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<None Update="Files\ubuntu-14.10-desktop-amd64.iso.torrent">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand All @@ -23,11 +26,11 @@
<PackageReference Include="AutoFixture.Xunit2" Version="3.50.3" />
<PackageReference Include="FluentAssertions" Version="4.19.3" />
<PackageReference Include="NSubstitute" Version="2.0.3" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.core" Version="2.2.0" />
<PackageReference Include="xunit.extensibility.execution" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" />
<PackageReference Include="xunit" Version="2.3.0-beta3-build3705" />
<PackageReference Include="xunit.core" Version="2.3.0-beta3-build3705" />
<PackageReference Include="xunit.extensibility.execution" Version="2.3.0-beta3-build3705" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta3-build3705" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta3-build3705" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions BencodeNET.Tests/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"shadowCopy": false
}
5 changes: 5 additions & 0 deletions BencodeNET/BencodeNET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

<!-- Needed for code coverage -->
<PropertyGroup>
<DebugType>full</DebugType>
</PropertyGroup>

<PropertyGroup>
<PackageId>BencodeNET</PackageId>
<Version>2.2.0</Version>
Expand Down
139 changes: 124 additions & 15 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,35 +1,144 @@
var target = Argument("target", "Default");
// Install addins.
#addin "nuget:?package=Cake.Coveralls&version=0.5.0"

Task("Set-Build-Version")
// Install tools.
#tool "nuget:?package=OpenCover&version=4.6.519"
#tool "nuget:?package=coveralls.io&version=1.3.4"
#tool "nuget:?package=xunit.runner.console&version=2.2.0"


///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////

var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");


///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////

var libraryName = "BencodeNET";

var sourceFolder = "./";

var projectFile = "./BencodeNET/BencodeNET.csproj";

var testProjectFile = "./BencodeNET.Tests/BencodeNET.Tests.csproj";
var codeCoverageOutput = "coverage.xml";
var codeCoverageFilter = "+[*]* -[*.Tests]*";

var cakeVersion = typeof(ICakeContext).Assembly.GetName().Version.ToString();


///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////

Setup(context =>
{
Information($"Building using version {cakeVersion} of Cake");
});


///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////

Task("Update-Build-Version")
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
var projectFile = "./BencodeNET/BencodeNET.csproj";
var versionPeekXpath = "/Project/PropertyGroup/Version/text()";
var versionPokeXpath = "/Project/PropertyGroup/Version";
var buildNumber = AppVeyor.Environment.Build.Number;
var version = XmlPeek(projectFile, versionPeekXpath);
Information("AppVeyor build version is " + AppVeyor.Environment.Build.Version);
Information("Project version is " + version);
var parts = version.Split('.');
version = string.Join(".", parts[0], parts[1], buildNumber);
Information("Changing versions to " + version);
AppVeyor.UpdateBuildVersion(version);
XmlPoke(projectFile, versionPokeXpath, version);
});

var buildNumber = 0;
Task("Restore-NuGet-Packages")
.Does(() =>
{
DotNetCoreRestore();
});

if (BuildSystem.IsRunningOnAppVeyor)
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
DotNetCoreBuild(sourceFolder + libraryName + ".sln", new DotNetCoreBuildSettings
{
buildNumber = AppVeyor.Environment.Build.Number;
}
Configuration = configuration
});
});

version = string.Join(".", parts[0], parts[1], buildNumber);
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
DotNetCoreTest(testProjectFile, new DotNetCoreTestSettings
{
NoBuild = true,
Configuration = configuration
});
});

if (BuildSystem.IsRunningOnAppVeyor)
Task("Run-Code-Coverage")
.IsDependentOn("Build")
.Does(() =>
{
Action<ICakeContext> testAction = ctx => ctx.DotNetCoreTest(testProjectFile, new DotNetCoreTestSettings
{
AppVeyor.UpdateBuildVersion(version);
Information("Updated AppVeyor build version to " + version);
}
NoBuild = true,
Configuration = configuration
});
XmlPoke(projectFile, versionPokeXpath, version);
Information("Set project version to " + version);
OpenCover(testAction,
codeCoverageOutput,
new OpenCoverSettings
{
OldStyle = true,
SkipAutoProps = true,
MergeOutput = false
}
.WithFilter(codeCoverageFilter)
);
});

Task("Upload-Coverage-Result")
.Does(() =>
{
CoverallsIo(codeCoverageOutput);
});


///////////////////////////////////////////////////////////////////////////////
// TARGETS
///////////////////////////////////////////////////////////////////////////////

Task("AppVeyor")
.IsDependentOn("Update-Build-Version")
.IsDependentOn("Run-Code-Coverage")
.IsDependentOn("Upload-Coverage-Result");

Task("Default")
.IsDependentOn("Set-Build-Version");
.IsDependentOn("AppVeyor");


///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////

RunTarget(target);
4 changes: 4 additions & 0 deletions tools/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.21.1" />
</packages>

0 comments on commit 2cdeb66

Please sign in to comment.