/
build.cake
198 lines (173 loc) · 7.12 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
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var isLocalBuild = !AppVeyor.IsRunningOnAppVeyor;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
var isTag = AppVeyor.Environment.Repository.Tag.IsTag;
var solutions = GetFiles("./**/*.sln");
var solutionPaths = solutions.Select(solution => solution.GetDirectory());
var version = "0.1.0";
var binDir = "./src/Cake.Prompt/bin/" + configuration;
var nugetRoot = "./nuget/";
var semVersion = isLocalBuild
? version
: string.Concat(version, "-build-", AppVeyor.Environment.Build.Number);
var assemblyInfo = new AssemblyInfoSettings {
Title = "Cake.Prompt",
Description = "Cake Prompt AddIn",
Product = "Cake.Prompt",
Version = version,
FileVersion = version,
InformationalVersion = semVersion,
Copyright = string.Format("Copyright © Yves Schmid {0}", DateTime.Now.Year),
CLSCompliant = true
};
var nuGetPackSettings = new NuGetPackSettings {
Id = assemblyInfo.Product,
Version = assemblyInfo.InformationalVersion,
Title = assemblyInfo.Title,
Authors = new[] {"Yves Schmid"},
Owners = new[] {"Yves Schmid"},
Description = assemblyInfo.Description,
Summary = "Cake AddIn that extends Cake with user interactive prompt features",
ProjectUrl = new Uri("https://github.com/yvschmid/Cake.Prompt/"),
LicenseUrl = new Uri("https://github.com/yvschmid/Cake.Prompt/"),
Copyright = assemblyInfo.Copyright,
Tags = new [] {"Cake", "Script", "Build", "Prompt"},
RequireLicenseAcceptance= false,
Symbols = false,
NoPackageAnalysis = true,
Files = new [] {
new NuSpecContent {Source = "Cake.Prompt.dll"},
new NuSpecContent {Source = "Cake.Prompt.pdb"},
new NuSpecContent {Source = "Cake.Prompt.xml"}
},
BasePath = binDir,
OutputDirectory = nugetRoot
};
if (!isLocalBuild)
{
AppVeyor.UpdateBuildVersion(semVersion);
}
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(() =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
var buildStartMessage = string.Format(
"Building version {0} of {1} ({2}).",
version,
assemblyInfo.Product,
semVersion
);
Information(buildStartMessage);
});
Teardown(() =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
// Clean solution directories.
foreach(var path in solutionPaths)
{
Information("Cleaning {0}", path);
CleanDirectories(path + "/**/bin/" + configuration);
CleanDirectories(path + "/**/obj/" + configuration);
}
});
Task("Restore")
.Does(() =>
{
// Restore all NuGet packages.
foreach(var solution in solutions)
{
Information("Restoring {0}...", solution);
NuGetRestore(solution);
}
});
Task("SolutionInfo")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
var file = "./src/SolutionInfo.cs";
CreateAssemblyInfo(file, assemblyInfo);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("SolutionInfo")
.Does(() =>
{
// Build all solutions.
foreach(var solution in solutions)
{
Information("Building {0}", solution);
MSBuild(solution, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.WithProperty("TreatWarningsAsErrors","true")
.WithTarget("Build")
.SetConfiguration(configuration));
}
});
Task("Create-NuGet-Package")
.IsDependentOn("Build")
.Does(() =>
{
if (!DirectoryExists(nugetRoot))
{
CreateDirectory(nugetRoot);
}
NuGetPack(nuGetPackSettings);
});
Task("Publish-To-MyGet")
.IsDependentOn("Create-NuGet-Package")
.WithCriteria(() => !isLocalBuild)
.WithCriteria(() => !isPullRequest)
.Does(() =>
{
var apiKey = EnvironmentVariable("MYGET_API_KEY");
var source = EnvironmentVariable("MYGET_SOURCE");
var package = nugetRoot + "Cake.Prompt." + semVersion + ".nupkg";
NuGetPush(package, new NuGetPushSettings {
Source = source,
ApiKey = apiKey
});
});
Task("Publish-To-NuGet")
.IsDependentOn("Create-NuGet-Package")
.WithCriteria(() => !isLocalBuild)
.WithCriteria(() => !isPullRequest)
.WithCriteria(() => isTag)
.Does(() =>
{
var apiKey = EnvironmentVariable("NUGET_API_KEY");
var source = EnvironmentVariable("NUGET_SOURCE");
var package = nugetRoot + "/Cake.Prompt." + semVersion + ".nupkg";
NuGetPush(package, new NuGetPushSettings {
Source = source,
ApiKey = apiKey
});
});
Task("Default")
.IsDependentOn("Create-NuGet-Package");
Task("AppVeyor")
.IsDependentOn("Publish-To-MyGet")
.IsDependentOn("Publish-To-NuGet");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);