forked from LitJSON/litjson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
230 lines (194 loc) · 6.95 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#tool "nuget:https://api.nuget.org/v3/index.json?package=GitVersion.CommandLine&version=3.6.2"
#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// PARAMETERS
//////////////////////////////////////////////////////////////////////
DotNetCoreMSBuildSettings msBuildSettings = null;
string version = null,
semVersion = null,
milestone = null;
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
Information("Calculating Semantic Version");
if (!BuildSystem.IsLocalBuild)
{
GitVersion(new GitVersionSettings{
OutputType = GitVersionOutput.BuildServer
});
}
CopyFile("./src/LitJson/AssemblyInfo.cs.in", "./src/LitJson/AssemblyInfo.cs");
GitVersion assertedVersions = GitVersion(new GitVersionSettings
{
UpdateAssemblyInfoFilePath = "./src/LitJson/AssemblyInfo.cs",
UpdateAssemblyInfo = true,
OutputType = GitVersionOutput.Json,
});
version = assertedVersions.MajorMinorPatch;
semVersion = assertedVersions.LegacySemVerPadded;
milestone = string.Concat("v", version);
Information("Calculated Semantic Version: {0}", semVersion);
msBuildSettings = new DotNetCoreMSBuildSettings()
.WithProperty("Version", semVersion)
.WithProperty("AssemblyVersion", version)
.WithProperty("FileVersion", version);
if(!IsRunningOnWindows())
{
var frameworkPathOverride = new FilePath(typeof(object).Assembly.Location).GetDirectory().FullPath + "/";
// Use FrameworkPathOverride when not running on Windows.
Information("Build will use FrameworkPathOverride={0} since not building on Windows.", frameworkPathOverride);
msBuildSettings.WithProperty("FrameworkPathOverride", frameworkPathOverride);
}
// Executed BEFORE the first task.
Information("Running tasks...");
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() => {
CleanDirectories(
new[] {
"./src/bin",
"./test/bin",
"./src/obj",
"./test/obj",
"./artifacts/nuget"
}
);
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() => {
DotNetCoreRestore("./LitJSON.sln",
new DotNetCoreRestoreSettings { MSBuildSettings = msBuildSettings }
);
});
Task("Build")
.IsDependentOn("Restore")
.Does(() => {
DotNetCoreBuild("./LitJSON.sln",
new DotNetCoreBuildSettings {
Configuration = configuration,
MSBuildSettings = msBuildSettings,
ArgumentCustomization = args => args.Append("--no-restore")
}
);
});
Task("Test")
.IsDependentOn("Build")
.Does(() => {
DotNetCoreTest("./test/LitJSON.Tests.csproj",
new DotNetCoreTestSettings {
Configuration = configuration,
Framework = "netcoreapp2.0",
NoBuild = true,
ArgumentCustomization = args => args.Append("--no-restore")
}
);
NUnit3("./test/**/bin/" + configuration + "/net45/*.Tests.dll", new NUnit3Settings {
NoResults = true
});
});
Task("Test-SourceLink")
.IsDependentOn("Build")
.WithCriteria(IsRunningOnWindows())
.Does(() => {
foreach(var asssembly in GetFiles("./src/LitJSON/bin/" + configuration + "/**/*.dll"))
{
DotNetCoreTool("./src/LitJSON/LitJSON.csproj", "sourcelink", $"test {asssembly}");
}
});
Task("Package")
.IsDependentOn("Test")
.IsDependentOn("Test-SourceLink")
.Does(() => {
DotNetCorePack("./src/LitJSON/LitJSON.csproj",
new DotNetCorePackSettings {
Configuration = configuration,
NoBuild = true,
IncludeSymbols = true,
OutputDirectory = "./artifacts/nuget",
MSBuildSettings = msBuildSettings,
ArgumentCustomization = args => args.Append("--no-restore")
}
);
});
Task("Upload-AppVeyor-Artifacts")
.IsDependentOn("Package")
.WithCriteria(AppVeyor.IsRunningOnAppVeyor)
.Does(() => {
foreach(var artifact in GetFiles("./artifacts/**/*.*"))
{
AppVeyor.UploadArtifact(artifact);
}
});
Task("Publish-MyGet")
.IsDependentOn("Package")
.WithCriteria((AppVeyor.IsRunningOnAppVeyor && !AppVeyor.Environment.PullRequest.IsPullRequest)
|| StringComparer.OrdinalIgnoreCase.Equals(target, "Publish-MyGet"))
.Does(() => {
// Resolve the API key.
var apiKey = EnvironmentVariable("MYGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet API key.");
}
// Resolve the API url.
var apiUrl = EnvironmentVariable("MYGET_API_URL");
if(string.IsNullOrEmpty(apiUrl)) {
throw new InvalidOperationException("Could not resolve MyGet API url.");
}
foreach(var package in (GetFiles("./artifacts/nuget/*.nupkg") - GetFiles("./artifacts/nuget/*.symbols.nupkg")))
{
DotNetCoreNuGetPush(package.FullPath,
new DotNetCoreNuGetPushSettings {
ApiKey = apiKey,
Source = apiUrl
}
);
}
});
Task("Publish-NuGet")
.IsDependentOn("Package")
.WithCriteria((AppVeyor.IsRunningOnAppVeyor && AppVeyor.Environment.Repository.Tag.IsTag && !AppVeyor.Environment.PullRequest.IsPullRequest)
|| StringComparer.OrdinalIgnoreCase.Equals(target, "Publish-NuGet"))
.Does(() => {
// Resolve the API key.
var apiKey = EnvironmentVariable("NUGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet API key.");
}
// Resolve the API url.
var apiUrl = EnvironmentVariable("NUGET_API_URL");
if(string.IsNullOrEmpty(apiUrl)) {
throw new InvalidOperationException("Could not resolve MyGet API url.");
}
foreach(var package in (GetFiles("./artifacts/nuget/*.nupkg") - GetFiles("./artifacts/nuget/*.symbols.nupkg")))
{
DotNetCoreNuGetPush(package.FullPath,
new DotNetCoreNuGetPushSettings {
ApiKey = apiKey,
Source = apiUrl
}
);
}
});
Task("AppVeyor")
.IsDependentOn("Upload-AppVeyor-Artifacts")
.IsDependentOn("Publish-MyGet")
.IsDependentOn("Publish-NuGet");
Task("Default")
.IsDependentOn("Package");
RunTarget(target);