-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.cake
184 lines (150 loc) · 5.08 KB
/
build.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#tool nuget:?package=NUnit.ConsoleRunner
#l "settingsUtils.cake"
#l "versionUtils.cake"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Define directories.
var buildDir = Directory("./Source/bin") + Directory(configuration);
var solution = "./Source/FountainSharp.sln";
var solutionDir = System.IO.Path.GetDirectoryName(solution);
var versionInfo = VersionUtils.LoadVersion(Context);
var settings = SettingsUtils.LoadSettings(Context);
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Setup((c) =>
{
c.Information("Command Line:");
c.Information("\tSolution: {0}", solution);
c.Information("\tSolution directory: {0}", solutionDir);
// Executed BEFORE the first task.
settings.Display(c);
versionInfo.Display(c);
});
Task("Clean")
.Does(() =>
{
CleanDirectory(buildDir);
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
Information("Restoring {0}...", solution);
// Nuget v3 restore does not work for project.json type projects on Unix-like systems
// Restore for projects using packages.config
NuGetRestore(solution, new NuGetRestoreSettings { Verbosity = NuGetVerbosity.Detailed });
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
// Use MSBuild
MSBuild(solution, buildSettings => buildSettings.SetConfiguration(configuration));
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
var fileExtensions = new[] { "exe", "dll" };
foreach (var fileExtension in fileExtensions)
{
NUnit3(solutionDir + "/**/bin/" + configuration + "/*.Tests." + fileExtension, new NUnit3Settings {
NoResults = true
});
}
});
Task("Package")
.Description("Packages all nuspec files into nupkg packages.")
// .IsDependentOn("Build")
.Does(() =>
{
CreateDirectory(settings.NuGet.ArtifactsPath);
Information("Nuspec path: " + settings.NuGet.NuSpecPath);
var nugetProps = new Dictionary<string, string>() { {"Configuration", configuration} };
var nuSpecFiles = GetFiles(settings.NuGet.NuSpecFileSpec);
foreach (var nsf in nuSpecFiles)
{
Information("Packaging {0}", nsf);
// if (buildSettings.NuGet.UpdateVersion)
// {
// VersionUtils.UpdateNuSpecVersion(Context, buildSettings, versionInfo, nsf.ToString());
// }
// VersionUtils.UpdateNuSpecVersionDependency(Context, buildSettings, versionInfo, nsf.ToString());
NuGetPack(nsf, new NuGetPackSettings {
Version = versionInfo.ToString(),
//ReleaseNotes = versionInfo.ReleaseNotes,
Symbols = true,
Properties = nugetProps,
OutputDirectory = settings.NuGet.ArtifactsPath,
ArgumentCustomization = args => args.Append("-NoDefaultExcludes")
});
}
});
Task("Publish")
.Description("Publishes all of the nupkg packages to the nuget server. ")
.IsDependentOn("Package")
.Does(() =>
{
var nupkgFiles = GetFiles(settings.NuGet.NuGetPackagesSpec);
foreach(var pkg in nupkgFiles)
{
// Lets skip everything except the current version and we can skip the symbols pkg for now
if (!pkg.ToString().Contains(versionInfo.ToString()) || pkg.ToString().Contains("symbols")) {
Information("Skipping {0}", pkg);
continue;
}
Information("Publishing {0}", pkg);
var nugetSettings = new NuGetPushSettings
{
Source = settings.NuGet.FeedUrl,
Verbosity = NuGetVerbosity.Detailed
};
if (FileExists(settings.NuGet.NuGetConfig))
nugetSettings.ConfigFile = settings.NuGet.NuGetConfig;
if (!string.IsNullOrEmpty(settings.NuGet.FeedApiKey))
{
nugetSettings.ApiKey = settings.NuGet.FeedApiKey;
}
NuGetPush(pkg, nugetSettings);
}
});
Task("IncrementVersion")
.Description("Increments the version number and then updates it in the necessary files")
.Does(() =>
{
var oldVer = versionInfo.ToString();
if (versionInfo.IsPreRelease) versionInfo.PreRelease++; else versionInfo.Build++;
Information("Incrementing Version {0} to {1}", oldVer, versionInfo.ToString());
VersionUtils.UpdateVersion(Context, versionInfo);
});
Task("BuildNewVersion")
.Description("Increments and Builds a new version")
.IsDependentOn("IncrementVersion")
.IsDependentOn("Build")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
});
Task("PublishNewVersion")
.Description("Increments, Builds, and publishes a new version")
.IsDependentOn("BuildNewVersion")
.IsDependentOn("Publish")
.Does(() =>
{
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Run-Unit-Tests");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);