Skip to content

Commit

Permalink
Update build cake script
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Sep 5, 2018
1 parent 56bfe29 commit 35cace4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 48 deletions.
6 changes: 5 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# configuration for develop and master branch
# http://www.appveyor.com/docs/appveyor-yml

# configuration for develop/CI and master/Release branch
-
branches:
only:
Expand All @@ -26,3 +27,6 @@

artifacts:
- path: \src\Publish\*.*

nuget:
disable_publish_on_pr: true
107 changes: 61 additions & 46 deletions src/build.cake
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// TOOLS / ADDINS
//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

#tool paket:?package=GitVersion.CommandLine
#tool paket:?package=gitreleasemanager
#tool paket:?package=vswhere
#tool paket:?package=xunit.runner.console
#addin paket:?package=Cake.Figlet
#addin paket:?package=Cake.Paket

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

var target = Argument("target", "Default");
if (string.IsNullOrWhiteSpace(target))
Expand All @@ -25,47 +25,66 @@ if (string.IsNullOrWhiteSpace(configuration))
configuration = "Release";
}

//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

// Set build version
GitVersion(new GitVersionSettings { OutputType = GitVersionOutput.BuildServer });
GitVersion gitVersion;
GitVersion gitVersion = GitVersion(new GitVersionSettings { OutputType = GitVersionOutput.Json });

var latestInstallationPath = VSWhereProducts("*", new VSWhereProductSettings { Version = "[\"15.0\",\"16.0\"]" }).FirstOrDefault();
var msBuildPath = latestInstallationPath.CombineWithFilePath("./MSBuild/15.0/Bin/MSBuild.exe");

var local = BuildSystem.IsLocalBuild;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
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;

// Define directories.
// Directories and Paths
var solution = "MahApps.Metro.sln";
var publishDir = "./Publish";

//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////

Setup(context =>
Setup(ctx =>
{
context.Tools.RegisterFile("./packages/NuGet.CommandLine/tools/NuGet.exe");
// Executed BEFORE the first task.

if (!IsRunningOnWindows())
{
throw new NotImplementedException("MahApps.Metro will only build on Windows because it's not possible to target WPF and Windows Forms from UNIX.");
}

Information(Figlet("MahApps.Metro"));

gitVersion = GitVersion(new GitVersionSettings { OutputType = GitVersionOutput.Json });
Information("Informational Version : {0}", gitVersion.InformationalVersion);
Information("SemVer Version : {0}", gitVersion.SemVer);
Information("AssemblySemVer Version : {0}", gitVersion.AssemblySemVer);
Information("Informational Version: {0}", gitVersion.InformationalVersion);
Information("SemVer Version: {0}", gitVersion.SemVer);
Information("AssemblySemVer Version: {0}", gitVersion.AssemblySemVer);
Information("MajorMinorPatch Version: {0}", gitVersion.MajorMinorPatch);
Information("NuGet Version : {0}", gitVersion.NuGetVersion);
Information("NuGet Version: {0}", gitVersion.NuGetVersion);
Information("IsLocalBuild : {0}", local);
Information("Configuration : {0}", configuration);
});

Information(Figlet("MahApps.Metro"));
Teardown(ctx =>
{
// Executed AFTER the last task.
});

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

Task("Clean")
//.ContinueOnError()
.Does(() =>
{
CleanDirectories("./**/bin");
CleanDirectories("./**/obj");
var directoriesToDelete = GetDirectories("./**/obj").Concat(GetDirectories("./**/bin"));
DeleteDirectories(directoriesToDelete, new DeleteDirectorySettings { Recursive = true, Force = true });
});

Task("NuGet-Paket-Restore")
Expand All @@ -74,13 +93,8 @@ Task("NuGet-Paket-Restore")
{
PaketRestore();

// Restore all NuGet packages.
var solutions = GetFiles("./**/*.sln");
foreach(var solution in solutions)
{
Information("Restoring {0}", solution);
MSBuild(solution, settings => settings.SetMaxCpuCount(0).SetConfiguration(configuration).WithTarget("restore"));
}
var msBuildSettings = new MSBuildSettings() { ToolPath = msBuildPath };
MSBuild(solution, msBuildSettings.SetVerbosity(Verbosity.Normal).WithTarget("restore"));
});

