Skip to content

Commit ab7d0f6

Browse files
[WIP] Move from psake to cake
1 parent 9d31709 commit ab7d0f6

13 files changed

+768
-360
lines changed

.gitattributes

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,6 @@ _UpgradeReport_Files/
107107
Backup*/
108108
UpgradeLog*.XML
109109

110-
build_artifacts
110+
artifacts
111+
build
112+
tools

GitVersionConfig.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
next-version: 2.2.4

build.bat

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@ECHO OFF
2+
PUSHD %~dp0
3+
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& './build.ps1'"
4+
5+
IF %errorlevel% neq 0 PAUSE
6+

build.cake

+223
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// ARGUMENTS
3+
///////////////////////////////////////////////////////////////////////////////
4+
5+
var target = Argument<string>("target", "Default");
6+
var configuration = Argument<string>("configuration", "Release");
7+
8+
//////////////////////////////////////////////////////////////////////
9+
// EXTERNAL NUGET TOOLS
10+
//////////////////////////////////////////////////////////////////////
11+
12+
#Tool "xunit.runner.console"
13+
#Tool "GitVersion.CommandLine"
14+
15+
//////////////////////////////////////////////////////////////////////
16+
// EXTERNAL NUGET LIBRARIES
17+
//////////////////////////////////////////////////////////////////////
18+
19+
#addin "System.Text.Json"
20+
using System.Text.Json;
21+
22+
///////////////////////////////////////////////////////////////////////////////
23+
// GLOBAL VARIABLES
24+
///////////////////////////////////////////////////////////////////////////////
25+
26+
var projectName = "Polly";
27+
28+
var solutions = GetFiles("./**/*.sln");
29+
var solutionPaths = solutions.Select(solution => solution.GetDirectory());
30+
31+
var srcDir = Directory("./src");
32+
var buildDir = Directory("./build");
33+
var artifactsDir = Directory("./artifacts");
34+
var testResultsDir = artifactsDir + Directory("test-results");
35+
36+
// NuGet
37+
var nuspecFilename = projectName + ".nuspec";
38+
var nuspecSrcFile = srcDir + File(nuspecFilename);
39+
var nuspecDestFile = buildDir + File(nuspecFilename);
40+
var nupkgDestDir = artifactsDir + Directory("nuget-package");
41+
42+
var projectToNugetFolderMap = new Dictionary<string, string>() {
43+
{ "Net35", "net35" },
44+
{ "Net40", "net40" },
45+
{ "Net45", "net45" },
46+
{ "Pcl", "portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS" }
47+
};
48+
49+
// Gitversion
50+
var gitVersionPath = ToolsExePath("GitVersion.exe");
51+
Dictionary<string, object> gitVersionOutput;
52+
53+
var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
54+
55+
///////////////////////////////////////////////////////////////////////////////
56+
// SETUP / TEARDOWN
57+
///////////////////////////////////////////////////////////////////////////////
58+
59+
Setup(() =>
60+
{
61+
62+
});
63+
64+
Teardown(() =>
65+
{
66+
Information("Finished running tasks.");
67+
});
68+
69+
//////////////////////////////////////////////////////////////////////
70+
// PRIVATE TASKS
71+
//////////////////////////////////////////////////////////////////////
72+
73+
Task("__Clean")
74+
.Does(() =>
75+
{
76+
CleanDirectories(new DirectoryPath[] {
77+
buildDir,
78+
artifactsDir,
79+
testResultsDir,
80+
nupkgDestDir
81+
});
82+
83+
foreach(var path in solutionPaths)
84+
{
85+
Information("Cleaning {0}", path);
86+
CleanDirectories(path + "/**/bin/" + configuration);
87+
CleanDirectories(path + "/**/obj/" + configuration);
88+
}
89+
});
90+
91+
Task("__RestoreNugetPackages")
92+
.Does(() =>
93+
{
94+
foreach(var solution in solutions)
95+
{
96+
Information("Restoring NuGet Packages for {0}", solution);
97+
NuGetRestore(solution);
98+
}
99+
});
100+
101+
Task("__UpdateAssemblyVersionInformation")
102+
.Does(() =>
103+
{
104+
105+
var gitVersionSettings = new ProcessSettings()
106+
.SetRedirectStandardOutput(true)
107+
.WithArguments(args => args
108+
.Append("/updateassemblyinfo")
109+
.AppendQuoted(@".\src\GlobalAssemblyInfo.cs"));
110+
111+
IEnumerable<string> outputLines;
112+
StartProcess(gitVersionPath, gitVersionSettings, out outputLines);
113+
114+
var output = string.Join("\n", outputLines);
115+
gitVersionOutput = new JsonParser().Parse<Dictionary<string, object>>(output);
116+
117+
Information("Updated GlobalAssemblyInfo");
118+
Information("AssemblyVersion -> {0}", gitVersionOutput["AssemblySemVer"]);
119+
Information("AssemblyFileVersion -> {0}", gitVersionOutput["MajorMinorPatch"]);
120+
Information("AssemblyInformationalVersion -> {0}", gitVersionOutput["InformationalVersion"]);
121+
});
122+
123+
Task("__UpdateAppVeyorBuildNumber")
124+
.WithCriteria(() => isRunningOnAppVeyor)
125+
.Does(() =>
126+
{
127+
var fullSemVer = gitVersionOutput["FullSemVer"].ToString();
128+
AppVeyor.UpdateBuildVersion(fullSemVer);
129+
});
130+
131+
Task("__BuildSolutions")
132+
.Does(() =>
133+
{
134+
foreach(var solution in solutions)
135+
{
136+
Information("Building {0}", solution);
137+
138+
MSBuild(solution, settings =>
139+
settings
140+
.SetConfiguration(configuration)
141+
.WithProperty("TreatWarningsAsErrors", "true")
142+
.UseToolVersion(MSBuildToolVersion.NET46)
143+
.SetVerbosity(Verbosity.Minimal)
144+
.SetNodeReuse(false));
145+
}
146+
});
147+
148+
Task("__RunTests")
149+
.Does(() =>
150+
{
151+
XUnit2("./src/**/bin/" + configuration + "/*.Specs.dll", new XUnit2Settings {
152+
OutputDirectory = testResultsDir,
153+
XmlReportV1 = true
154+
});
155+
});
156+
157+
Task("__CopyOutputToNugetFolder")
158+
.Does(() =>
159+
{
160+
foreach(var project in projectToNugetFolderMap.Keys) {
161+
var sourceDir = srcDir + Directory(projectName + "." + project) + Directory("bin") + Directory(configuration);
162+
var destDir = buildDir + Directory("lib") + Directory(projectToNugetFolderMap[project]);
163+
164+
Information("Copying {0} -> {1}.", sourceDir, destDir);
165+
CopyDirectory(sourceDir, destDir);
166+
}
167+
168+
CopyFile(nuspecSrcFile, nuspecDestFile);
169+
});
170+
171+
Task("__CreateNugetPackage")
172+
.Does(() =>
173+
{
174+
var nugetVersion = gitVersionOutput["NuGetVersion"].ToString();
175+
176+
Information("Building {0}.{1}.nupkg", projectName, nugetVersion);
177+
178+
var nuGetPackSettings = new NuGetPackSettings {
179+
Id = "Polly",
180+
Title = "Polly",
181+
Version = nugetVersion,
182+
Symbols = true,
183+
OutputDirectory = nupkgDestDir
184+
};
185+
186+
NuGetPack(nuspecDestFile, nuGetPackSettings);
187+
});
188+
189+
//////////////////////////////////////////////////////////////////////
190+
// BUILD TASKS
191+
//////////////////////////////////////////////////////////////////////
192+
193+
Task("Build")
194+
.IsDependentOn("__Clean")
195+
.IsDependentOn("__RestoreNugetPackages")
196+
.IsDependentOn("__UpdateAssemblyVersionInformation")
197+
.IsDependentOn("__UpdateAppVeyorBuildNumber")
198+
.IsDependentOn("__BuildSolutions")
199+
.IsDependentOn("__RunTests")
200+
.IsDependentOn("__CopyOutputToNugetFolder")
201+
.IsDependentOn("__CreateNugetPackage");
202+
203+
///////////////////////////////////////////////////////////////////////////////
204+
// PRIMARY TARGETS
205+
///////////////////////////////////////////////////////////////////////////////
206+
207+
Task("Default")
208+
.IsDependentOn("Build");
209+
210+
///////////////////////////////////////////////////////////////////////////////
211+
// EXECUTION
212+
///////////////////////////////////////////////////////////////////////////////
213+
214+
RunTarget(target);
215+
216+
//////////////////////////////////////////////////////////////////////
217+
// HELPER FUNCTIONS
218+
//////////////////////////////////////////////////////////////////////
219+
220+
string ToolsExePath(string exeFileName) {
221+
var exePath = System.IO.Directory.GetFiles(@".\Tools", exeFileName, SearchOption.AllDirectories).FirstOrDefault();
222+
return exePath;
223+
}

0 commit comments

Comments
 (0)