forked from cake-build/cake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
222 lines (189 loc) · 6.71 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
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
220
221
222
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Get whether or not this is a local build.
var local = BuildSystem.IsLocalBuild;
var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
// Parse release notes.
var releaseNotes = ParseReleaseNotes("./ReleaseNotes.md");
// Get version.
var buildNumber = AppVeyor.Environment.Build.Number;
var version = releaseNotes.Version.ToString();
var semVersion = local ? version : (version + string.Concat("-build-", buildNumber));
// Define directories.
var buildDir = Directory("./src/Cake/bin") + Directory(configuration);
var buildResultDir = Directory("./build") + Directory("v" + semVersion);
var testResultsDir = buildResultDir + Directory("test-results");
var nugetRoot = buildResultDir + Directory("nuget");
var binDir = buildResultDir + Directory("bin");
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(() =>
{
Information("Building version {0} of Cake.", semVersion);
});
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectories(new DirectoryPath[] {
buildResultDir, binDir, testResultsDir, nugetRoot});
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore("./src/Cake.sln", new NuGetRestoreSettings {
Source = new List<string> {
"https://www.nuget.org/api/v2/",
"https://www.myget.org/F/roslyn-nightly/"
}
});
});
Task("Patch-Assembly-Info")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
var file = "./src/SolutionInfo.cs";
CreateAssemblyInfo(file, new AssemblyInfoSettings {
Product = "Cake",
Version = version,
FileVersion = version,
InformationalVersion = semVersion,
Copyright = "Copyright (c) Patrik Svensson, Mattias Karlsson and contributors"
});
});
Task("Build")
.IsDependentOn("Patch-Assembly-Info")
.Does(() =>
{
MSBuild("./src/Cake.sln", settings =>
settings.SetConfiguration(configuration)
.WithProperty("TreatWarningsAsErrors", "true")
.UseToolVersion(MSBuildToolVersion.NET45)
.SetVerbosity(Verbosity.Minimal)
.SetNodeReuse(false));
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
XUnit2("./src/**/bin/" + configuration + "/*.Tests.dll", new XUnit2Settings {
OutputDirectory = testResultsDir,
XmlReportV1 = true
});
});
Task("Copy-Files")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
CopyFileToDirectory(buildDir + File("Cake.exe"), binDir);
CopyFileToDirectory(buildDir + File("Cake.Core.dll"), binDir);
CopyFileToDirectory(buildDir + File("Cake.Core.xml"), binDir);
CopyFileToDirectory(buildDir + File("Cake.Core.pdb"), binDir);
CopyFileToDirectory(buildDir + File("Cake.Common.dll"), binDir);
CopyFileToDirectory(buildDir + File("Cake.Common.xml"), binDir);
CopyFileToDirectory(buildDir + File("Cake.Common.pdb"), binDir);
CopyFileToDirectory(buildDir + File("Mono.CSharp.dll"), binDir);
CopyFileToDirectory(buildDir + File("Autofac.dll"), binDir);
CopyFileToDirectory(buildDir + File("Nuget.Core.dll"), binDir);
CopyFiles(new FilePath[] { "LICENSE", "README.md", "ReleaseNotes.md" }, binDir);
});
Task("Zip-Files")
.IsDependentOn("Copy-Files")
.Does(() =>
{
var packageFile = File("Cake-bin-v" + semVersion + ".zip");
var packagePath = buildResultDir + packageFile;
Zip(binDir, packagePath);
});
Task("Create-NuGet-Packages")
.IsDependentOn("Copy-Files")
.Does(() =>
{
// Create Cake package.
NuGetPack("./nuspec/Cake.nuspec", new NuGetPackSettings {
Version = semVersion,
ReleaseNotes = releaseNotes.Notes.ToArray(),
BasePath = binDir,
OutputDirectory = nugetRoot,
Symbols = false,
NoPackageAnalysis = true
});
// Create Core package.
NuGetPack("./nuspec/Cake.Core.nuspec", new NuGetPackSettings {
Version = semVersion,
ReleaseNotes = releaseNotes.Notes.ToArray(),
BasePath = binDir,
OutputDirectory = nugetRoot,
Symbols = false
});
// Create Common package.
NuGetPack("./nuspec/Cake.Common.nuspec", new NuGetPackSettings {
Version = semVersion,
ReleaseNotes = releaseNotes.Notes.ToArray(),
BasePath = binDir,
OutputDirectory = nugetRoot,
Symbols = false
});
});
Task("Update-AppVeyor-Build-Number")
.WithCriteria(() => isRunningOnAppVeyor)
.Does(() =>
{
AppVeyor.UpdateBuildVersion(semVersion);
});
Task("Upload-AppVeyor-Artifacts")
.IsDependentOn("Package")
.WithCriteria(() => isRunningOnAppVeyor)
.Does(() =>
{
var artifact = buildResultDir + File("Cake-bin-v" + semVersion + ".zip");
AppVeyor.UploadArtifact(artifact);
});
Task("Publish-MyGet")
.WithCriteria(() => !local)
.WithCriteria(() => !isPullRequest)
.Does(() =>
{
// Resolve the API key.
var apiKey = EnvironmentVariable("MYGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet API key.");
}
foreach(var package in new[]{"Cake", "Cake.Core", "Cake.Common"})
{
// Get the path to the package.
var packagePath = nugetRoot + File(string.Concat(package, ".",semVersion,".nupkg"));
// Push the package.
NuGetPush(packagePath, new NuGetPushSettings {
Source = "https://www.myget.org/F/cake/api/v2/package",
ApiKey = apiKey
});
}
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Package")
.IsDependentOn("Zip-Files")
.IsDependentOn("Create-NuGet-Packages");
Task("Default")
.IsDependentOn("Package");
Task("AppVeyor")
.IsDependentOn("Update-AppVeyor-Build-Number")
.IsDependentOn("Upload-AppVeyor-Artifacts")
.IsDependentOn("Publish-MyGet");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);