-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.cake
103 lines (88 loc) · 2.67 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
// Addins
#tool MSBuild.SonarQube.Runner.Tool&version=4.6.0
#addin Cake.Sonar&version=1.1.22
#addin Cake.Coverlet&version=2.3.4
var solutionPath = "./src";
// Environment variables
var target = Argument("target", EnvironmentVariable("BUILD_TARGET") ?? "Default");
var buildNumber = EnvironmentVariable("BITRISE_BUILD_NUMBER") ?? "0";
var nugetApiKey = EnvironmentVariable("NUGET_API_KEY");
var isStableVersion = !string.IsNullOrEmpty(EnvironmentVariable("NUGET_STABLE"));
var sonarLogin = EnvironmentVariable("SONAR_LOGIN");
var sonarOrganization = EnvironmentVariable("SONAR_ORGANIZATION");
var sonarKey = EnvironmentVariable("SONAR_KEY");
var sonarHost = EnvironmentVariable("SONAR_HOST");
string versionSuffix = null;
var coveragePath = ".coverage/";
// Targets
Setup(setupContext =>
{
if (buildNumber != null && !isStableVersion)
{
versionSuffix = "build." + buildNumber;
}
CreateDirectory(coveragePath);
if (!string.IsNullOrEmpty(sonarLogin))
{
SonarBegin(new SonarBeginSettings
{
Login = sonarLogin,
Organization = sonarOrganization,
Key = sonarKey,
Url = sonarHost,
OpenCoverReportsPath = coveragePath + "*.xml"
});
}
});
Teardown(context =>
{
if (!string.IsNullOrEmpty(sonarLogin))
{
SonarEnd(new SonarEndSettings
{
Login = sonarLogin
});
}
});
Task("Test")
.Does(() => DotNetCoreTest(solutionPath, 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(solutionPath, 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);