-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.cake
194 lines (171 loc) · 5.93 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
#tool "nuget:?package=GitVersion.CommandLine"
#load "helpers.cake"
#tool nuget:?package=DocFx.Console&version=2.33.2
#addin nuget:?package=Cake.DocFx&version=0.7.0
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var solutionPath = File("./src/Cake.DNF.Module.sln");
var projects = GetProjects(solutionPath);
var artifacts = "./dist/";
var testResultsPath = MakeAbsolute(Directory(artifacts + "./test-results"));
GitVersion versionInfo = null;
var frameworks = new List<string> { "netstandard2.0" };
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
versionInfo = GitVersion();
Information("Building for version {0}", versionInfo.FullSemVer);
Verbose("Building for " + string.Join(", ", frameworks));
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
// Clean solution directories.
foreach(var path in projects.AllProjectPaths)
{
Information("Cleaning {0}", path);
CleanDirectories(path + "/**/bin/" + configuration);
CleanDirectories(path + "/**/obj/" + configuration);
}
Information("Cleaning common files...");
CleanDirectory(artifacts);
});
Task("Restore")
.Does(() =>
{
// Restore all NuGet packages.
Information("Restoring solution...");
//NuGetRestore(solutionPath);
foreach (var project in projects.AllProjectPaths) {
DotNetCoreRestore(project.FullPath);
}
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
Information("Building solution...");
foreach(var framework in frameworks) {
foreach (var project in projects.SourceProjectPaths) {
var settings = new DotNetCoreBuildSettings {
Framework = framework,
Configuration = configuration,
NoIncremental = true,
};
DotNetCoreBuild(project.FullPath, settings);
}
}
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
if (projects.TestProjects.Any()) {
CreateDirectory(testResultsPath);
/*var settings = new XUnit2Settings {
NoAppDomain = true,
XmlReport = true,
HtmlReport = true,
OutputDirectory = testResultsPath,
};
settings.ExcludeTrait("Category", "Integration"); */
var settings = new DotNetCoreTestSettings {
Configuration = configuration,
//ArgumentCustomization = args => args.AppendSwitchQuoted("--logger", "trx;LogFilePath=" + testResultsPath + "tests.trx")
};
//XUnit2(testAssemblies, settings);
foreach(var project in projects.TestProjects) {
DotNetCoreTest(project.Path.FullPath, settings);
}
}
});
Task("Generate-Docs").Does(() => {
DocFx("./docfx/docfx.json");
Zip("./docfx/_site/", artifacts + "/docfx.zip");
});
Task("Post-Build")
.IsDependentOn("Build")
.IsDependentOn("Run-Unit-Tests")
.IsDependentOn("Generate-Docs")
.Does(() =>
{
CreateDirectory(artifacts + "build");
CreateDirectory(artifacts + "modules");
foreach (var project in projects.SourceProjects) {
CreateDirectory(artifacts + "build/" + project.Name);
foreach (var framework in frameworks) {
var frameworkDir = artifacts + "build/" + project.Name + "/" + framework;
CreateDirectory(frameworkDir);
var files = GetFiles(project.Path.GetDirectory() + "/bin/" + configuration + "/" + framework + "/" + project.Name +".*");
CopyFiles(files, frameworkDir);
}
}
});
Task("Pack")
.IsDependentOn("Post-Build")
.Does(() =>
{
CreateDirectory(artifacts + "/package");
foreach(var project in projects.SourceProjects)
{
Information("\nPacking {0}...", project.Name);
DotNetCorePack(project.Path.FullPath, new DotNetCorePackSettings
{
Configuration = configuration,
OutputDirectory = artifacts + "/package/",
NoBuild = true,
ArgumentCustomization = args => args
.Append("--include-symbols --include-source")
});
}
});
Task("NuGet")
.IsDependentOn("Post-Build")
.Does(() =>
{
CreateDirectory(artifacts + "package");
Information("Building NuGet package");
var versionNotes = ParseAllReleaseNotes("./ReleaseNotes.md").FirstOrDefault(v => v.Version.ToString() == versionInfo.MajorMinorPatch);
var content = GetContent(frameworks, projects);
var settings = new NuGetPackSettings {
Id = "Cake.DNF.Module",
Version = versionInfo.NuGetVersionV2,
Title = "Cake DNF Module",
Authors = new[] { "Alistair Chapman" },
Owners = new[] { "achapman", "cake-contrib" },
Description = "This Cake module adds support for the DNF package manager when installing tools in your Cake build scripts.",
ReleaseNotes = versionNotes != null ? versionNotes.Notes.ToList() : new List<string>(),
Summary = "Adds DNF support to Cake builds.",
ProjectUrl = new Uri("https://github.com/cake-contrib/Cake.DNF.Module"),
IconUrl = new Uri("https://cdn.rawgit.com/cake-contrib/graphics/a5cf0f881c390650144b2243ae551d5b9f836196/png/cake-contrib-medium.png"),
LicenseUrl = new Uri("https://raw.githubusercontent.com/agc93/Cake.DNF.Module/master/LICENSE"),
Copyright = "Alistair Chapman 2017",
Tags = new[] { "cake", "build", "ci", "build", "dnf", "linux" },
OutputDirectory = artifacts + "/package",
Files = content,
//KeepTemporaryNuSpecFile = true
};
NuGetPack(settings);
});
Task("Default")
.IsDependentOn("Post-Build");
RunTarget(target);