-
Notifications
You must be signed in to change notification settings - Fork 58
/
build.cake
205 lines (176 loc) · 6.74 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
#tool "nuget:?package=ReportGenerator&version=4.2.10"
#tool nuget:?package=Codecov&version=1.5.0
#addin nuget:?package=Cake.Codecov&version=0.6.0
#addin nuget:?package=Cake.Coverlet&version=2.3.4
public class MyBuildData
{
public string Configuration { get; }
public string TestFramework { get; }
public string Framework { get; }
public bool RunCoverage { get; }
public ConvertableDirectoryPath ArtifactsDirectory { get; }
public ConvertableDirectoryPath CoverageDirectory { get; }
public ConvertableDirectoryPath CoverageReportDirectory { get; }
public ConvertableDirectoryPath TestResultsDirectory { get; }
public DotNetCoreBuildSettings BuildSettings { get; }
public DotNetCoreBuildSettings TestBuildSettings { get; }
public DotNetCoreTestSettings TestSettings { get; }
public DotNetCorePackSettings PackSettings { get; }
public CoverletSettings CoverletSettings { get; }
public IReadOnlyList<ConvertableDirectoryPath> BuildDirs { get; }
public MyBuildData(
string configuration,
string testFramework,
string framework,
bool runCoverage,
ConvertableDirectoryPath artifactsDirectory,
ConvertableDirectoryPath coverageDirectory,
ConvertableDirectoryPath coverageReportDirectory,
ConvertableDirectoryPath testResultsDirectory,
IReadOnlyList<ConvertableDirectoryPath> buildDirectories)
{
Configuration = configuration;
TestFramework = testFramework;
Framework = framework;
RunCoverage = runCoverage;
ArtifactsDirectory = artifactsDirectory;
CoverageDirectory = coverageDirectory;
CoverageReportDirectory = coverageReportDirectory;
TestResultsDirectory = testResultsDirectory;
BuildDirs = buildDirectories;
var setting = new DotNetCoreBuildSettings {
Configuration = configuration,
NoRestore = true,
ArgumentCustomization = args => args.Append("/property:WarningLevel=0") // Until Warnings are fixed in StyleCop
};
if(!string.IsNullOrEmpty(framework))
{
setting.Framework = framework;
}
var testSetting = new DotNetCoreBuildSettings {
NoRestore = true,
Configuration = configuration
};
if(!string.IsNullOrEmpty(testFramework))
{
testSetting.Framework = testFramework;
}
BuildSettings = setting;
TestBuildSettings = testSetting;
CoverletSettings = new CoverletSettings {
CollectCoverage = runCoverage,
CoverletOutputFormat = CoverletOutputFormat.opencover | CoverletOutputFormat.cobertura,
CoverletOutputDirectory = CoverageDirectory,
CoverletOutputName = $"results",
}
.WithFilter("[Stubble.Core.Tests]*")
.WithFilter("[Stubble.Core]*.Imported.*")
.WithFilter("[Stubble.Compilation]Stubble.Compilation.Helpers.*")
.WithFilter("[Stubble.Compilation.Tests]*")
.WithFilter("[Stubble.Compilation]*.Import.*")
.WithFilter("[Stubble.Compilation]Stubble.Compilation.Contexts.RegistryResult")
.WithFilter("[Stubble.Core]Stubble.Core.Helpers.*")
.WithFilter("[xunit.*]*")
.WithDateTimeTransformer();
var testSettings = new DotNetCoreTestSettings {
Configuration = configuration,
NoBuild = true,
Verbosity = DotNetCoreVerbosity.Quiet,
Framework = testFramework,
ArgumentCustomization = args =>
args.Append("--logger:trx")
};
TestSettings = testSettings;
PackSettings = new DotNetCorePackSettings
{
OutputDirectory = ArtifactsDirectory,
NoBuild = true,
Configuration = Configuration,
};
}
}
var target = Argument("target", "Default");
Setup<MyBuildData>(setupContext =>
{
return new MyBuildData(
configuration: Argument("configuration", "Release"),
testFramework: Argument("testFramework", ""),
framework: Argument("framework", ""),
runCoverage: Argument<bool>("runCoverage", true),
artifactsDirectory: Directory("./artifacts/"),
coverageDirectory: Directory("./coverage-results"),
coverageReportDirectory: Directory("./coverage-report"),
testResultsDirectory: Directory("./test/Stubble.Core.Tests/TestResults"),
buildDirectories: new List<ConvertableDirectoryPath> {
Directory("./src/Stubble.Core/bin/Any CPU/"),
Directory("./src/Stubble.Core.Tests/bin/Any CPU/"),
Directory("./src/Stubble.Core.Compilation/bin/Any CPU/")
});
});
Task("Clean")
.Does<MyBuildData>((data) =>
{
foreach (var dir in data.BuildDirs)
{
CleanDirectory(dir + Directory(data.Configuration));
}
CleanDirectory(data.ArtifactsDirectory);
CleanDirectory(data.CoverageDirectory);
CleanDirectory(data.CoverageReportDirectory);
CleanDirectory(data.TestResultsDirectory);
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore("./Stubble.Core.sln");
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does<MyBuildData>((data) =>
{
DotNetCoreBuild("./src/Stubble.Core/", data.BuildSettings);
DotNetCoreBuild("./test/Stubble.Core.Tests/", data.TestBuildSettings);
DotNetCoreBuild("./src/Stubble.Compilation/", data.BuildSettings);
DotNetCoreBuild("./test/Stubble.Compilation.Tests/", data.TestBuildSettings);
});
Task("Test")
.IsDependentOn("Build")
.Does<MyBuildData>((data) =>
{
DotNetCoreTest("./test/Stubble.Core.Tests/Stubble.Core.Tests.csproj", data.TestSettings, data.CoverletSettings);
DotNetCoreTest("./test/Stubble.Compilation.Tests/Stubble.Compilation.Tests.csproj", data.TestSettings, data.CoverletSettings);
});
Task("Pack")
.IsDependentOn("Test")
.Does<MyBuildData>((data) =>
{
DotNetCorePack("./src/Stubble.Core/Stubble.Core.csproj", data.PackSettings);
DotNetCorePack("./src/Stubble.Compilation/Stubble.Compilation.csproj", data.PackSettings);
});
Task("CodeCov")
.IsDependentOn("Pack")
.WithCriteria(BuildSystem.IsRunningOnAzurePipelinesHosted && IsRunningOnWindows())
.Does<MyBuildData>((data) =>
{
var coverageFiles = GetFiles((string)data.CoverageDirectory + "/*opencover.xml")
.Select(f => f.FullPath)
.ToArray();
var token = EnvironmentVariable("CODECOV_REPO_TOKEN");
var settings = new CodecovSettings
{
Token = token,
Files = coverageFiles
};
// Upload coverage reports.
Codecov(settings);
});
Task("CoverageReport")
.Does<MyBuildData>((data) =>
{
ReportGenerator((string)data.CoverageDirectory + "/*opencover.xml", data.CoverageReportDirectory);
});
Task("Default")
.IsDependentOn("CodeCov");
RunTarget(target);