forked from IdentityServer/IdentityServer4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
224 lines (189 loc) · 6.63 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
#tool "nuget:https://api.nuget.org/v3/index.json?package=GitVersion.CommandLine"
var target = Argument("target", "Default");
var configuration = Argument<string>("configuration", "Release");
// 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();
DotNetCoreMSBuildSettings msBuildSettings;
VersionInfo versions;
///////////////////////////////////////////////////////////////////////////////
// Setup
///////////////////////////////////////////////////////////////////////////////
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
};
var projects = GetFiles("./src/**/*.csproj");
foreach(var project in projects)
{
DotNetCoreBuild(project.GetDirectory().FullPath, settings);
}
if (!isWindows)
{
Information("Not running on Windows - skipping building tests for .NET Framework");
settings.Framework = "netcoreapp2.1";
}
var tests = GetFiles("./test/**/*.csproj");
foreach(var test in tests)
{
DotNetCoreBuild(test.GetDirectory().FullPath, settings);
}
});
///////////////////////////////////////////////////////////////////////////////
// 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);
});
private bool SkipPack()
{
if (!isWindows)
{
Information("Skipping pack because not on Windows.");
return true;
}
if (String.IsNullOrEmpty(versions.PreReleaseLabel) && versions.BranchName != "master")
{
Information("Skipping pack of release version, because not on master.");
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;
}
Task("Default")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Pack");
RunTarget(target);