-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.cake
73 lines (61 loc) · 1.91 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
// Addins
#tool MSBuild.SonarQube.Runner.Tool&version=4.6.0
#addin nuget:?package=Cake.Coverlet&version=2.5.4
// Environment variables
var target = Argument("target", EnvironmentVariable("BUILD_TARGET") ?? "Default");
var buildNumber = EnvironmentVariable("BUILD_NUMBER") ?? "0";
var nugetApiKey = EnvironmentVariable("NUGET_API_KEY");
var isStableVersion = !string.IsNullOrEmpty(EnvironmentVariable("NUGET_STABLE"));
string versionSuffix = null;
var coveragePath = ".coverage/";
// Targets
Setup(setupContext =>
{
if (buildNumber != null && !isStableVersion)
{
versionSuffix = "build." + buildNumber;
}
CreateDirectory(coveragePath);
});
Task("Test")
.Does(() => DotNetCoreTest(".", new DotNetCoreTestSettings
{
Configuration = "Release",
}, new CoverletSettings
{
CollectCoverage = true,
CoverletOutputFormat = CoverletOutputFormat.opencover,
CoverletOutputDirectory = coveragePath,
CoverletOutputName = $"results-{DateTime.UtcNow:dd-MM-yyyy-HH-mm-ss-FFF}"
}));
Task("Pack")
.Does(() =>
{
var buildSettings = new DotNetCoreBuildSettings
{
Configuration = "Release",
VersionSuffix = versionSuffix
};
Information("NuGet version suffix: " + buildSettings.VersionSuffix);
DotNetCoreBuild(".", buildSettings);
});
Task("Default")
.IsDependentOn("Test")
.IsDependentOn("Pack");
Task("Publish")
.IsDependentOn("Default")
.Does(() =>
{
var pkgPath = GetFiles($"./**/bin/Release/*{versionSuffix ?? string.Empty}.nupkg").First();
if (string.IsNullOrEmpty(nugetApiKey))
{
Error("NuGet API key not set");
return;
}
NuGetPush(pkgPath, new NuGetPushSettings
{
ApiKey = nugetApiKey,
Source = "https://api.nuget.org/v3/index.json"
});
});
RunTarget(target);