Skip to content

Commit

Permalink
Added build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Feb 13, 2019
1 parent cf55c0d commit d6c0f7c
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,10 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/

.sonarqube/

testoutput/

tools/**
!tools/packages.config
180 changes: 180 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#addin "nuget:?package=Cake.Sonar&version=1.1.18"
#addin "nuget:?package=Cake.FileHelpers&version=3.1.0"
#addin "nuget:?package=Cake.Incubator&version=3.0.0"
#tool "nuget:?package=MSBuild.SonarQube.Runner.Tool&version=4.3.1"


//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");

var configuration = EnvironmentVariable<string>("Build_Configuration", "Release");

var nugetToken = EnvironmentVariable<string>("Nuget_Token", default(string));
var sonarLogin = EnvironmentVariable<string>("Sonar_Token", default(string));

var packageVersion = EnvironmentVariable<string>("Version", default(string));


var version = EnvironmentVariable<string>("Build_Version", default(string));

var sonarPrKey = EnvironmentVariable<string>("Sonar_Pr_Key", default(string));
var sonarBranch = EnvironmentVariable<string>("Sonar_Branch", default(string));

//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
var testOutputDir = Directory("./testoutput");
var publishOutputDir = Directory("./artifacts");

//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////

Task("Clean")
.Does(() =>
{
DotNetCoreClean("./src");
});

Task("Restore")
.Does(() =>
{
DotNetCoreRestore("./src");
});

Task("Build")
.Does(() =>
{
var settings = new DotNetCoreBuildSettings
{
Configuration = configuration,
};
DotNetCoreBuild("./src", settings);
});

Task("Publish")
.Does(() =>
{
using(var process = StartAndReturnProcess("msbuild",
new ProcessSettings{ Arguments = "./src/Snapshooter.sln /t:restore /p:configuration=" + configuration }))
{
process.WaitForExit();
}
using(var process = StartAndReturnProcess("msbuild",
new ProcessSettings{ Arguments = "./src/Snapshooter.sln /t:build /p:configuration=" + configuration }))
{
process.WaitForExit();
}
using(var process = StartAndReturnProcess("msbuild",
new ProcessSettings{ Arguments = "./src/Snapshooter.sln /t:pack /p:configuration=" + configuration + " /p:IncludeSource=true /p:IncludeSymbols=true" }))
{
process.WaitForExit();
}
});

Task("Push")
.Does(() =>
{
var packages = GetFiles("./**/*.nupkg");
NuGetPush(packages, new NuGetPushSettings {
Source = "https://api.nuget.org/v3/index.json",
ApiKey = nugetToken
});
});

Task("Tests")
.Does(() =>
{
var buildSettings = new DotNetCoreBuildSettings
{
Configuration = "Debug"
};
int i = 0;
var testSettings = new DotNetCoreTestSettings
{
Configuration = "Debug",
ResultsDirectory = $"./{testOutputDir}",
Logger = "trx",
NoRestore = true,
NoBuild = true,
ArgumentCustomization = args => args
.Append("/p:CollectCoverage=true")
.Append("/p:Exclude=[xunit.*]*")
.Append("/p:CoverletOutputFormat=opencover")
.Append($"/p:CoverletOutput=\"../../{testOutputDir}/full_{i++}\" --blame")
};
DotNetCoreBuild("./src", buildSettings);
foreach(var file in GetFiles("./src/**/*.Tests.csproj"))
{
DotNetCoreTest(file.FullPath, testSettings);
}
});

Task("SonarBegin")
.Does(() =>
{
SonarBegin(new SonarBeginSettings
{
Url = "https://sonarcloud.io",
Login = sonarLogin,
Key = "SwissLife-OSS_Snapshooter",
Organization = "swisslife",
VsTestReportsPath = "**/*.trx",
OpenCoverReportsPath = "**/*.opencover.xml",
Exclusions = "**/*.js,**/*.html,**/*.css,**/examples/**/*.*,**/benchmarks/**/*.*,**/src/Templates/**/*.*",
Verbose = false,
Version = packageVersion,
ArgumentCustomization = args => {
var a = args;
if(!string.IsNullOrEmpty(sonarPrKey))
{
a = a.Append($"/d:sonar.pullrequest.key=\"{sonarPrKey}\"");
a = a.Append($"/d:sonar.pullrequest.branch=\"{sonarBranch}\"");
a = a.Append($"/d:sonar.pullrequest.base=\"master\"");
a = a.Append($"/d:sonar.pullrequest.provider=\"github\"");
a = a.Append($"/d:sonar.pullrequest.github.repository=\"SwissLife-OSS/Snapshooter\"");
}
return a;
}
});
});

