-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.cake
161 lines (138 loc) · 4.7 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
#tool "nuget:?package=GitVersion.CommandLine"
#load "build/helpers.cake"
#tool nuget:?package=docfx.console
#addin nuget:?package=Cake.DocFx
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var buildFrameworks = Argument("frameworks", "netstandard2.0");
///////////////////////////////////////////////////////////////////////////////
// VERSIONING
///////////////////////////////////////////////////////////////////////////////
#load "build/version.cake"
var packageVersion = string.Empty;
var fallbackVersion = Argument<string>("force-version", EnvironmentVariable("FALLBACK_VERSION") ?? "0.1.0");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var solutionPath = File("./src/Cake.AzCopy.sln");
var projects = GetProjects(solutionPath, configuration);
var artifacts = "./dist/";
var testResultsPath = MakeAbsolute(Directory(artifacts + "./test-results"));
var frameworks = buildFrameworks.Split(new[] { ";", ","}, StringSplitOptions.RemoveEmptyEntries);
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
CreateDirectory(artifacts);
packageVersion = BuildVersion(fallbackVersion);
if (FileExists("./build/.dotnet/dotnet.exe")) {
Information("Using local install of `dotnet` SDK!");
Context.Tools.RegisterFile("./build/.dotnet/dotnet.exe");
}
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...");
DotNetCoreRestore(projects.SolutionPath);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
Information("Building solution...");
Information("Building solution...");
foreach (var project in projects.SourceProjectPaths) {
Information($"Building {project.GetDirectoryName()} for {configuration}");
foreach (var framework in frameworks)
{
var settings = new DotNetCoreBuildSettings {
Configuration = configuration,
Framework = framework,
ArgumentCustomization = args => args.Append("/p:NoWarn=NU1701"),
};
DotNetCoreBuild(project.FullPath, settings);
}
}
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
CreateDirectory(testResultsPath);
if (projects.TestProjects.Any()) {
var settings = new DotNetCoreTestSettings {
Configuration = configuration
};
foreach(var project in projects.TestProjects) {
DotNetCoreTest(project.Path.FullPath, settings);
}
}
});
Task("Generate-Docs")
.WithCriteria(() => FileExists("./docfx/docfx.json"))
.Does(() =>
{
Information("Building metadata...");
DocFxMetadata("./docfx/docfx.json");
Information("Building docs...");
DocFxBuild("./docfx/docfx.json");
Information("Packaging built docs...");
Zip("./docfx/_site/", artifacts + "/docfx.zip");
})
.OnError(ex =>
{
Warning(ex.Message);
Warning("Error generating documentation!");
});
Task("Post-Build")
.IsDependentOn("Build")
.IsDependentOn("Run-Unit-Tests")
.IsDependentOn("Generate-Docs")
.Does(() =>
{
CreateDirectory(artifacts + "build");
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}/*.*");
CopyFiles(files, frameworkDir);
}
}
});
#load "build/nuget.cake"
Task("Default")
.IsDependentOn("NuGet");
RunTarget(target);