forked from Lachee/discord-rpc-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
225 lines (201 loc) · 6.16 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
// Addins
#addin nuget:?package=Cake.FileHelpers
#addin nuget:?package=Cake.Git
#addin nuget:?package=Cake.VersionReader
// Adjustable Variables
var projectName = "DiscordRPC";
// Arguments
var target = Argument ("target", "Default");
var buildType = Argument<string>("buildType", "Release");
var buildCounter = Argument<int>("buildCounter", 0);
var buildTag = Argument<string>("buildTag", "v1.0");
var signCertificate = Argument<string>("signCertificate", "certificate.pfx");
var signPassword = Argument<string>("signPassword", "");
// Project Variables
var asm = string.Format("./{0}/Properties/AssemblyInfo.cs", projectName);
var sln = string.Format("./{0}/{0}.sln", projectName);
var releaseFolder = string.Format("./{0}/bin/{1}/net35", projectName, buildType);
var releaseDll = "/DiscordRPC.dll";
var nuspecFile = string.Format("./{0}/{0}.nuspec", projectName);
// Execution Variables
var major_version = buildTag.Trim('v');
var version = major_version + "." + buildCounter.ToString() + ".0";
var ciVersion = major_version + ".0-CI00000";
var runningOnTeamCity = false;
var runningOnAppVeyor = false;
// Find out if we are running on a Build Server
Task ("DiscoverBuildDetails")
.Does (() =>
{
runningOnTeamCity = TeamCity.IsRunningOnTeamCity;
Information("Running on TeamCity: " + runningOnTeamCity);
runningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
Information("Running on AppVeyor: " + runningOnAppVeyor);
});
// Outputs Argument values so they are visible in the build log
Task ("OutputVariables")
.Does (() =>
{
Information("BuildType: " + buildType);
Information("BuildCounter: " + buildCounter);
Information("BuildTag: " + buildTag);
Information("MajorVersion: " + major_version);
Information("BuildVersion: " + version);
Information("CIVersion: " + ciVersion);
});
Task("SetVersion")
.Does(() => {
//version = major_version + "." + buildCounter.ToString() + ".0";
Information("Version: " + version);
ReplaceRegexInFiles(asm, "(?<=AssemblyVersion\\(\")(.+?)(?=\"\\))", version);
ReplaceRegexInFiles(asm, "(?<=Version\\(\")(.+?)(?=\"\\))", version);
});
// Builds the code
Task ("Build")
.Does (() => {
//Build 64bit versions of the solution
MSBuild (sln, new MSBuildSettings
{
Verbosity = Verbosity.Quiet,
Configuration = buildType
}.WithProperty("build", buildCounter.ToString())
.UseToolVersion(MSBuildToolVersion.VS2019));
var file = MakeAbsolute(Directory(releaseFolder)) + releaseDll;
version = GetVersionNumber(file);
ciVersion = GetVersionNumberWithContinuesIntegrationNumberAppended(file, buildCounter);
Information("Version: " + version);
Information("CI Version: " + ciVersion);
PushVersion(ciVersion);
});
// Create Nuget Package
Task ("Nuget")
.WithCriteria (buildType == "Release")
.Does (() => {
CreateDirectory ("./nupkg/");
ReplaceRegexInFiles(nuspecFile, "0.0.0", version);
NuGetPack (nuspecFile, new NuGetPackSettings {
Verbosity = NuGetVerbosity.Detailed,
OutputDirectory = "./nupkg/"
});
});
// Restore Nuget packages
Task ("NugetRestore")
.Does (() => {
var blockText = "Nuget Restore";
StartBlock(blockText);
NuGetRestore(sln);
EndBlock(blockText);
});
//Push to Nuget
Task ("Push")
.WithCriteria (buildType == "Release")
.Does (() => {
// Get the newest (by last write time) to publish
var newestNupkg = GetFiles ("nupkg/*.nupkg")
.OrderBy (f => new System.IO.FileInfo (f.FullPath).LastWriteTimeUtc)
.LastOrDefault();
var apiKey = EnvironmentVariable("NugetKey");
NuGetPush (newestNupkg, new NuGetPushSettings {
Verbosity = NuGetVerbosity.Detailed,
Source = "https://www.nuget.org/api/v2/package/",
ApiKey = apiKey
});
});
Task ("Sign")
.IsDependentOn("Build")
.Does(() => {
if (!String.IsNullOrEmpty(signPassword))
{
Information("Signing Assembly");
var file = MakeAbsolute(Directory(releaseFolder)) + releaseDll;
var asmb = new FilePath(file);
Sign(asmb, new SignToolSignSettings {
Description = "Signed by Lachee during a automated build",
TimeStampUri = new Uri("http://timestamp.digicert.com"),
CertPath = signCertificate,
Password = signPassword
});
}
else
{
Information("Skipping Signing");
}
});
Task ("Default")
.IsDependentOn ("OutputVariables")
.IsDependentOn ("DiscoverBuildDetails")
.IsDependentOn ("NugetRestore")
.IsDependentOn ("SetVersion")
.IsDependentOn ("Build");
Task ("NugetBuild")
.IsDependentOn ("OutputVariables")
.IsDependentOn ("DiscoverBuildDetails")
.IsDependentOn ("NugetRestore")
.IsDependentOn ("SetVersion")
.IsDependentOn ("Build")
.IsDependentOn ("Sign")
.IsDependentOn ("Nuget");
Task ("NugetBuildPush")
.IsDependentOn ("OutputVariables")
.IsDependentOn ("DiscoverBuildDetails")
.IsDependentOn ("NugetRestore")
.IsDependentOn ("SetVersion")
.IsDependentOn ("Build")
.IsDependentOn ("Sign")
.IsDependentOn ("Nuget")
.IsDependentOn ("Push");
RunTarget (target);
// Code to start a TeamCity log block
public void StartBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteStartBlock(blockName);
}
}
// Code to start a TeamCity build block
public void StartBuildBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteStartBuildBlock(blockName);
}
}
// Code to end a TeamCity log block
public void EndBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteEndBlock(blockName);
}
}
// Code to end a TeamCity build block
public void EndBuildBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteEndBuildBlock(blockName);
}
}
// Code to push the Version number to the build system
public void PushVersion(string version)
{
if(runningOnTeamCity)
{
TeamCity.SetBuildNumber(version);
}
if(runningOnAppVeyor)
{
Information("Pushing version to AppVeyor: " + version);
AppVeyor.UpdateBuildVersion(version);
}
}
// Code to push the Test Results to AppVeyor for display purposess
public void PushTestResults(string filePath)
{
var file = MakeAbsolute(File(filePath));
if(runningOnAppVeyor)
{
AppVeyor.UploadTestResults(file, AppVeyorTestResultsType.NUnit3);
}
}