forked from prom3theu5/aspirational-manifests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
137 lines (119 loc) · 4.21 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
#addin "nuget:?package=Cake.MinVer&version=3.0.0"
using System.Text.Json;
var target = Argument("Target", "CI");
var configuration =
HasArgument("Configuration") ? Argument<string>("Configuration") :
EnvironmentVariable("Configuration", "Release");
var shouldPack = HasArgument("pack") ? Argument<bool>("pack") : false;
var settings = new MinVerSettings()
{
AutoIncrement = MinVerAutoIncrement.Minor,
DefaultPreReleasePhase = "preview",
MinimumMajorMinor = "0.1",
TagPrefix = "v",
Verbosity = MinVerVerbosity.Trace,
};
var version = MinVer(settings);
Task("Clean")
.Description("Cleans the artifacts, bin and obj directories.")
.Does(() =>
{
DeleteDirectories(GetDirectories("**/bin"), new DeleteDirectorySettings() { Force = true, Recursive = true });
DeleteDirectories(GetDirectories("**/obj"), new DeleteDirectorySettings() { Force = true, Recursive = true });
CleanDirectory("./artifacts");
CleanDirectory("./test-output");
});
Task("Restore")
.Description("Restores NuGet packages.")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetRestore();
});
Task("Build")
.Description("Builds the solution.")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetBuild(
".",
new DotNetBuildSettings()
{
Configuration = configuration,
NoRestore = true,
ArgumentCustomization = args =>
args
.Append($"-p:Version={version}")
.Append($"-p:InformationalVersion={version}"),
});
});
Task("Test")
.Description("Runs unit tests and outputs test results to the artifacts directory.")
.Does(() =>
{
DotNetTest(
"tests/Aspirate.Tests/Aspirate.Tests.csproj",
new DotNetTestSettings()
{
Blame = true,
Configuration = configuration,
ResultsDirectory = "./test-output",
NoBuild = true,
NoRestore = true,
Collectors = new string[] { "Code Coverage", "XPlat Code Coverage" },
});
});
Task("Pack")
.Description("Packs the Required Project")
.IsDependentOn("Test")
.WithCriteria(shouldPack)
.Does(() =>
{
DotNetPack("src/Aspirate.Cli/Aspirate.Cli.csproj",
new DotNetPackSettings()
{
NoBuild = true,
NoRestore = true,
NoLogo = true,
OutputDirectory = "./artifacts",
Verbosity = DotNetVerbosity.Minimal,
Configuration = configuration,
ArgumentCustomization = builder => builder.Append($"-p:PackageVersion={version}")
});
});
Task("CI")
.Description("Cleans, restores NuGet packages, builds the solution and then runs unit tests.")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Pack");
Task("LocalTestInstall")
.Description("Installs the tool locally")
.IsDependentOn("Build")
.Does(() =>
{
StartProcess("dotnet", new ProcessSettings()
{
Arguments = $"tool uninstall -g aspirate",
});
DotNetPack("src/Aspirate.Cli/Aspirate.Cli.csproj",
new DotNetPackSettings()
{
NoBuild = true,
NoRestore = true,
NoLogo = true,
OutputDirectory = "./artifacts",
Verbosity = DotNetVerbosity.Minimal,
Configuration = configuration,
ArgumentCustomization = builder => builder.Append($"-p:PackageVersion=999.99.99")
});
var package = GetFiles("./artifacts/*.nupkg").FirstOrDefault();
if (package == null)
{
throw new Exception("Could not find package");
}
StartProcess("dotnet", new ProcessSettings()
{
Arguments = $"tool install -g --add-source ./artifacts aspirate",
});
});
RunTarget(target);