This repository has been archived by the owner on Mar 20, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
build.cake
294 lines (248 loc) · 8.47 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#tool "nuget:https://api.nuget.org/v3/index.json?package=GitVersion.CommandLine"
var target = Argument("target", "Default");
var configuration = Argument<string>("configuration", "Release");
var sign = Argument<bool>("sign", false);
// call e.g. .\build.ps1 --release=1.0.0 --pre=beta1
// call e.g. .\build.ps1 --release=1.0.0
var versionOverride = Argument<string>("release", "");
var suffixOverride = Argument<string>("pre", "");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var packPath = Directory("./src");
var buildArtifacts = Directory("./artifacts");
var isAppVeyor = AppVeyor.IsRunningOnAppVeyor;
var isVsts = TFBuild.IsRunningOnVSTS;
var isWindows = IsRunningOnWindows();
///////////////////////////////////////////////////////////////////////////////
// Setup
///////////////////////////////////////////////////////////////////////////////
DotNetCoreMSBuildSettings msBuildSettings;
VersionInfo versions;
class VersionInfo
{
public string AssemblyVersion { get; set; }
public string VersionSuffix { get; set; }
public string FileVersion { get; set; }
public string InformationalVersion { get; set; }
public string BranchName { get; set; }
public string PreReleaseLabel { get; set; }
}
Setup(context =>
{
// only calculate versions if on Windows
// due to problems with GitVersion in the current setup - but also since Windows is our release platform anyways
if (isWindows)
{
var gitVersions = Context.GitVersion();
versions = new VersionInfo
{
InformationalVersion = gitVersions.InformationalVersion,
BranchName = gitVersions.BranchName,
PreReleaseLabel = gitVersions.PreReleaseLabel
};
// explicit version has been passed in as argument
if (!string.IsNullOrEmpty(versionOverride))
{
versions.AssemblyVersion = versionOverride;
versions.FileVersion = versionOverride;
if (!string.IsNullOrEmpty(suffixOverride))
{
versions.VersionSuffix = suffixOverride;
}
}
else
{
versions.AssemblyVersion = gitVersions.AssemblySemVer;
versions.FileVersion = gitVersions.AssemblySemVer;
if (!string.IsNullOrEmpty(versions.PreReleaseLabel))
{
versions.VersionSuffix = gitVersions.PreReleaseLabel + gitVersions.CommitsSinceVersionSourcePadded;
}
}
Information("branch : " + versions.BranchName);
Information("pre-release label : " + versions.PreReleaseLabel);
Information("version : " + versions.AssemblyVersion);
Information("version suffix : " + versions.VersionSuffix);
Information("informational : " + versions.InformationalVersion);
msBuildSettings = GetMSBuildSettings();
}
else
{
Information("Skipping version calculation because not on Windows.");
msBuildSettings = null;
}
});
///////////////////////////////////////////////////////////////////////////////
// Clean
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectories(new DirectoryPath[] { buildArtifacts });
});
///////////////////////////////////////////////////////////////////////////////
// Build
///////////////////////////////////////////////////////////////////////////////
Task("Build")
.IsDependentOn("Clean")
.Does(() =>
{
var settings = new DotNetCoreBuildSettings
{
Configuration = configuration,
MSBuildSettings = msBuildSettings
};
// building projects
if (!isWindows)
{
Information("Not running on Windows - building source for netstandard2.0");
settings.Framework = "netstandard2.0";
}
var projects = GetFiles("./src/**/*.csproj");
foreach(var project in projects)
{
DotNetCoreBuild(project.GetDirectory().FullPath, settings);
}
// building tests
if (!isWindows)
{
Information("Not running on Windows - building tests for netcoreapp2.1");
settings.Framework = "netcoreapp2.1";
}
var tests = GetFiles("./test/**/*.csproj");
foreach(var test in tests)
{
DotNetCoreBuild(test.GetDirectory().FullPath, settings);
}
// authenticode sign assemblies
if (sign)
{
var dlls = GetFiles("./src/bin/release/**/IdentityServer4*.dll");
foreach(var dll in dlls)
{
SignFile(dll.FullPath);
}
}
});
///////////////////////////////////////////////////////////////////////////////
// Test
///////////////////////////////////////////////////////////////////////////////
Task("Test")
.IsDependentOn("Clean")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new DotNetCoreTestSettings
{
Configuration = configuration,
NoBuild = true
};
if (!isWindows)
{
Information("Not running on Windows - skipping tests for .NET Framework");
settings.Framework = "netcoreapp2.1";
}
var projects = GetFiles("./test/**/*.csproj");
foreach(var project in projects)
{
DotNetCoreTest(project.FullPath, settings);
}
});
///////////////////////////////////////////////////////////////////////////////
// Pack
///////////////////////////////////////////////////////////////////////////////
Task("Pack")
.IsDependentOn("Clean")
.IsDependentOn("Build")
.Does(() =>
{
if (SkipPack()) return;
var settings = new DotNetCorePackSettings
{
Configuration = configuration,
MSBuildSettings = msBuildSettings,
OutputDirectory = buildArtifacts + Directory("packages"),
NoBuild = true
};
DotNetCorePack(packPath, settings);
if (sign)
{
var packages = GetFiles("./artifacts/**/*.nupkg");
foreach(var package in packages)
{
SignFile(package.FullPath);
}
}
});
///////////////////////////////////////////////////////////////////////////////
// Helpers
///////////////////////////////////////////////////////////////////////////////
private bool SkipPack()
{
if (!isWindows)
{
Information("Skipping pack because not on Windows.");
return true;
}
if (String.IsNullOrEmpty(versions.PreReleaseLabel) && versions.BranchName == "dev")
{
Information("Skipping pack of release version, because on dev.");
return true;
}
if (versions.PreReleaseLabel == "PullRequest")
{
Information("Skipping pack for pull requests.");
return true;
}
return false;
}
private DotNetCoreMSBuildSettings GetMSBuildSettings()
{
var settings = new DotNetCoreMSBuildSettings();
settings.WithProperty("AssemblyVersion", versions.AssemblyVersion);
settings.WithProperty("VersionPrefix", versions.AssemblyVersion);
settings.WithProperty("FileVersion", versions.FileVersion);
settings.WithProperty("InformationalVersion", versions.InformationalVersion);
if (!String.IsNullOrEmpty(versions.VersionSuffix))
{
settings.WithProperty("VersionSuffix", versions.VersionSuffix);
}
return settings;
}
private void SignFile(string fileName)
{
var signClientConfig = EnvironmentVariable("SignClientConfig") ?? "";
var signClientSecret = EnvironmentVariable("SignClientSecret") ?? "";
if (signClientConfig == "")
{
throw new Exception("SignClientConfig environment variable is missing. Aborting.");
}
if (signClientSecret == "")
{
throw new Exception("SignClientSecret environment variable is missing. Aborting.");
}
Information(" Signing " + fileName);
var success = StartProcess("./tools/signclient", new ProcessSettings {
Arguments = new ProcessArgumentBuilder()
.Append("sign")
.Append($"-c {signClientConfig}")
.Append($"-i {fileName}")
.Append("-r [email protected]")
.Append($"-s {signClientSecret}")
.Append(@"-n 'IdentityServer4'")
});
if (success == 0)
{
Information(" success.");
}
else
{
throw new Exception("Error signing " + fileName);
}
}
Task("Default")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Pack");
RunTarget(target);