-
Notifications
You must be signed in to change notification settings - Fork 84
/
build.cake
169 lines (138 loc) · 5.02 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
var target = Argument ("Target", "Default");
var configuration = Argument ("Configuration", "Release");
var version = EnvironmentVariable ("GITVERSION_NUGETVERSIONV2") ?? Argument ("buildVersion", "0.0.0");
var nugetApiKey = EnvironmentVariable ("NUGET_API_KEY") ?? Argument ("nugetApiKey", "");
Information ($"Running target {target} in configuration {configuration} with version {version}");
var packageDirectory = Directory ("./dist_package");
Task ("Init").Does (() => {
//nothing
});
private IEnumerable<FilePath> GetAllProjects () {
var files = GetFiles ("./src/**/*.csproj").ToArray ();
return files;
}
// Deletes the contents of the Artifacts folder if it contains anything from a previous build.
Task ("Clean")
.Does (() => {
CleanDirectory (packageDirectory);
DotNetClean ("./src",
new DotNetCleanSettings () {
Configuration = configuration,
ArgumentCustomization = builder => builder
.Append($"/p:Version={version}")
});
});
// Run dotnet restore to restore all package references.
Task ("Restore")
.Does (() => {
var settings = new DotNetRestoreSettings();
DotNetRestore ("./src", settings);
});
// Build using the build configuration specified as an argument.
Task ("Build")
.Does (() => {
DotNetBuild ("./src",
new DotNetBuildSettings () {
Configuration = configuration,
ArgumentCustomization = builder => builder
.Append($"/p:Version={version}"),
NoRestore = true,
MSBuildSettings = new DotNetMSBuildSettings {
}
});
});
Task ("ConventionTest")
.Does (() => {
var projects = GetFiles ("./src/Nimbus.Tests.*/Nimbus.Tests.*.csproj");
var settings = new DotNetTestSettings {
NoBuild = true,
NoRestore = true,
Configuration = configuration,
Filter = "Category=\"Convention\"",
ResultsDirectory = packageDirectory.Path.Combine("ConventionTests"),
Loggers = new []{"trx"},
};
foreach (var project in projects) {
Information ("Testing project " + project);
DotNetTest (project.FullPath, settings);
}
});
Task ("UnitTest")
.Does (() => {
var projects = GetFiles ("./src/Nimbus.Tests.*/Nimbus.Tests.*.csproj");
var settings = new DotNetTestSettings {
NoBuild = true,
NoRestore = true,
Configuration = configuration,
Filter = "Category=\"UnitTest\"",
ResultsDirectory = packageDirectory.Path.Combine("UnitTests"),
Loggers = new []{"trx"},
};
foreach (var project in projects) {
Information ("Testing project " + project);
DotNetTest (project.FullPath, settings);
}
});
Task ("IntegrationTest")
.Does (() => {
var projects = GetFiles ("./src/Nimbus.Tests.*/Nimbus.Tests.*.csproj");
var settings = new DotNetTestSettings {
NoBuild = true,
NoRestore = true,
Configuration = configuration,
Filter = "Category!=\"Convention\" & Category!=\"UnitTest\"",
ResultsDirectory = packageDirectory.Path.Combine("IntegrationTests"),
Loggers = new []{"trx"},
};
foreach (var project in projects) {
Information ("Testing project " + project);
DotNetTest (project.FullPath, settings);
}
});
Task ("CollectPackages")
.Does(()=>{
var packages = GetFiles ($"./**/bin/Release/Nimbus*.{version}.nupkg");
CopyFiles(packages, packageDirectory);
});
Task("PushPackages")
.Does(() => {
var settings = new DotNetNuGetPushSettings
{
Source = "https://api.nuget.org/v3/index.json",
//Source = "https://www.myget.org/F/nimbusapi/api/v3/index.json",
ApiKey = nugetApiKey,
};
var packages = GetFiles( $"{packageDirectory}/Nimbus*.nupkg");
foreach (var package in packages)
{
Information("Pushing " + package);
DotNetNuGetPush(package, settings);
};
});
Task("Test")
.IsDependentOn("ConventionTest")
.IsDependentOn("UnitTest")
;
// A meta-task that runs all the steps to Build and Test the app
Task ("BuildAndTest")
.IsDependentOn ("Clean")
.IsDependentOn ("Restore")
.IsDependentOn ("Build")
.IsDependentOn ("Test")
;
Task ("CI")
.IsDependentOn ("BuildAndTest")
//.IsDependentOn ("IntegrationTest")
.IsDependentOn ("CollectPackages")
;
Task ("FastCI")
.IsDependentOn ("BuildAndTest")
.IsDependentOn ("CollectPackages")
;
// The default task to run if none is explicitly specified. In this case, we want
// to run everything starting from Clean, all the way up to Publish.
Task ("Default")
.IsDependentOn ("BuildAndTest")
;
// Executes the task specified in the target argument.
RunTarget (target);