-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.cake
More file actions
188 lines (152 loc) · 4.16 KB
/
build.cake
File metadata and controls
188 lines (152 loc) · 4.16 KB
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
//Addins
#addin nuget:?package=Cake.VersionReader&version=5.0.0
#addin nuget:?package=Cake.FileHelpers&version=3.2.0
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.10.0"
#region Paths
var tools = "./tools";
var sln = "./Cake.VersionReader/Cake.VersionReader.sln";
var nuspec = "./Cake.VersionReader/Cake.VersionReader/Cake.VersionReader.nuspec";
var releaseFolder = "./Cake.VersionReader/Cake.VersionReader/bin/Release/netstandard2.0";
var releaseDll = "/Cake.VersionReader.dll";
var unitTestPaths = "./Cake.VersionReader/Cake.VersionReader.Test/bin/Release/Cake.VersionReader.Tests.dll";
var testResultFile = "./TestResult.xml";
#endregion
#region Arguments
var target = Argument ("target", "Build");
var buildType = Argument<string>("buildType", "develop");
var buildCounter = Argument<int>("buildCounter", 0);
#endregion
#region Runtime Variables
var version = "0.0.0";
var ciVersion = "0.0.0-CI00000";
var runningOnAppVeyor = false;
var runningOnTeamCity = false;
var testSucceeded = true;
#endregion
#region Tasks
// 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);
});
Task ("Build")
.IsDependentOn("DiscoverBuildDetails")
.Does (() => {
NuGetRestore (sln);
MSBuild (sln, new MSBuildSettings {
ToolVersion = MSBuildToolVersion.VS2017,
Configuration = "Release"
});
var file = MakeAbsolute(Directory(releaseFolder)) + releaseDll;
version = GetVersionNumber(file);
ciVersion = GetVersionNumberWithContinuesIntegrationNumberAppended(file, buildCounter);
Information("Version: " + version);
Information("CI Version: " + ciVersion);
PushVersion(ciVersion);
});
//Execute Unit tests
Task("UnitTest")
.IsDependentOn("Build")
.Does(() =>
{
StartBlock("Unit Testing");
var testAssemblies = GetFiles(unitTestPaths);
NUnit3(testAssemblies, new NUnit3Settings {
OutputFile = testResultFile,
WorkingDirectory = ".",
Work = MakeAbsolute(Directory("."))
});
PushTestResults(testResultFile);
EndBlock("Unit Testing");
});
Task ("Nuget")
.IsDependentOn ("UnitTest")
.Does (() => {
CreateDirectory ("./nupkg/");
ReplaceRegexInFiles(nuspec, "0.0.0", version);
NuGetPack (nuspec, new NuGetPackSettings {
Verbosity = NuGetVerbosity.Detailed,
OutputDirectory = "./nupkg/"
});
});
Task ("Push")
.WithCriteria(buildType == "master")
.IsDependentOn ("Nuget")
.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 ("Clean").Does (() =>
{
CleanDirectories ("./**/bin");
CleanDirectories ("./**/obj");
CleanDirectories ("./**/Components");
CleanDirectories ("./**/tools");
DeleteFiles ("./**/*.apk");
});
Task("Default")
.IsDependentOn("Push");
#endregion
RunTarget (target);
#region Helper Methods
public void StartBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteStartBlock(blockName);
}
}
public void StartBuildBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteStartBuildBlock(blockName);
}
}
public void EndBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteEndBlock(blockName);
}
}
public void EndBuildBlock(string blockName)
{
if(runningOnTeamCity)
{
TeamCity.WriteEndBuildBlock(blockName);
}
}
public void PushVersion(string version)
{
if(runningOnTeamCity)
{
TeamCity.SetBuildNumber(version);
}
if(runningOnAppVeyor)
{
Information("Pushing version to AppVeyor: " + version);
AppVeyor.UpdateBuildVersion(version);
}
}
public void PushTestResults(string filePath)
{
var file = MakeAbsolute(File(filePath));
if(runningOnAppVeyor)
{
AppVeyor.UploadTestResults(file, AppVeyorTestResultsType.NUnit3);
}
}
#endregion