This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
212 lines (191 loc) · 6.64 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
// Tools
#tool "nuget:?package=GitVersion.CommandLine"
#tool "nuget:?package=NUnit.ConsoleRunner"
// Add Ins
#addin "Cake.FileHelpers"
// Target
var target = Argument("target", "Default");
// Paths
var solutionPath = File("Detector.sln");
var baseOutput = Directory("Output");
var buildOutput = baseOutput + Directory("Build");
var buildOutputNet45 = buildOutput + Directory("net45");
var buildOutputNetStandard = buildOutput + Directory("netstandard");
var buildOutputPCL = buildOutput + Directory("pcl");
var testOutput = baseOutput + Directory("TestBuild");
var artifactOutput = baseOutput + Directory("Artifacts");
// Meta informations
var projectName = "WD.Detector";
var summary = "Implementation of Detector use case";
var description = "Implementation of Detector use case, if only one of the events is relevant.";
var authors = new [] { "Eugen [WebDucer] Richter" };
var tags = new [] { "Detector", "Event", "Async" };
var copyright = "MIT - WebDucer (c) " + DateTime.Now.Year;
var projectUri = new Uri("https://bitbucket.org/webducertutorials/detectors");
var licenceUri = new Uri("https://bitbucket.org/webducertutorials/detectors/raw/master/LICENSE.txt");
var releaseNotes = FileReadLines("RELEASE_NOTES.md");
// Version
var version = GitVersion();
// Cross platform build
var buildProject = new Action<FilePath, DirectoryPath>((FilePath projectFile, DirectoryPath outputFolder) => {
if(IsRunningOnUnix()){
var buildSettings = new XBuildSettings{
Configuration = "Release"
}.WithProperty("OutDir", outputFolder.FullPath + "/");
XBuild(projectFile, buildSettings);
} else {
var buildSettings = new MSBuildSettings{
Configuration = "Release",
NodeReuse = true,
MaxCpuCount = 0,
}.WithProperty("OutDir", outputFolder.FullPath);
MSBuild(projectFile, buildSettings);
}
});
/*
* Remove all old files from build and test directories
*/
Task("Cleanup")
.Does(() => {
var directories = new DirectoryPath[] {buildOutput, testOutput, artifactOutput};
CleanDirectories(directories);
});
/*
* Restore all nuget packages of the solution
*/
Task("RestoreDependencies")
.IsDependentOn("Cleanup")
.Does(() => {
NuGetRestore(solutionPath);
});
/*
* Build test projects
*/
Task("BuildTests")
.IsDependentOn("RestoreDependencies")
.Does(() => {
var toBuildFolder = MakeAbsolute(testOutput);
var testProjects = GetFiles("./tests/**/Detector.Tests.csproj");
foreach(var project in testProjects){
buildProject(project, toBuildFolder);
}
});
/*
* Run NUnit3 tests
*/
Task("RunTests")
.IsDependentOn("BuildTests")
.Does(() => {
var testResultFile = artifactOutput + File("TestResults.xml");
var testFiles = GetFiles(testOutput.Path.FullPath + "/*Tests.dll");
var testSetiings = new NUnit3Settings {
Results = testResultFile
};
NUnit3(testFiles, testSetiings);
if(BuildSystem.IsRunningOnAppVeyor) {
BuildSystem.AppVeyor.UploadTestResults(testResultFile, AppVeyorTestResultsType.NUnit3);
}
});
/*
* Patch assembly version
*/
Task("PatchAssemblyVersion")
.IsDependentOn("RestoreDependencies")
.Does(() => {
var versionSettings = new GitVersionSettings {
UpdateAssemblyInfo = true
};
GitVersion(versionSettings);
});
/*
* Build the library
*/
Task("BuildLibrary")
.IsDependentOn("RestoreDependencies")
.IsDependentOn("PatchAssemblyVersion")
.Does(() => {
// Net 45
var toBuildFolder = MakeAbsolute(buildOutputNet45);
var buildProjects = GetFiles("./src/**/Detector.csproj");
foreach(var project in buildProjects){
buildProject(project, toBuildFolder);
}
// NetStandard
toBuildFolder = MakeAbsolute(buildOutputNetStandard);
buildProjects = GetFiles("./src/**/Detector.NetStandard.csproj");
foreach(var project in buildProjects){
buildProject(project, toBuildFolder);
}
// PCL
toBuildFolder = MakeAbsolute(buildOutputPCL);
buildProjects = GetFiles("./src/**/Detector.PCL.csproj");
foreach(var project in buildProjects){
buildProject(project, toBuildFolder);
}
});
/*
* Create NuGet package
*/
Task("CreatePackage")
.IsDependentOn("RunTests")
.IsDependentOn("BuildLibrary")
.Does(() => {
var libFolderNet45 = Directory("lib") + Directory("net45");
var libFolderNetStandard = Directory("lib") + Directory("netstandard1.1");
var libFolderPcl = Directory("lib") + Directory("portable-net45+wp8+win8");
var libFolderAndroid = Directory("lib") + Directory("MonoAndroid");
var libFolderIos = Directory("lib") + Directory("xamarinios");
var nugetSettings = new NuGetPackSettings {
Id = projectName,
Title = projectName,
Summary = summary,
Description = description,
Authors = authors,
Owners = authors,
Version = version.NuGetVersion,
Tags = tags,
OutputDirectory = artifactOutput,
Copyright = copyright,
BasePath = "./",
ProjectUrl = projectUri,
LicenseUrl = licenceUri,
ReleaseNotes = releaseNotes,
Files = new [] {
new NuSpecContent {
Source = buildOutputNet45 + File("WD.Detector.dll"),
Target = libFolderNet45
},
new NuSpecContent {
Source = buildOutputNetStandard + File("WD.Detector.dll"),
Target = libFolderNetStandard
},
new NuSpecContent {
Source = buildOutputPCL + File("WD.Detector.dll"),
Target = libFolderPcl
},
new NuSpecContent {
Source = buildOutputPCL + File("WD.Detector.dll"),
Target = libFolderAndroid
},
new NuSpecContent {
Source = buildOutputPCL + File("WD.Detector.dll"),
Target = libFolderIos
}
},
Dependencies = new [] {
// NetStandard
new NuSpecDependency {
Id = "System.Threading.Tasks.Parallel",
TargetFramework = "netstandard1.1",
Version = "4.3.0"
}
}
};
NuGetPack(nugetSettings);
});
Task("Default")
.IsDependentOn("CreatePackage");
/*
* Run build
*/
RunTarget(target);