-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.cake
181 lines (158 loc) · 5.44 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
#load "build/helpers.cake"
#tool "nuget:https://api.nuget.org/v3/index.json?package=nuget.commandline&version=5.3.1"
///////////////////////////////////////////////////////////////////////////////
// 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/NexusMiddleware.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-Runtimes")
.IsDependentOn("Build")
.Does(() =>
{
var projectDir = $"{artifacts}publish";
CreateDirectory(projectDir);
/* DotNetCorePublish("./src/NexusUploader/NexusUploader.csproj", 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,
ArgumentCustomization = args => args.Append($"/p:Version={packageVersion}").Append("/p:PackAsTool=false")
};
DotNetCorePublish("./src/NexusUploader/NexusUploader.csproj", settings);
CreateDirectory($"{artifacts}archive");
Zip(runtimeDir, $"{artifacts}archive/unex-{runtime}.zip");
}
});
Task("Build-NuGet-Package")
.IsDependentOn("Publish-Runtimes")
.Does(() =>
{
Information("Building dotnet package");
foreach(var project in projects.SourceProjects) {
CreateDirectory($"{artifacts}packages/dotnet-any");
var packSettings = new DotNetCorePackSettings {
ArgumentCustomization = args => args.Append($"/p:Version={packageVersion}").Append("/p:NoWarn=\"NU5105\""),
Configuration = configuration,
OutputDirectory = $"{artifacts}packages/dotnet-any/"
};
DotNetCorePack(project.Path.FullPath, packSettings);
}
});
Task("Publish-NuGet-Package")
.IsDependentOn("Build-NuGet-Package")
.WithCriteria(() => HasEnvironmentVariable("NUGET_TOKEN"))
.WithCriteria(() => EnvironmentVariable("GITHUB_REF").StartsWith("refs/tags/v"))
.Does(() => {
var nupkgDir = $"{artifacts}packages";
var nugetToken = EnvironmentVariable("NUGET_TOKEN");
var pkgFiles = GetFiles($"{nupkgDir}/dotnet-any/*.nupkg");
NuGetPush(pkgFiles, new NuGetPushSettings {
Source = "https://api.nuget.org/v3/index.json",
ApiKey = nugetToken
});
});
Task("Default")
.IsDependentOn("Build");
Task("Release")
.IsDependentOn("Package")
.IsDependentOn("Publish-NuGet-Package");
Task("Package")
.IsDependentOn("Publish-Runtimes")
.IsDependentOn("Build-NuGet-Package");
RunTarget(target);