Skip to content

Commit 35b9e41

Browse files
authored
Merge pull request #4 from XerProjects/build-appveyor
Use Cake Build Tooling
2 parents 4da0381 + 9da9179 commit 35b9e41

File tree

9 files changed

+715
-0
lines changed

9 files changed

+715
-0
lines changed

.DS_Store

8 KB
Binary file not shown.

.gitattributes

Lines changed: 63 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,7 @@ __pycache__/
262262

263263
# VS Code
264264
.vscode/
265+
266+
[Tt]ools/**
267+
![Tt]ools/packages.config
268+
BuildArtifacts/**

GitVersion.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mode: ContinuousDelivery
2+
next-version: 1.0.0
3+
branches: {}
4+
ignore:
5+
sha: []

Tools/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Cake" version="0.26.1" />
4+
</packages>

Xer.Delegator.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCoreApp", "Samples\As
1717
EndProject
1818
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadSide", "Samples\ReadSide\ReadSide.csproj", "{45C19B67-5162-441C-8469-8969D2F9236D}"
1919
EndProject
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "Samples\Infrastructure\Infrastructure.csproj", "{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}"
21+
EndProject
2022
Global
2123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2224
Debug|Any CPU = Debug|Any CPU
@@ -102,11 +104,24 @@ Global
102104
{45C19B67-5162-441C-8469-8969D2F9236D}.Release|x64.Build.0 = Release|x64
103105
{45C19B67-5162-441C-8469-8969D2F9236D}.Release|x86.ActiveCfg = Release|x86
104106
{45C19B67-5162-441C-8469-8969D2F9236D}.Release|x86.Build.0 = Release|x86
107+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
108+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
109+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Debug|x64.ActiveCfg = Debug|x64
110+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Debug|x64.Build.0 = Debug|x64
111+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Debug|x86.ActiveCfg = Debug|x86
112+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Debug|x86.Build.0 = Debug|x86
113+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
114+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Release|Any CPU.Build.0 = Release|Any CPU
115+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Release|x64.ActiveCfg = Release|x64
116+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Release|x64.Build.0 = Release|x64
117+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Release|x86.ActiveCfg = Release|x86
118+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C}.Release|x86.Build.0 = Release|x86
105119
EndGlobalSection
106120
GlobalSection(NestedProjects) = preSolution
107121
{B9EE4A32-6BB4-40C7-8727-5EBAEAFFF3B8} = {D56DF064-CA65-433E-89AD-F585765C65F9}
108122
{9BAA418C-A3C1-4A29-AB38-DE7207943296} = {D56DF064-CA65-433E-89AD-F585765C65F9}
109123
{E3C5BB87-432D-4FDE-9C17-17DAF7149505} = {D56DF064-CA65-433E-89AD-F585765C65F9}
110124
{45C19B67-5162-441C-8469-8969D2F9236D} = {D56DF064-CA65-433E-89AD-F585765C65F9}
125+
{C6AB5E8D-7AE6-47AD-81AB-03067DCB6F1C} = {D56DF064-CA65-433E-89AD-F585765C65F9}
111126
EndGlobalSection
112127
EndGlobal

build.cake

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// ADDINS/TOOLS
3+
///////////////////////////////////////////////////////////////////////////////
4+
#tool "nuget:?package=GitVersion.CommandLine"
5+
#addin nuget:?package=Cake.Git
6+
7+
///////////////////////////////////////////////////////////////////////////////
8+
// ARGUMENTS
9+
///////////////////////////////////////////////////////////////////////////////
10+
11+
var target = Argument<string>("target", "Default");
12+
var configuration = Argument<string>("configuration", "Release");
13+
14+
///////////////////////////////////////////////////////////////////////////////
15+
// GLOBAL VARIABLES
16+
///////////////////////////////////////////////////////////////////////////////
17+
18+
var solutions = GetFiles("./**/*.sln");
19+
var projects = GetFiles("./**/*.csproj").Select(x => x.GetDirectory());
20+
21+
GitVersion gitVersion;
22+
23+
///////////////////////////////////////////////////////////////////////////////
24+
// SETUP / TEARDOWN
25+
///////////////////////////////////////////////////////////////////////////////
26+
27+
Setup(context =>
28+
{
29+
gitVersion = GitVersion(new GitVersionSettings {
30+
UpdateAssemblyInfo = true
31+
});
32+
33+
BuildParameters.Initialize(Context);
34+
35+
// Executed BEFORE the first task.
36+
Information("Xer.Delegator");
37+
Information("Parameters");
38+
Information("///////////////////////////////////////////////////////////////////////////////");
39+
Information("Branch: {0}", BuildParameters.Instance.BranchName);
40+
Information("Version semver: {0}", gitVersion.LegacySemVerPadded);
41+
Information("Version assembly: {0}", gitVersion.MajorMinorPatch);
42+
Information("Version informational: {0}", gitVersion.InformationalVersion);
43+
Information("Master branch: {0}", BuildParameters.Instance.IsMasterBranch);
44+
Information("Dev branch: {0}", BuildParameters.Instance.IsDevBranch);
45+
Information("Hotfix branch: {0}", BuildParameters.Instance.IsHotFixBranch);
46+
Information("Publish to myget: {0}", BuildParameters.Instance.ShouldPublishMyGet);
47+
Information("Publish to nuget: {0}", BuildParameters.Instance.ShouldPublishNuGet);
48+
Information("///////////////////////////////////////////////////////////////////////////////");
49+
});
50+
51+
Teardown(context =>
52+
{
53+
// Executed AFTER the last task.
54+
Information("Finished running tasks.");
55+
});
56+
57+
///////////////////////////////////////////////////////////////////////////////
58+
// TASK DEFINITIONS
59+
///////////////////////////////////////////////////////////////////////////////
60+
61+
Task("Clean")
62+
.Description("Cleans all directories that are used during the build process.")
63+
.Does(() =>
64+
{
65+
// Clean solution directories.
66+
foreach(var project in projects)
67+
{
68+
Information("Cleaning {0}", project);
69+
DotNetCoreClean(project.FullPath);
70+
}
71+
});
72+
73+
Task("Restore")
74+
.Description("Restores all the NuGet packages that are used by the specified solution.")
75+
.Does(() =>
76+
{
77+
var settings = new DotNetCoreRestoreSettings
78+
{
79+
ArgumentCustomization = args => args
80+
.Append("/p:Version={0}", gitVersion.LegacySemVerPadded)
81+
.Append("/p:AssemblyVersion={0}", gitVersion.MajorMinorPatch)
82+
.Append("/p:FileVersion={0}", gitVersion.MajorMinorPatch)
83+
.Append("/p:AssemblyInformationalVersion={0}", gitVersion.InformationalVersion)
84+
};
85+
86+
// Restore all NuGet packages.
87+
foreach(var solution in solutions)
88+
{
89+
Information("Restoring {0}...", solution);
90+
91+
DotNetCoreRestore(solution.FullPath, settings);
92+
}
93+
});
94+
95+
Task("Build")
96+
.Description("Builds all the different parts of the project.")
97+
.IsDependentOn("Clean")
98+
.IsDependentOn("Restore")
99+
.Does(() =>
100+
{
101+
var settings = new DotNetCoreBuildSettings
102+
{
103+
Configuration = configuration,
104+
ArgumentCustomization = args => args
105+
.Append("/p:Version={0}", gitVersion.LegacySemVerPadded)
106+
.Append("/p:AssemblyVersion={0}", gitVersion.MajorMinorPatch)
107+
.Append("/p:FileVersion={0}", gitVersion.MajorMinorPatch)
108+
.Append("/p:AssemblyInformationalVersion={0}", gitVersion.InformationalVersion)
109+
};
110+
111+
// Build all solutions.
112+
foreach(var solution in solutions)
113+
{
114+
Information("Building {0}", solution);
115+
116+
DotNetCoreBuild(solution.FullPath, settings);
117+
}
118+
});
119+
120+
Task("Test")
121+
.Description("Execute all unit test projects.")
122+
.IsDependentOn("Build")
123+
.Does(() =>
124+
{
125+
var projects = GetFiles("./Tests/**/*.Tests.csproj");
126+
var settings = new DotNetCoreTestSettings
127+
{
128+
Configuration = configuration,
129+
NoBuild = true,
130+
};
131+
132+
foreach(var project in projects)
133+
{
134+
DotNetCoreTest(project.FullPath, settings);
135+
}
136+
});
137+
138+
Task("Pack")
139+
.IsDependentOn("Test")
140+
.Does(() =>
141+
{
142+
var projects = GetFiles("./src/**/*.csproj");
143+
var settings = new DotNetCorePackSettings
144+
{
145+
NoBuild = true,
146+
Configuration = configuration,
147+
ArgumentCustomization = (args) => args
148+
.Append("/p:Version={0}", gitVersion.LegacySemVerPadded)
149+
.Append("/p:AssemblyVersion={0}", gitVersion.MajorMinorPatch)
150+
.Append("/p:FileVersion={0}", gitVersion.MajorMinorPatch)
151+
.Append("/p:AssemblyInformationalVersion={0}", gitVersion.InformationalVersion)
152+
};
153+
154+
foreach (var project in projects)
155+
{
156+
DotNetCorePack(project.ToString(), settings);
157+
}
158+
});
159+
160+
Task("PublishMyGet")
161+
.WithCriteria(() => BuildParameters.Instance.ShouldPublishMyGet)
162+
.IsDependentOn("Pack")
163+
.Does(() =>
164+
{
165+
var nupkgs = GetFiles("./**/*.nupkg");
166+
167+
foreach(var nupkgFile in nupkgs)
168+
{
169+
Information("Pulishing to myget {0}", nupkgFile);
170+
171+
NuGetPush(nupkgFile, new NuGetPushSettings
172+
{
173+
Source = BuildParameters.Instance.MyGetFeed,
174+
ApiKey = BuildParameters.Instance.MyGetApiKey
175+
});
176+
}
177+
});
178+
179+
Task("PublishNuGet")
180+
.WithCriteria(() => BuildParameters.Instance.ShouldPublishNuGet)
181+
.IsDependentOn("Pack")
182+
.Does(() =>
183+
{
184+
var nupkgs = GetFiles("./**/*.nupkg");
185+
186+
foreach(var nupkgFile in nupkgs)
187+
{
188+
Information("Pulishing to nuget {0}", nupkgFile);
189+
NuGetPush(nupkgFile, new NuGetPushSettings
190+
{
191+
Source = BuildParameters.Instance.NuGetFeed,
192+
ApiKey = BuildParameters.Instance.NuGetApiKey
193+
});
194+
}
195+
});
196+
197+
198+
///////////////////////////////////////////////////////////////////////////////
199+
// TARGETS
200+
///////////////////////////////////////////////////////////////////////////////
201+
202+
Task("Default")
203+
.Description("This is the default task which will be ran if no specific target is passed in.")
204+
.IsDependentOn("PublishNuGet")
205+
.IsDependentOn("PublishMyGet");
206+
207+
///////////////////////////////////////////////////////////////////////////////
208+
// EXECUTION
209+
///////////////////////////////////////////////////////////////////////////////
210+
211+
RunTarget(target);
212+
213+
public class BuildParameters
214+
{
215+
private static BuildParameters _buildParameters;
216+
217+
public static BuildParameters Instance => _buildParameters;
218+
219+
private ICakeContext _context;
220+
221+
private BuildParameters(ICakeContext context)
222+
{
223+
_context = context;
224+
}
225+
226+
public static void Initialize(ICakeContext context)
227+
{
228+
if(_buildParameters != null)
229+
{
230+
return;
231+
}
232+
233+
_buildParameters = new BuildParameters(context);
234+
}
235+
236+
public bool IsAppVeyorBuild => _context.BuildSystem().AppVeyor.IsRunningOnAppVeyor;
237+
238+
public bool IsLocalBuild => _context.BuildSystem().IsLocalBuild;
239+
240+
public string BranchName
241+
{
242+
get
243+
{
244+
return IsLocalBuild
245+
? _context.GitBranchCurrent(".").FriendlyName
246+
: _context.BuildSystem().AppVeyor.Environment.Repository.Branch;
247+
}
248+
}
249+
250+
public string MyGetFeed => _context.EnvironmentVariable("MYGET_SOURCE");
251+
252+
public string MyGetApiKey => _context.EnvironmentVariable("MYGET_API_KEY");
253+
254+
public string NuGetFeed => _context.EnvironmentVariable("NUGET_SOURCE");
255+
256+
public string NuGetApiKey => _context.EnvironmentVariable("NUGET_API_KEY");
257+
258+
public bool IsMasterBranch => StringComparer.OrdinalIgnoreCase.Equals("master", BranchName);
259+
260+
public bool IsDevBranch => StringComparer.OrdinalIgnoreCase.Equals("dev", BranchName);
261+
262+
public bool IsReleaseBranch => BranchName.StartsWith("release", StringComparison.OrdinalIgnoreCase);
263+
264+
public bool IsHotFixBranch => BranchName.StartsWith("hotfix", StringComparison.OrdinalIgnoreCase);
265+
266+
public bool ShouldPublishMyGet => !string.IsNullOrWhiteSpace(MyGetApiKey) && !string.IsNullOrWhiteSpace(MyGetFeed);
267+
268+
public bool ShouldPublishNuGet => !string.IsNullOrWhiteSpace(NuGetApiKey)
269+
&& !string.IsNullOrWhiteSpace(NuGetFeed)
270+
&& IsMasterBranch
271+
&& IsHotFixBranch;
272+
}

0 commit comments

Comments
 (0)