Skip to content

Commit e2652b1

Browse files
authored
Merge pull request #5 from mkane91301/master
Add build
2 parents 590f4cb + f16ea48 commit e2652b1

File tree

7 files changed

+571
-28
lines changed

7 files changed

+571
-28
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Polly.Caching.Serialization.System.Text.Json change log
2+
3+
## 1.0.0
4+
- Initial release

build.bat

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

build.cake

Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
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 "Cake.FileHelpers"
20+
#addin nuget:?package=Cake.Yaml
21+
#addin nuget:?package=YamlDotNet&version=5.2.1
22+
23+
///////////////////////////////////////////////////////////////////////////////
24+
// GLOBAL VARIABLES
25+
///////////////////////////////////////////////////////////////////////////////
26+
27+
var projectName = "Polly.Caching.Serialization.System.Text.Json";
28+
29+
var solutions = GetFiles("./**/*.sln");
30+
var solutionPaths = solutions.Select(solution => solution.GetDirectory());
31+
32+
var srcDir = Directory("./src");
33+
var artifactsDir = Directory("./artifacts");
34+
var testResultsDir = artifactsDir + Directory("test-results");
35+
36+
// NuGet
37+
var nupkgDestDir = artifactsDir + Directory("nuget-package");
38+
39+
// Gitversion
40+
var gitVersionPath = ToolsExePath("GitVersion.exe");
41+
Dictionary<string, object> gitVersionOutput;
42+
var gitVersionConfigFilePath = "./GitVersionConfig.yaml";
43+
44+
// Versioning
45+
string nugetVersion;
46+
string appveyorBuildNumber;
47+
string assemblyVersion;
48+
string assemblySemver;
49+
50+
///////////////////////////////////////////////////////////////////////////////
51+
// INNER CLASSES
52+
///////////////////////////////////////////////////////////////////////////////
53+
class GitVersionConfigYaml
54+
{
55+
public string NextVersion { get; set; }
56+
}
57+
58+
///////////////////////////////////////////////////////////////////////////////
59+
// SETUP / TEARDOWN
60+
///////////////////////////////////////////////////////////////////////////////
61+
62+
Setup(_ =>
63+
{
64+
Information("");
65+
Information("----------------------------------------");
66+
Information("Starting the cake build script");
67+
Information("Building: " + projectName);
68+
Information("----------------------------------------");
69+
Information("");
70+
});
71+
72+
Teardown(_ =>
73+
{
74+
Information("Finished running tasks.");
75+
});
76+
77+
//////////////////////////////////////////////////////////////////////
78+
// PRIVATE TASKS
79+
//////////////////////////////////////////////////////////////////////
80+
81+
Task("__Clean")
82+
.Does(() =>
83+
{
84+
DirectoryPath[] cleanDirectories = new DirectoryPath[] {
85+
testResultsDir,
86+
nupkgDestDir,
87+
artifactsDir
88+
};
89+
90+
CleanDirectories(cleanDirectories);
91+
92+
foreach(var path in cleanDirectories) { EnsureDirectoryExists(path); }
93+
94+
foreach(var path in solutionPaths)
95+
{
96+
Information("Cleaning {0}", path);
97+
DotNetCoreClean(path.ToString());
98+
}
99+
});
100+
101+
Task("__RestoreNugetPackages")
102+
.Does(() =>
103+
{
104+
foreach(var solution in solutions)
105+
{
106+
Information("Restoring NuGet Packages for {0}", solution);
107+
DotNetCoreRestore(solution.ToString());
108+
}
109+
});
110+
111+
Task("__UpdateAssemblyVersionInformation")
112+
.Does(() =>
113+
{
114+
var gitVersionSettings = new ProcessSettings()
115+
.SetRedirectStandardOutput(true);
116+
117+
try {
118+
IEnumerable<string> outputLines;
119+
StartProcess(gitVersionPath, gitVersionSettings, out outputLines);
120+
121+
var output = string.Join("\n", outputLines);
122+
gitVersionOutput = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(output);
123+
}
124+
catch
125+
{
126+
Information("Error reading git version information. Build may be running outside of a git repo. Falling back to version specified in " + gitVersionConfigFilePath);
127+
128+
string gitVersionYamlString = System.IO.File.ReadAllText(gitVersionConfigFilePath);
129+
GitVersionConfigYaml deserialized = DeserializeYaml<GitVersionConfigYaml>(gitVersionYamlString.Replace("next-version", "NextVersion"));
130+
string gitVersionConfig = deserialized.NextVersion;
131+
132+
gitVersionOutput = new Dictionary<string, object>{
133+
{ "NuGetVersion", gitVersionConfig + "-NotFromGitRepo" },
134+
{ "FullSemVer", gitVersionConfig },
135+
{ "AssemblySemVer", gitVersionConfig },
136+
{ "Major", gitVersionConfig.Split('.')[0] },
137+
};
138+
139+
}
140+
141+
Information("");
142+
Information("Obtained raw version info for package versioning:");
143+
Information("NuGetVersion -> {0}", gitVersionOutput["NuGetVersion"]);
144+
Information("FullSemVer -> {0}", gitVersionOutput["FullSemVer"]);
145+
Information("AssemblySemVer -> {0}", gitVersionOutput["AssemblySemVer"]);
146+
147+
appveyorBuildNumber = gitVersionOutput["BranchName"].ToString().Equals("master", StringComparison.OrdinalIgnoreCase)
148+
? gitVersionOutput["FullSemVer"].ToString()
149+
: gitVersionOutput["InformationalVersion"].ToString();
150+
nugetVersion = gitVersionOutput["NuGetVersion"].ToString();
151+
assemblyVersion = gitVersionOutput["Major"].ToString() + ".0.0.0";
152+
assemblySemver = gitVersionOutput["AssemblySemVer"].ToString();
153+
154+
Information("");
155+
Information("Mapping versioning information to:");
156+
Information("Appveyor build number -> {0}", appveyorBuildNumber);
157+
Information("Nuget package version -> {0}", nugetVersion);
158+
Information("AssemblyVersion -> {0}", assemblyVersion);
159+
Information("AssemblyFileVersion -> {0}", assemblySemver);
160+
Information("AssemblyInformationalVersion -> {0}", assemblySemver);
161+
});
162+
163+
Task("__UpdateDotNetStandardAssemblyVersionNumber")
164+
.Does(() =>
165+
{
166+
Information("Updating Assembly Version Information");
167+
168+
var attributeToValueMap = new Dictionary<string, string>() {
169+
{ "AssemblyVersion", assemblyVersion },
170+
{ "FileVersion", assemblySemver },
171+
{ "InformationalVersion", assemblySemver },
172+
{ "Version", nugetVersion },
173+
{ "PackageVersion", nugetVersion },
174+
};
175+
176+
var csproj = File("./src/" + projectName + "/" + projectName + ".csproj");
177+
178+
foreach(var attributeMap in attributeToValueMap) {
179+
var attribute = attributeMap.Key;
180+
var value = attributeMap.Value;
181+
182+
var replacedFiles = ReplaceRegexInFiles(csproj, $@"\<{attribute}\>[^\<]*\</{attribute}\>", $@"<{attribute}>{value}</{attribute}>");
183+
if (!replacedFiles.Any())
184+
{
185+
throw new Exception($"{attribute} version could not be updated in {csproj}.");
186+
}
187+
}
188+
189+
});
190+
191+
Task("__UpdateAppVeyorBuildNumber")
192+
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
193+
.Does(() =>
194+
{
195+
AppVeyor.UpdateBuildVersion(appveyorBuildNumber);
196+
});
197+
198+
Task("__BuildSolutions")
199+
.Does(() =>
200+
{
201+
foreach(var solution in solutions)
202+
{
203+
Information("Building {0}", solution);
204+
205+
var dotNetCoreBuildSettings = new DotNetCoreBuildSettings {
206+
Configuration = configuration,
207+
Verbosity = DotNetCoreVerbosity.Minimal,
208+
NoRestore = true,
209+
MSBuildSettings = new DotNetCoreMSBuildSettings { TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error }
210+
};
211+
212+
DotNetCoreBuild(solution.ToString(), dotNetCoreBuildSettings);
213+
}
214+
});
215+
216+
Task("__RunTests")
217+
.Does(() =>
218+
{
219+
foreach(var specsProj in GetFiles("./src/**/*.Specs.csproj")) {
220+
DotNetCoreTest(specsProj.FullPath, new DotNetCoreTestSettings {
221+
Configuration = configuration,
222+
NoBuild = true
223+
});
224+
}
225+
});
226+
227+
Task("__CreateSignedNugetPackage")
228+
.Does(() =>
229+
{
230+
var packageName = projectName;
231+
232+
Information("Building {0}.{1}.nupkg", packageName, nugetVersion);
233+
234+
var dotNetCorePackSettings = new DotNetCorePackSettings {
235+
Configuration = configuration,
236+
NoBuild = true,
237+
OutputDirectory = nupkgDestDir
238+
};
239+
240+
DotNetCorePack($@"{srcDir}\{projectName}.sln", dotNetCorePackSettings);
241+
});
242+
243+
//////////////////////////////////////////////////////////////////////
244+
// BUILD TASKS
245+
//////////////////////////////////////////////////////////////////////
246+
247+
Task("Build")
248+
.IsDependentOn("__Clean")
249+
.IsDependentOn("__RestoreNugetPackages")
250+
.IsDependentOn("__UpdateAssemblyVersionInformation")
251+
.IsDependentOn("__UpdateDotNetStandardAssemblyVersionNumber")
252+
.IsDependentOn("__UpdateAppVeyorBuildNumber")
253+
.IsDependentOn("__BuildSolutions")
254+
.IsDependentOn("__RunTests")
255+
.IsDependentOn("__CreateSignedNugetPackage");
256+
257+
///////////////////////////////////////////////////////////////////////////////
258+
// PRIMARY TARGETS
259+
///////////////////////////////////////////////////////////////////////////////
260+
261+
Task("Default")
262+
.IsDependentOn("Build");
263+
264+
///////////////////////////////////////////////////////////////////////////////
265+
// EXECUTION
266+
///////////////////////////////////////////////////////////////////////////////
267+
268+
RunTarget(target);
269+
270+
//////////////////////////////////////////////////////////////////////
271+
// HELPER FUNCTIONS
272+
//////////////////////////////////////////////////////////////////////
273+
274+
string ToolsExePath(string exeFileName) {
275+
var exePath = System.IO.Directory.GetFiles(@"./tools", exeFileName, SearchOption.AllDirectories).FirstOrDefault();
276+
return exePath;
277+
}

0 commit comments

Comments
 (0)