Skip to content

Commit

Permalink
WIP: Cake build, see #162
Browse files Browse the repository at this point in the history
  • Loading branch information
cd21h committed Mar 3, 2018
1 parent 5aacc59 commit a99513b
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 48 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bld/
[Oo]bj/
[Ll]og/
tools/
.ReSharperCaches/

# Visual Studio 2015 cache/options directory
.vs/
Expand Down
7 changes: 4 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@ environment:
coveralls_repo_token:
secure: FgZlD1O2ilcGB6nF7cIgNcF6f8wWJk//ish6EG800QfuMd0y3BQWUXkl9u7TB4yG
appveyor_cache_entry_zip_args: -t7z -m0=lzma -mx=5 -ms=on
CAKE_SETTINGS_SKIPVERIFICATION: true

before_build:
# - cmd: nuget restore Solutions/SharpArch.sln
# - ps: gitversion /output buildserver /updateAssemblyInfo .\Common\AssemblyVersion.cs /ensureAssemblyInfo

build_script:
# skip BuildSamples; for now..
- cmd: 'MSBuild.exe Build\Build.proj /t:Build;RunTests;UploadNUnitCoverage;FindDuplicates;InspectCode;PackageNuget /p:IsDesktopBuild=false'
- ps: ./build.ps1

test: off

artifacts:
- path: Drops/**/*.nupkg
name: Nugets
- path: Drops/Duplicates/CodeDuplicatesReport.html
- path: Drops/Inspections/CodeDuplicates.html
name: CodeDuplicates
- path: Drops/Inspections/CodeInspectionsReport.html
- path: Drops/Inspections/CodeInspections.html
name: CodeInspections

deploy:
Expand Down
164 changes: 119 additions & 45 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
#addin "Cake.Coveralls"
#addin "Cake.PinNuGetDependency"
#addin "Cake.Incubator"
#addin "Cake.Issues"
#addin "Cake.Issues.InspectCode"
#addin "Cake.ReSharperReports"
#addin nuget:?package=Cake.AppVeyor
#addin nuget:?package=Refit&version=3.0.0
#addin nuget:?package=Newtonsoft.Json&version=9.0.1

// TOOLS
#tool "GitReleaseManager"
Expand All @@ -11,6 +17,8 @@
#tool "OpenCover"
#tool "ReportGenerator"
#tool "nuget:?package=NUnit.ConsoleRunner"
#tool "nuget:?package=JetBrains.ReSharper.CommandLineTools"
#tool "nuget:?package=ReSharperReports"

// ARGUMENTS
var target = Argument("target", "Default");
Expand All @@ -19,7 +27,7 @@ if (string.IsNullOrWhiteSpace(target))
target = "Default";
}

var buildConfig = Argument("buildConfig", "Debug");
var buildConfig = Argument("buildConfig", "Release");
if (string.IsNullOrEmpty(buildConfig)) {
buildConfig = "Release";
}
Expand All @@ -32,6 +40,8 @@ var isRepository = StringComparer.OrdinalIgnoreCase.Equals("SharpArchitecture/Sh
var isDevelopBranch = StringComparer.OrdinalIgnoreCase.Equals("develop", AppVeyor.Environment.Repository.Branch);
var isReleaseBranch = StringComparer.OrdinalIgnoreCase.Equals("master", AppVeyor.Environment.Repository.Branch);
var isTagged = AppVeyor.Environment.Repository.Tag.IsTag;
var appVeyorJobId = AppVeyor.Environment.JobId;


GitVersion semVersion = GitVersion();
var nugetVersion = semVersion.NuGetVersion;
Expand All @@ -43,11 +53,14 @@ var informationalVersion = semVersion.InformationalVersion;
// Artifacts
var artifactDirectory = "./Drops/";
var testCoverageOutputFile = artifactDirectory + "OpenCover.xml";

var codeInspectionsOutputFile = artifactDirectory + "Inspections/CodeInspections.xml";
var duplicateFinderOutputFile = artifactDirectory + "Inspections/CodeDuplicates.xml";
var solutionFile = "./Solutions/SharpArch.sln";
var nunitTestResults = artifactDirectory + "Nunit3TestResults.xml";

Setup((context) =>
{
Information("Building SharpArchitecture, version {0} (isTagged: {1})...", nugetVersion, isTagged);
Information("Building SharpArchitecture, version {0} (isTagged: {1}, isLocal: {2})...", nugetVersion, isTagged, local);
CreateDirectory(artifactDirectory);
});

Expand All @@ -66,7 +79,27 @@ Task("SetVersion")
});
});



Task("UpdateAppVeyorBuildNumber")
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
AppVeyor.UpdateBuildVersion(buildVersion);
}).ReportError(exception =>
{
// When a build starts, the initial identifier is an auto-incremented value supplied by AppVeyor.
// As part of the build script, this version in AppVeyor is changed to be the version obtained from
// GitVersion. This identifier is purely cosmetic and is used by the core team to correlate a build
// with the pull-request. In some circumstances, such as restarting a failed/cancelled build the
// identifier in AppVeyor will be already updated and default behaviour is to throw an
// exception/cancel the build when in fact it is safe to swallow.
// See https://github.com/reactiveui/ReactiveUI/issues/1262
Warning("Build with version {0} already exists.", buildVersion);
});


