-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
208 lines (175 loc) · 6.06 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
#tool "nuget:?package=OpenCover"
#tool "nuget:?package=Codecov&version=1.1.0"
#addin "nuget:?package=Cake.Codecov"
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var assemblyVersion = "0.0.1";
var packageVersion = "0.0.1";
var artifactsDir = MakeAbsolute(Directory("artifacts"));
var testsResultsDir = artifactsDir.Combine(Directory("test-results"));
var packagesDir = artifactsDir.Combine(Directory("packages"));
EnsureDirectoryExists(artifactsDir);
var solutionPath = "./Brematic.Net.sln";
Task("Clean")
.Does(() =>
{
CleanDirectory(artifactsDir);
var settings = new DotNetCoreCleanSettings
{
Configuration = configuration
};
DotNetCoreClean(solutionPath, settings);
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore();
});
Task("SemVer")
.IsDependentOn("Restore")
.Does(() =>
{
GitVersion gitVersion = GitVersion();
assemblyVersion = gitVersion.AssemblySemVer;
packageVersion = gitVersion.NuGetVersion;
Information($"AssemblySemVer: {assemblyVersion}");
Information($"NuGetVersion: {packageVersion}");
});
Task("SetAppVeyorVersion")
.IsDependentOn("Semver")
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
AppVeyor.UpdateBuildVersion(packageVersion);
});
Task("Build")
.IsDependentOn("SetAppVeyorVersion")
.Does(() =>
{
var settings = new DotNetCoreBuildSettings
{
Configuration = configuration,
NoIncremental = true,
NoRestore = true,
MSBuildSettings = new DotNetCoreMSBuildSettings()
.SetVersion(assemblyVersion)
.WithProperty("FileVersion", packageVersion)
.WithProperty("InformationalVersion", packageVersion)
.WithProperty("nowarn", "7035")
};
DotNetCoreBuild(solutionPath, settings);
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new DotNetCoreToolSettings();
var argumentsBuilder = new ProcessArgumentBuilder()
.Append("-configuration")
.Append(configuration)
.Append("-nobuild");
var projectFiles = GetFiles("./tests/*/*Tests.csproj");
foreach (var projectFile in projectFiles)
{
var testResultsFile = testsResultsDir.Combine($"{projectFile.GetFilenameWithoutExtension()}.xml");
var arguments = $"{argumentsBuilder.Render()} -xml \"{testResultsFile}\"";
DotNetCoreTool(projectFile, "xunit", arguments, settings);
}
})
.DeferOnError();
Task("Cover")
.IsDependentOn("Test")
.WithCriteria(() => HasArgument("cover"))
.Does(() =>
{
var projects = GetFiles("./src/**/*.csproj");
foreach(var project in projects)
{
TransformTextFile(project.FullPath, ">", "<")
.WithToken("portable", ">full<")
.Save(project.FullPath);
}
projects = GetFiles("./tests/**/*.csproj");
var resultsFile = artifactsDir.CombineWithFilePath("coverage.xml");
foreach(var project in projects)
{
OpenCover(
x => x.DotNetCoreTest(
project.FullPath,
new DotNetCoreTestSettings() {
Configuration = configuration,
NoBuild = true
}
),
resultsFile,
new OpenCoverSettings()
{
ArgumentCustomization = args => args
.Append("-threshold:100")
.Append("-returntargetcode")
.Append("-hideskipped:Filter;Attribute"),
Register = "user",
MergeOutput = true,
OldStyle = true,
SkipAutoProps = true,
MergeByHash = true
}
.WithFilter("+[Brematic.Net]*")
.WithFilter("-[Brematic.Net.Tests]*")
.WithFilter("-[xunit*]*")
.ExcludeByAttribute("*.ExcludeFromCodeCoverage*")
);
}
if (HasArgument("codecov")) {
Codecov(resultsFile.FullPath);
}
});
Task("Pack")
.IsDependentOn("Cover")
.WithCriteria(() => HasArgument("pack"))
.Does(() =>
{
var settings = new DotNetCorePackSettings
{
Configuration = configuration,
NoBuild = true,
NoRestore = true,
IncludeSymbols = true,
OutputDirectory = packagesDir,
MSBuildSettings = new DotNetCoreMSBuildSettings()
.WithProperty("PackageVersion", packageVersion)
.WithProperty("Copyright", $"Copyright Tobias Efinger {DateTime.Now.Year}")
};
FixProps();
GetFiles("./src/*/*.csproj")
.ToList()
.ForEach(f => DotNetCorePack(f.FullPath, settings));
});
Task("PublishAppVeyorArtifacts")
.IsDependentOn("Pack")
.WithCriteria(() => HasArgument("pack") && AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
CopyFiles($"{packagesDir}/*.nupkg", MakeAbsolute(Directory("./")), false);
GetFiles($"./*.nupkg")
.ToList()
.ForEach(f => AppVeyor.UploadArtifact(f, new AppVeyorUploadArtifactsSettings { DeploymentName = "packages" }));
});
Task("Default")
.IsDependentOn("PublishAppVeyorArtifacts");
RunTarget(target);
private void FixProps()
{
/* Workaround this issue: https://github.com/NuGet/Home/issues/4337
`pack` does not respect the `Version` and ends up generating invalid
`NuGet` packages when same-solution project dependencies
*/
var restoreSettings = new DotNetCoreRestoreSettings
{
MSBuildSettings = new DotNetCoreMSBuildSettings()
.WithProperty("Version", packageVersion)
.WithProperty("Configuration", configuration)
};
DotNetCoreRestore(restoreSettings);
}