-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
179 lines (150 loc) · 5.04 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
/// <summary>
/// Just a simple build script.
/// </summary>
#addin Cake.Coveralls
#tool "nuget:?package=xunit.runner.console"
#tool "nuget:?package=ReportUnit"
#tool "nuget:?package=OpenCover"
#tool "nuget:?package=coveralls.net"
// *********************
// ARGUMENTS
// *********************
var Target = Argument("target", "default");
var Configuration = Argument("configuration", "release");
// *********************
// VARIABLES
// *********************
var Solution = File("AntMeCore.sln");
var Tests = new List<FilePath>();
var BuildVerbosity = Verbosity.Minimal;
// *********************
// TASKS
// *********************
/// <summary>
/// Task to build the solution. Using MSBuild on Windows and MDToolBuild on OSX / Linux
/// </summary>
Task("build")
.WithCriteria(() =>
{
var canBuild = Solution != null && FileExists(Solution);
if(!canBuild)
Information("Build skipped. To run a build set Solution variable before.");
return canBuild;
})
.Does(() =>
{
DotNetBuild(Solution, cfg =>
{
cfg.Configuration = Configuration;
cfg.Verbosity = BuildVerbosity;
});
});
/// <summary>
/// Task to clean all obj and bin directories as well as the ./output folder.
/// Commonly called right before build.
/// </summary>
Task("clean")
.Does(() =>
{
CleanDirectories("./output");
CleanDirectories("./bin");
CleanDirectories(string.Format("./src/**/obj/{0}", Configuration));
CleanDirectories(string.Format("./src/**/bin/{0}", Configuration));
CleanDirectories(string.Format("./tests/**/obj/{0}", Configuration));
CleanDirectories(string.Format("./tests/**/bin/{0}", Configuration));
});
/// <summary>
/// The default task with a predefined flow.
/// </summary>
Task("default")
.IsDependentOn("clean")
.IsDependentOn("restore")
.IsDependentOn("build")
.IsDependentOn("test")
.IsDependentOn("upload-coverage");
/// <summary>
/// Task to rebuild. Nothing else than a clean followed by build.
/// </summary>
Task("rebuild")
.IsDependentOn("clean")
.IsDependentOn("build");
/// <summary>
/// Task to restore NuGet packages on solution level for all containing projects.
/// </summary>
Task("restore")
.WithCriteria(() =>
{
var canRestore = Solution != null && FileExists(Solution);
if(!canRestore)
Information("Restore skipped. To restore packages set Solution variable.");
return canRestore;
})
.Does(() => NuGetRestore(Solution));
/// <summary>
/// Task to run unit tests.
/// </summary>
Task("test")
.WithCriteria(() =>
{
// Find Tests by convention
var testLibs = GetFiles(string.Format("./tests/*/bin/{0}/**/*.Tests.dll", Configuration)).ToArray();
Tests.AddRange(testLibs);
var canTest = Tests != null && Tests.Any();
if(!canTest)
Information("Test skipped. To run tests add some dlls to Tests variable.");
return canTest;
})
.Does(() =>
{
CreateDirectory("./output/xunit");
var parallelOption = IsRunningOnWindows() ? ParallelismOption.All : ParallelismOption.None;
Action<ICakeContext> runXunit = tool => {
tool.XUnit2(Tests, new XUnit2Settings
{
OutputDirectory = "./output/xunit",
XmlReport = true,
ShadowCopy = false,
Parallelism = parallelOption,
NoAppDomain = ! IsRunningOnWindows()
});
};
if(IsRunningOnWindows())
{
OpenCover(runXunit,
File("./output/coverage.xml"),
new OpenCoverSettings()
.WithFilter("+[AntMe.*]*")
.WithFilter("-[AntMe.*.Tests]*"));
}
else
runXunit(Context);
})
.Finally(() =>
{
ReportUnit("./output/xunit");
});
/// <summary>
/// Task to upload test coverage result to coveralls.io. Only executed on AppVeyor CI.
/// </summary>
Task("upload-coverage")
.WithCriteria(() =>
{
var isMainRepo = AppVeyor.Environment.Repository.Name == "AntMeNet/AntMeCore";
var isPR = AppVeyor.Environment.PullRequest.IsPullRequest;
var canUpload = FileExists("./output/coverage.xml") && AppVeyor.IsRunningOnAppVeyor && isMainRepo && !isPR;
if(!canUpload)
Information("Upload coverage result skipped. To upload test coverage run on AppVeyor CI.");
return canUpload;
})
.Does(() =>
{
var repoToken = EnvironmentVariable("COVERALLS_REPO_TOKEN");
if(string.IsNullOrEmpty(repoToken))
throw new Exception("Coveralls repo token missing. Set COVERALLS_REPO_TOKEN evironment variable");
CoverallsNet("./output/coverage.xml", CoverallsNetReportType.OpenCover, new CoverallsNetSettings()
{
RepoToken = repoToken
});
});
// Execution
RunTarget(Target);