Task("Restore")
.Does(() =>
{
Expand All @@ -75,6 +108,8 @@ Task("Restore")


Task("Build")
.IsDependentOn("UpdateAppVeyorBuildNumber")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetCoreBuild("./Solutions/", new DotNetCoreBuildSettings{
Expand All @@ -83,64 +118,103 @@ Task("Build")
});


Task("RunUnitTests")
// .IsDependentOn("Build")
.Does(() =>
Task("RunTests")
.Does(() =>
{
var testAssemblies = GetFiles("./Solutions/tests/SharpArch.Tests/bin/Release/net462/SharpArch.Tests.dll")
//.Union(GetFiles("./Solutions/tests/SharpArch.Tests.NHibernate/bin/Release/net462/SharpArch.Tests.NHibernate.dll"))
;
foreach (var item in testAssemblies)
{
Information("Test assembly: {0}", item);
}
Information("Artifacts directory: {0}", artifactDirectory + "TestResult.xml");
NUnit3(testAssemblies,
new NUnit3Settings {
OutputFile = artifactDirectory + "TestOutput.xml",
ErrorOutputFile = artifactDirectory + "ErrorOutput.xml",
Results = new [] {
new NUnit3Result {
FileName = artifactDirectory + "TestResult.xml"
}
},
//OutputDirectory = artifactDirectory + "/",
ShadowCopy = false,
});
// Action<ICakeContext> testAction = tool => {
// tool.NUnit3("./Solutions/tests/**/bin/Release/**/SharpArch.Tests.*.dll",
// new NUnit3Settings {
// //OutputDirectory = artifactDirectory + "/",
// ShadowCopy = false,
// });
// };
// OpenCover(testAction,
// testCoverageOutputFile,
// new OpenCoverSettings {
// ReturnTargetCodeOffset = 0,
// ArgumentCustomization = args => args.Append("-mergeoutput")
// }
// .WithFilter("+[*]* -[*.Tests*]* -[Splat*]*")
// .ExcludeByAttribute("*.ExcludeFromCodeCoverage*")
// .ExcludeByFile("*/*Designer.cs;*/*.g.cs;*/*.g.i.cs;*splat/splat*"));
// ReportGenerator(testCoverageOutputFile, artifactDirectory);
Action<ICakeContext> testAction = tool => {
tool.NUnit3(testAssemblies,
new NUnit3Settings {
OutputFile = artifactDirectory + "TestOutput.xml",
ErrorOutputFile = artifactDirectory + "ErrorOutput.xml",
Results = new [] {
new NUnit3Result {
FileName = nunitTestResults
}
},
ShadowCopy = false,
});
};
OpenCover(testAction,
testCoverageOutputFile,
new OpenCoverSettings {
ReturnTargetCodeOffset = 0,
ArgumentCustomization = args => args.Append("-mergeoutput")
}
.WithFilter("+[*]* -[*.Tests*]*")
.ExcludeByAttribute("*.ExcludeFromCodeCoverage*")
.ExcludeByFile("*/*Designer.cs "));
});


Task("GenerateCoverageReport")
.WithCriteria(() => local)
.Does(() =>
{
ReportGenerator(testCoverageOutputFile, artifactDirectory+"CodeCoverageReport");
});


Task("UploadTestResults")
.WithCriteria(() => !local)
.Does(() => {
CoverallsIo(testCoverageOutputFile);
UploadFile("https://ci.appveyor.com/api/testresults/nunit3/"+appVeyorJobId, nunitTestResults)
});


Task("RunUnitTests")
// .IsDependentOn("Build")
.IsDependentOn("RunTests")
.IsDependentOn("GenerateCoverageReport")
.IsDependentOn("UploadTestResults")
.Does(() =>
{
});


Task("InspectCode")
.Does(() => {
DupFinder(solutionFile, new DupFinderSettings() {
ShowStats = true,
ShowText = true,
OutputFile = duplicateFinderOutputFile,
});
ReSharperReports(
duplicateFinderOutputFile,
System.IO.Path.ChangeExtension(duplicateFinderOutputFile, "html")
);
InspectCode(solutionFile, new InspectCodeSettings() {
OutputFile = codeInspectionsOutputFile,
Profile = "./Solutions/SharpArch.sln.DotSettings",
CachesHome = "./.ReSharperCaches",
SolutionWideAnalysis = true
});
ReSharperReports(
codeInspectionsOutputFile,
System.IO.Path.ChangeExtension(codeInspectionsOutputFile, "html")
);
});


Task("Default")
.IsDependentOn("SetVersion")
// .IsDependentOn("Restore")
// .IsDependentOn("Build")
.IsDependentOn("UpdateAppVeyorBuildNumber")
.IsDependentOn("Build")
.IsDependentOn("RunUnitTests")
.IsDependentOn("InspectCode")
.Does(
() => {}
);


// EXECUTION
RunTarget(target);

0 comments on commit a99513b

Please sign in to comment.