Task("SonarEnd")
.Does(() =>
{
SonarEnd(new SonarEndSettings
{
Login = sonarLogin,
});
});

//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Tests");

Task("Sonar")
.IsDependentOn("SonarBegin")
.IsDependentOn("Tests")
.IsDependentOn("SonarEnd");

Task("Release")
.IsDependentOn("Sonar")
.IsDependentOn("Publish");

//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);
18 changes: 18 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="DefaultPushSource" value="https://api.nuget.org/v3/index.json" />
</config>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<activePackageSource>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</activePackageSource>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
12 changes: 12 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>
<PropertyGroup>
<CCSourceDirectory>$(MSBuildThisFileDirectory.TrimEnd('\').TrimEnd('/'))</CCSourceDirectory>
<CCSettingsProps>$([System.IO.Path]::Combine($(CCSourceDirectory), 'Settings.props'))</CCSettingsProps>
<CCVersionProps>$([System.IO.Path]::Combine($(CCSourceDirectory), 'Version.props'))</CCVersionProps>
<CCPackageProps>$([System.IO.Path]::Combine($(CCSourceDirectory), 'Package.props'))</CCPackageProps>
</PropertyGroup>

<Import Project="$(CCSettingsProps)" Condition="Exists('$(CCSettingsProps)')"/>
<Import Project="$(CCVersionProps)" Condition="Exists('$(CCVersionProps)')"/>
<Import Project="$(CCPackageProps)" Condition="Exists('$(CCPackageProps)')"/>
</Project>
6 changes: 6 additions & 0 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<Target Name="CheckCCPropertyFiles" BeforeTargets="Build">
<Error Text="Could not load version.props file." Condition="!Exists('$(CCVersionProps)')" />
<Error Text="Could not load package.props file." Condition="!Exists('$(CCPackageProps)')" />
</Target>
</Project>
30 changes: 30 additions & 0 deletions src/Package.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project>

<PropertyGroup>
<Product>Snapshooter</Product>
<Authors>Swiss Life authors and contributors</Authors>
<Company>Swiss Life</Company>
<Copyright>Copyright © 2018 Swiss Life</Copyright>
<PackageLicenseUrl>https://github.com/SwissLife-OSS/Snapshooter/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/SwissLife-OSS/Snapshooter</PackageProjectUrl>
<PackageReleaseNotes>Release notes: https://github.com/ChilliCream/SwissLife-OSS/Snapshooter/releases/$(Version)</PackageReleaseNotes>
<PackageTags>XUnit SwissLife Snapshot</PackageTags>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<!--PackageIconUrl>https://cdn.rawgit.com/ChilliCream/Snapshooter-logo/master/img/Snapshooter-signet.png</PackageIconUrl-->
</PropertyGroup>

<PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<RepositoryUrl>https://github.com/SwissLife-OSS/Snapshooter.git</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

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

</Project>
7 changes: 7 additions & 0 deletions src/Settings.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>

<PropertyGroup>
<LangVersion>7.2</LangVersion>
</PropertyGroup>

</Project>
8 changes: 5 additions & 3 deletions src/Snapshooter.Json.Tests/Snapshooter.Json.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.5.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="FluentAssertions" Version="5.5.3" />
<PackageReference Include="coverlet.msbuild" Version="2.5.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.4.0-beta.1.build3958" />
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 5 additions & 6 deletions src/Snapshooter.Tests/Snapshooter.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="FluentAssertions" Version="5.5.3" />
<PackageReference Include="Microsoft.CodeCoverage" Version="1.0.3" />
<PackageReference Include="coverlet.msbuild" Version="2.5.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.4.0-beta.1.build3958" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 7 additions & 0 deletions src/Version.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>

<PropertyGroup>
<Version Condition="$(Version) == ''">0.0.0</Version>
</PropertyGroup>

</Project>

0 comments on commit d6c0f7c

Please sign in to comment.