This repository was archived by the owner on Aug 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.csx
205 lines (170 loc) · 6.24 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
#l "build/utilities.csx"
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Debug");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var projectName = "Tamarind";
var projectDescription = "C# port of Google's Guava library";
var projectAuthors = new [] { "Jordan S. Jones", "Esteban Araya" };
// Directories
// WorkingDirectory is relative to this file. Make it relative to the Solution file.
var baseDir = GetContext().Environment.WorkingDirectory;
var packagingRoot = baseDir.Combine("Packaging");
var testResultsDir = baseDir.Combine("TestResults");
var tamarindPackagingDir = packagingRoot.Combine(projectName);
// Files
var solutionInfoCs = baseDir.Combine("build").GetFilePath("SolutionInfo.cs");
var nuspecFile = baseDir.Combine("build").GetFilePath(projectName + ".nuspec");
var solution = baseDir.GetFilePath(projectName + ".sln");
var solutionDir = solution.GetDirectory();
// Get whether or not this is a local build.
var local = IsLocalBuild();
var isReleaseBuild = IsReleaseBuild();
// Release notes
var releaseNotes = ParseReleaseNotes(baseDir.GetFilePath("ReleaseNotes.md"));
// Version
var buildNumber = GetBuildNumber();
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...");
});
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);
CleanDirectories(dir.FullPath);
}
});
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("UnitTests")
.IsDependentOn("Build")
.Does(() =>
{
Information("Running Tests in {0}", solution);
XUnit2(
solutionDir + "/**/bin/" + configuration + "/**/*.Tests*.dll",
new XUnit2Settings {
OutputDirectory = testResultsDir,
HtmlReport = true
}
);
});
Task("CopyTamarindPackageFiles")
.IsDependentOn("UnitTests")
.WithCriteria(() => isReleaseBuild)
.Does(() =>
{
var baseBuildDir = solutionDir.Combine(projectName).Combine("bin").Combine(configuration);
var net45BuildDir = baseBuildDir.Combine("Net45");
var net45PackageDir = tamarindPackagingDir.Combine("lib/net45/");
var netcore45BuildDir = baseBuildDir.Combine("NetCore45");
var netcore45PackageDir = tamarindPackagingDir.Combine("lib/netcore45/");
var portableBuildDir = baseBuildDir.Combine("Portable-net45+win+wpa81+wp80");
var portablePackageDir = tamarindPackagingDir.Combine("lib/portable-net45+wp80+win+wpa81/");
var dirMap = new Dictionary<DirectoryPath, DirectoryPath> {
{ net45BuildDir, net45PackageDir },
{ netcore45BuildDir, netcore45PackageDir },
{ portableBuildDir, portablePackageDir }
};
CleanDirectories(dirMap.Values);
foreach (var dirPair in dirMap)
{
var files = new DirectoryInfo(dirPair.Key.FullPath)
.EnumerateFiles()
.Select(x => new FilePath(x.FullName));
CopyFiles(files, dirPair.Value);
}
var packageFiles = new FilePath[] {
solutionDir.CombineWithFilePath("LICENSE.txt"),
solutionDir.CombineWithFilePath("README.md"),
solutionDir.CombineWithFilePath("ReleaseNotes.md")
};
CopyFiles(packageFiles, tamarindPackagingDir);
});
Task("CreateTamarindPackage")
.IsDependentOn("CopyTamarindPackageFiles")
.WithCriteria(() => isReleaseBuild)
.Does(() =>
{
NuGetPack(
nuspecFile,
new NuGetPackSettings {
Id = projectName,
Title = projectName,
Authors = projectAuthors.ToList(),
Summary = projectDescription,
Description = projectDescription,
Version = semVersion,
ReleaseNotes = releaseNotes.Notes.ToArray(),
BasePath = tamarindPackagingDir,
OutputDirectory = packagingRoot,
Symbols = false,
NoPackageAnalysis = false
}
);
});
///////////////////////////////////////////////////////////////////////////////
// TASK TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("Package")
.IsDependentOn("CreateTamarindPackage");
Task("Default")
.IsDependentOn("Package");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
Information("Building {0} [{1}] ({2} - {3}).", solution.GetFilename(), configuration, version, semVersion);
RunTarget(target);