forked from cake-contrib/Cake.Newman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
169 lines (149 loc) · 5.5 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
#tool "GitVersion.CommandLine"
#addin nuget:?package=Cake.DocFx
#tool nuget:?package=docfx.console&version=2.33.2
#tool "OpenCover"
#tool "nuget:?package=ReportGenerator"
#load "helpers.cake"
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
var framework = Argument<string>("framework", "netstandard2.0");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var solutionPath = File("./src/Cake.Newman.sln");
var solution = ParseSolution(solutionPath);
var projects = solution.Projects.Where(p => p.Type != "{2150E333-8FDC-42A3-9474-1A3956D46DE8}");
var projectPaths = projects.Select(p => p.Path.GetDirectory());
var frameworks = GetFrameworks(framework);
var testAssemblies = projects.Where(p => p.Name.Contains(".Tests"));
var artifacts = "./dist/";
var testResultsPath = MakeAbsolute(Directory(artifacts + "./test-results/"));
GitVersion versionInfo = null;
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
versionInfo = GitVersion();
Information("Building for version {0}", versionInfo.FullSemVer);
Information("Building against '{0}'", framework);
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
// Clean solution directories.
foreach(var path in projectPaths)
{
Information("Cleaning {0}", path);
CleanDirectories(path + "/**/bin/" + configuration);
CleanDirectories(path + "/**/obj/" + configuration);
}
Information("Cleaning common files...");
CleanDirectory(artifacts);
DeleteFiles(GetFiles("./*.temp.nuspec"));
});
Task("Restore")
.Does(() =>
{
// Restore all NuGet packages.
Information("Restoring solution...");
//NuGetRestore(solutionPath);
foreach(var project in projects) {
DotNetCoreRestore(project.Path.GetDirectory() + $"/{project.Name}.csproj");
}
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
Information("Building solution...");
CreateDirectory(artifacts + "build/");
foreach(var project in projects) {
foreach(var f in frameworks) {
//CreateDirectory(artifacts + "build/" + f);
DotNetCoreBuild(project.Path.GetDirectory().FullPath, new DotNetCoreBuildSettings {
//Framework = f,
Configuration = configuration,
//OutputDirectory = artifacts + "build/" + configuration + "/" + f
});
}
}
});
Task("Post-Build")
.IsDependentOn("Build")
.Does(() => {
foreach (var project in projects) {
CopyDirectory(project.Path.GetDirectory() + "/bin/" + configuration, artifacts + "build/" + project.Name);
}
});
Task("Generate-Docs").Does(() => {
DocFxBuild("./docfx/docfx.json");
Zip("./docfx/_site/", artifacts + "/docfx.zip");
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
CreateDirectory(testResultsPath);
CreateDirectory(testResultsPath + "/coverage");
Action<ICakeContext> testAction = ctx => ctx.DotNetCoreTest("./src/Cake.Newman.Tests", new DotNetCoreTestSettings {
NoBuild = true,
Configuration = configuration,
ArgumentCustomization = args => args.Append("--").AppendSwitchQuoted("-xml", testResultsPath + "/test-results.xml")
});
OpenCover(testAction,
testResultsPath + "/coverage.xml",
new OpenCoverSettings {
ReturnTargetCodeOffset = 0,
Register = "User",
OldStyle = true,
ArgumentCustomization = args => args.Append("-mergeoutput"),
// SearchDirectories = frameworks.Select(f => $"./src/Cake.Newman.Tests/bin/{configuration}/{f}")
}
.WithFilter("+[Cake.Newman]*")
.ExcludeByAttribute("*.ExcludeFromCodeCoverage*")
.ExcludeByFile("*/*Designer.cs;*/*.g.cs;*/*.g.i.cs"));
ReportGenerator(testResultsPath + "/coverage.xml", testResultsPath + "/coverage");
});
Task("NuGet")
.IsDependentOn("Post-Build")
// .IsDependentOn("Copy-Core-Dependencies")
.IsDependentOn("Run-Unit-Tests")
.Does(() => {
CreateDirectory(artifacts + "package/");
Information("Building NuGet package");
var nuspecFiles = GetFiles("./*.nuspec");
var versionNotes = ParseAllReleaseNotes("./ReleaseNotes.md").FirstOrDefault(v => v.Version.ToString() == versionInfo.MajorMinorPatch);
var content = GetContent(frameworks, artifacts + "build/Cake.Newman/", "/Cake.Newman");
NuGetPack(nuspecFiles, new NuGetPackSettings() {
Version = versionInfo.NuGetVersionV2,
ReleaseNotes = versionNotes != null ? versionNotes.Notes.ToList() : new List<string>(),
OutputDirectory = artifacts + "/package",
Files = content,
//KeepTemporaryNuSpecFile = true
});
});
///////////////////////////////////////////////////////////////////////////////
// TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("NuGet")
.IsDependentOn("Generate-Docs");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);