Task("Update-SolutionInfo")
Expand All @@ -94,33 +108,33 @@ Task("Build")
.IsDependentOn("NuGet-Paket-Restore")
.Does(() =>
{
var solutions = GetFiles("./**/*.sln");
foreach(var solution in solutions)
{
Information("Building {0}", solution);
MSBuild(solution, settings => settings.SetMaxCpuCount(0).SetConfiguration(configuration));
}
var msBuildSettings = new MSBuildSettings() { ToolPath = msBuildPath, ArgumentCustomization = args => args.Append("/m") };
MSBuild(solution, msBuildSettings.SetMaxCpuCount(0)
.SetVerbosity(Verbosity.Normal)
//.WithRestore() only with cake 0.28.x
.SetConfiguration(configuration)
);
});

Task("Paket-Pack")
//.WithCriteria(ShouldRunRelease())
.Does(() =>
{
EnsureDirectoryExists(Directory(publishDir));
PaketPack(publishDir, new PaketPackSettings { Version = isReleaseBranch ? gitVersion.MajorMinorPatch : gitVersion.NuGetVersion });
EnsureDirectoryExists(Directory(publishDir));
PaketPack(publishDir, new PaketPackSettings {
Version = isReleaseBranch ? gitVersion.MajorMinorPatch : gitVersion.NuGetVersion,
BuildConfig = configuration
});
});

Task("Zip-Demos")
//.WithCriteria(ShouldRunRelease())
.Does(() =>
{
EnsureDirectoryExists(Directory(publishDir));
EnsureDirectoryExists(Directory(publishDir));
Zip("./MahApps.Metro.Samples/MahApps.Metro.Demo/bin/" + configuration, publishDir + "/MahApps.Metro.Demo-v" + gitVersion.NuGetVersion + ".zip");
Zip("./MahApps.Metro.Samples/MahApps.Metro.Caliburn.Demo/bin/" + configuration, publishDir + "/MahApps.Metro.Caliburn.Demo-v" + gitVersion.NuGetVersion + ".zip");
});

Task("Unit-Tests")
//.WithCriteria(ShouldRunRelease())
.Does(() =>
{
XUnit2(
Expand All @@ -130,6 +144,7 @@ Task("Unit-Tests")
});

Task("CreateRelease")
.WithCriteria(() => isReleaseBranch)
.WithCriteria(() => !isTagged)
.Does(() =>
{
Expand Down Expand Up @@ -178,9 +193,9 @@ Task("ExportReleaseNotes")
});
});

//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

Task("Default")
.IsDependentOn("Build");
Expand All @@ -192,8 +207,8 @@ Task("appveyor")
.IsDependentOn("Paket-Pack")
.IsDependentOn("Zip-Demos");

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

RunTarget(target);
RunTarget(target);
3 changes: 2 additions & 1 deletion src/paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ group cake
nuget Cake.Figlet
nuget Cake.Paket
nuget Cake.Paket.Module
nuget vswhere
nuget GitVersion.CommandLine prerelease
nuget gitreleasemanager
nuget xunit.runner.console prerelease
nuget xunit.runner.console prerelease
1 change: 1 addition & 0 deletions src/paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ NUGET
Cake.Paket.Module (4.0)
gitreleasemanager (0.7.1)
GitVersion.CommandLine (4.0.0-beta0014)
vswhere (2.5.2)
xunit.runner.console (2.4.1-pre.build.4059)

GROUP test
Expand Down

0 comments on commit 35cace4

Please sign in to comment.