-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
150 lines (130 loc) · 4.28 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
#load "build/helpers.cake"
// #addin nuget:?package=Cake.Docker
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
// var framework = Argument("framework", "netcoreapp3.1");
///////////////////////////////////////////////////////////////////////////////
// VERSIONING
///////////////////////////////////////////////////////////////////////////////
var packageVersion = string.Empty;
#load "build/version.cake"
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var solutionPath = File("./src/ACInstallerCreator.sln");
var solution = ParseSolution(solutionPath);
var projects = GetProjects(solutionPath, configuration);
var artifacts = "./dist/";
var testResultsPath = MakeAbsolute(Directory(artifacts + "./test-results"));
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
packageVersion = BuildVersion(fallbackVersion);
if (FileExists("./build/.dotnet/dotnet.exe")) {
Information("Using local install of `dotnet` SDK!");
Context.Tools.RegisterFile("./build/.dotnet/dotnet.exe");
}
});
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...");
foreach (var project in projects.AllProjectPaths) {
DotNetCoreRestore(project.FullPath);
}
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
Information("Building solution...");
var settings = new DotNetCoreBuildSettings {
Configuration = configuration,
NoIncremental = true,
ArgumentCustomization = args => args.Append($"/p:Version={packageVersion}")
};
DotNetCoreBuild(solutionPath, 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("Publish-Runtime")
.IsDependentOn("Build")
.Does(() =>
{
var projectDir = $"{artifacts}publish";
CreateDirectory(projectDir);
foreach (var projPath in new[] {"./src/InstallerCreator/InstallerCreator.csproj", "./src/PackCreator/PackCreator.csproj"})
{
DotNetCorePublish(projPath, new DotNetCorePublishSettings {
OutputDirectory = projectDir + "/dotnet-any",
Configuration = configuration,
PublishSingleFile = false,
PublishTrimmed = false
});
var runtimes = new[] { "linux-x64", "win-x64"};
foreach (var runtime in runtimes) {
var runtimeDir = $"{projectDir}/{runtime}";
CreateDirectory(runtimeDir);
Information("Publishing for {0} runtime", runtime);
var settings = new DotNetCorePublishSettings {
Runtime = runtime,
Configuration = configuration,
OutputDirectory = runtimeDir,
PublishSingleFile = true,
PublishTrimmed = true,
IncludeNativeLibrariesForSelfExtract = true,
ArgumentCustomization = args => args.Append($"/p:Version={packageVersion}")
};
DotNetCorePublish(projPath, settings);
CreateDirectory($"{artifacts}archive");
Zip(runtimeDir, $"{artifacts}archive/acmi-{runtime}.zip");
}
}
});
Task("Default")
.IsDependentOn("Build");
Task("Publish")
.IsDependentOn("Publish-Runtime");
RunTarget(target);