forked from jordansjones/Swasey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.csx
219 lines (181 loc) · 6.18 KB
/
build.csx
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Debug");
var forcePackage = HasArgument("forcePackage");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var projectName = "Swasey";
// "Root"
var baseDir = Context.Environment.WorkingDirectory;
var solution = baseDir.GetFilePath(projectName + ".sln");
// Directories
// WorkingDirectory is relative to this file. Make it relative to the Solution file.
var solutionDir = solution.GetDirectory();
var packagingRoot = baseDir.Combine("publish");
var testResultsDir = baseDir.Combine("TestResults");
var nugetPackagingDir = packagingRoot.Combine(projectName);
var sourcesDir = solutionDir.Combine("src");
var testsDir = solutionDir.Combine("tests");
var metaDir = solutionDir.Combine("meta");
// Files
var solutionInfoCs = metaDir.GetFilePath("SolutionInfo.cs");
var nuspecFile = metaDir.GetFilePath(projectName + ".nuspec");
var licenseFile = solutionDir.GetFilePath("LICENSE.txt");
var readmeFile = solutionDir.GetFilePath("README.md");
var releaseNotesFile = metaDir.GetFilePath("ReleaseNotes.md");
var appVeyorEnv = Context.AppVeyor().Environment;
// Get whether or not this is a local build.
var local = !Context.BuildSystem().IsRunningOnAppVeyor;
var isReleaseBuild = !local && appVeyorEnv.Repository.Tag.IsTag;
// Release notes
var releaseNotes = ParseReleaseNotes(releaseNotesFile);
// Version
var buildNumber = !isReleaseBuild ? 0 : appVeyorEnv.Build.Number;
var version = releaseNotes.Version.ToString();
var semVersion = isReleaseBuild ? version : (version + string.Concat("-build-", buildNumber));
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(() =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
if (!DirectoryExists(testResultsDir))
{
CreateDirectory(testResultsDir);
}
if (!DirectoryExists(nugetPackagingDir))
{
CreateDirectory(nugetPackagingDir);
}
});
Teardown(() =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
// Clean Solution directories
Information("Cleaning {0}", solutionDir);
CleanDirectories(solutionDir + "/packages");
CleanDirectories(solutionDir + "/**/bin/" + configuration);
CleanDirectories(solutionDir + "/**/obj/" + configuration);
foreach (var dir in new [] { packagingRoot, testResultsDir })
{
Information("Cleaning {0}", dir);
CleanDirectory(dir);
}
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
Information("Restoring {0}", solution);
NuGetRestore(solution);
});
Task("AssemblyInfo")
.IsDependentOn("Restore")
.WithCriteria(() => !isReleaseBuild)
.Does(() =>
{
Information("Creating {0} - Version: {1}", solutionInfoCs, version);
CreateAssemblyInfo(solutionInfoCs, new AssemblyInfoSettings {
Product = projectName,
Version = version,
FileVersion = version,
InformationalVersion = semVersion
});
});
Task("Build")
.IsDependentOn("AssemblyInfo")
.Does(() =>
{
Information("Building {0}", solution);
MSBuild(solution, settings =>
settings.SetConfiguration(configuration)
);
});
Task("InstallUnitTestRunner")
.Does(() =>
{
NuGetInstall("xunit.runner.console", new NuGetInstallSettings {
ExcludeVersion = true,
OutputDirectory = solutionDir.Combine("tools"),
Version = "2.0.0"
});
});
Task("UnitTests")
.IsDependentOn("Build")
.IsDependentOn("InstallUnitTestRunner")
.Does(() =>
{
Information("Running Tests in {0}", solution);
XUnit2(
solutionDir + "/**/bin/" + configuration + "/**/*.Tests*.dll",
new XUnit2Settings {
OutputDirectory = testResultsDir,
HtmlReport = true,
XmlReport = true
}
);
});
Task("CopyNugetPackageFiles")
.IsDependentOn("UnitTests")
.Does(() =>
{
var baseBuildDir = sourcesDir.Combine(projectName).Combine("bin").Combine(configuration);
var net45BuildDir = baseBuildDir.Combine("Net45");
var net45PackageDir = nugetPackagingDir.Combine("lib/net45/");
var dirMap = new Dictionary<DirectoryPath, DirectoryPath> {
{ net45BuildDir, net45PackageDir }
};
CleanDirectories(dirMap.Values);
foreach (var dirPair in dirMap)
{
var files = GetFiles(dirPair.Key + "/" + projectName + "*");
CopyFiles(files, dirPair.Value);
}
var packageFiles = new FilePath[] {
licenseFile,
readmeFile,
releaseNotesFile
};
CopyFiles(packageFiles, nugetPackagingDir);
});
Task("CreateNugetPackage")
.IsDependentOn("CopyNugetPackageFiles")
.Does(() =>
{
NuGetPack(
nuspecFile,
new NuGetPackSettings {
Version = semVersion,
ReleaseNotes = releaseNotes.Notes.ToArray(),
BasePath = nugetPackagingDir,
OutputDirectory = packagingRoot,
Symbols = false,
NoPackageAnalysis = false
}
);
});
///////////////////////////////////////////////////////////////////////////////
// TASK TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("Package")
.IsDependentOn("CreateNugetPackage")
.WithCriteria(() => isReleaseBuild || forcePackage);
Task("Default")
.IsDependentOn("Package");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
Information("Building {0} [{1}] ({2} - {3}).", solution.GetFilename(), configuration, version, semVersion);
RunTarget(target);