forked from OctopusDeploy/Calamari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
192 lines (166 loc) · 6.37 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
//////////////////////////////////////////////////////////////////////
// TOOLS
//////////////////////////////////////////////////////////////////////
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0-beta0011"
using Path = System.IO.Path;
using System.Xml;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var testFilter = Argument("where", "");
var signingCertificatePath = Argument("signing_certificate_path", "");
var signingCertificatePassword = Argument("signing_certificate_password", "");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var localPackagesDir = "../LocalPackages";
var sourceFolder = "./source/";
var artifactsDir = "./artifacts";
var publishDir = "./publish";
GitVersion gitVersionInfo;
string nugetVersion;
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
gitVersionInfo = GitVersion(new GitVersionSettings {
OutputType = GitVersionOutput.Json
});
nugetVersion = gitVersionInfo.NuGetVersion;
Information("Building Calamari v{0}", nugetVersion);
});
Teardown(context =>
{
Information("Finished running tasks.");
});
//////////////////////////////////////////////////////////////////////
// PRIVATE TASKS
//////////////////////////////////////////////////////////////////////
Task("SetTeamCityVersion")
.Does(() => {
if(BuildSystem.IsRunningOnTeamCity)
BuildSystem.TeamCity.SetBuildNumber(gitVersionInfo.NuGetVersion);
});
Task("Clean")
.IsDependentOn("SetTeamCityVersion")
.Does(() =>
{
CleanDirectories(publishDir);
CleanDirectories(artifactsDir);
CleanDirectories("./**/bin");
CleanDirectories("./**/obj");
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() => DotNetCoreRestore("source", new DotNetCoreRestoreSettings
{
ArgumentCustomization = args => args.Append($"--verbosity normal")
}));
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetCoreBuild("./source/Calamari.sln", new DotNetCoreBuildSettings
{
Configuration = configuration,
ArgumentCustomization = args => args.Append($"/p:Version={nugetVersion}").Append($"--verbosity normal")
});
});
Task("Test")
.IsDependentOn("Build")
.Does(() => {
var projects = GetFiles("./source/**/*Tests.csproj");
foreach(var project in projects)
DotNetCoreTest(project.FullPath, new DotNetCoreTestSettings
{
Configuration = configuration,
NoBuild = true,
ArgumentCustomization = args => {
if(!string.IsNullOrEmpty(testFilter)) {
args = args.Append("--where").AppendQuoted(testFilter);
}
return args.Append("--logger:trx")
.Append($"--verbosity normal");
}
});
});
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
DoPackage("Calamari", "net40", nugetVersion);
DoPackage("Calamari.Azure", "net451", nugetVersion);
Zip("./source/Calamari.Tests/bin/Release/net452/", Path.Combine(artifactsDir, "Binaries.zip"));
// Create a portable .NET Core package
DoPackage("Calamari", "netcoreapp2.0", nugetVersion, "portable");
// Create the self-contained Calamari packages for each runtime ID defined in Calamari.csproj
foreach(var rid in GetProjectRuntimeIds(@".\source\Calamari\Calamari.csproj"))
{
DoPackage("Calamari", "netcoreapp2.0", nugetVersion, rid);
}
});
Task("CopyToLocalPackages")
.WithCriteria(BuildSystem.IsLocalBuild)
.IsDependentOn("Pack")
.Does(() =>
{
CreateDirectory(localPackagesDir);
CopyFiles(Path.Combine(artifactsDir, $"Calamari.*.nupkg"), localPackagesDir);
});
private void DoPackage(string project, string framework, string version, string runtimeId = null)
{
var publishedTo = Path.Combine(publishDir, project, framework);
var projectDir = Path.Combine("./source", project);
var packageId = $"{project}";
var nugetPackProperties = new Dictionary<string,string>();
var publishSettings = new DotNetCorePublishSettings
{
Configuration = configuration,
OutputDirectory = publishedTo,
Framework = framework,
ArgumentCustomization = args => args.Append($"/p:Version={nugetVersion}").Append($"--verbosity normal")
};
if (!string.IsNullOrEmpty(runtimeId))
{
publishedTo = Path.Combine(publishedTo, runtimeId);
publishSettings.OutputDirectory = publishedTo;
// "portable" is not an actual runtime ID. We're using it to represent the portable .NET core build.
publishSettings.Runtime = (runtimeId != null && runtimeId != "portable") ? runtimeId : null;
packageId = $"{project}.{runtimeId}";
nugetPackProperties.Add("runtimeId", runtimeId);
}
var nugetPackSettings = new NuGetPackSettings
{
Id = packageId,
OutputDirectory = artifactsDir,
BasePath = publishedTo,
Version = nugetVersion,
Verbosity = NuGetVerbosity.Normal,
Properties = nugetPackProperties
};
DotNetCorePublish(projectDir, publishSettings);
var nuspec = $"{publishedTo}/{packageId}.nuspec";
CopyFile($"{projectDir}/{project}.nuspec", nuspec);
NuGetPack(nuspec, nugetPackSettings);
}
// Returns the runtime identifiers from the project file
private IEnumerable<string> GetProjectRuntimeIds(string projectFile)
{
var doc = new XmlDocument();
doc.Load(projectFile);
var rids = doc.SelectSingleNode("Project/PropertyGroup/RuntimeIdentifiers").InnerText;
return rids.Split(';');
}
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("SetTeamCityVersion")
.IsDependentOn("CopyToLocalPackages");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);