forked from giacomelli/GeneticSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.cake
More file actions
120 lines (105 loc) · 3.03 KB
/
build.cake
File metadata and controls
120 lines (105 loc) · 3.03 KB
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
// Tools & Addins
#tool dotnet:?package=dotnet-sonarscanner&version=11.0.0
#addin nuget:?package=Cake.Sonar&version=5.0.0
#addin nuget:?package=Cake.Git&version=5.0.1
var target = Argument("target", "Default");
var solutionDir = "./src";
var sonarLogin = EnvironmentVariable("GeneticSharp_SonarQube_login");
string DetectBranch()
{
// AppVeyor: PR source branch.
var appveyorPrBranch = EnvironmentVariable("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH");
if (!string.IsNullOrWhiteSpace(appveyorPrBranch))
return appveyorPrBranch;
// AppVeyor: normal branch.
var appveyorBranch = EnvironmentVariable("APPVEYOR_REPO_BRANCH");
if (!string.IsNullOrWhiteSpace(appveyorBranch))
return appveyorBranch;
// Local fallback.
try
{
return GitBranchCurrent(".").FriendlyName;
}
catch
{
return "master";
}
}
var branch = DetectBranch();
// Validation
if (string.IsNullOrWhiteSpace(sonarLogin))
{
throw new Exception("Set 'GeneticSharp_SonarQube_login' env var with a SonarCloud token from https://sonarcloud.io/account/security/.");
}
// Tasks
Task("Restore")
.Does(() =>
{
DotNetRestore(solutionDir);
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetBuild(solutionDir, new DotNetBuildSettings
{
Configuration = "Release",
NoRestore = true
});
});
Task("Test")
.Does(() =>
{
DotNetTest(solutionDir, new DotNetTestSettings
{
Configuration = "Release",
NoBuild = true,
ArgumentCustomization = args =>
args.Append("/p:CollectCoverage=true")
.Append("/p:CoverletOutput=./coverage")
.Append("/p:CoverletOutputFormat=opencover")
});
});
Task("SonarBegin")
.Does(() =>
{
SonarBegin(new SonarBeginSettings
{
Key = "GeneticSharp",
Organization = "giacomelli-github",
Url = "https://sonarcloud.io",
Token = sonarLogin,
Branch = branch,
Verbose = false,
OpenCoverReportsPath = "**/coverage.opencover.xml",
Exclusions = string.Join(",", new[]{
"GeneticSharp.Benchmarks/**/*.cs",
"**/*Test.cs",
"**/Samples/**/*.cs",
"GeneticSharp.Runner.BlazorApp/**/*.*",
"src/GeneticSharp.Runner.BlazorApp/wwwroot/js/canvas-helper.js",
"GeneticSharp.Runner.GtkApp/*.*",
"src/GeneticSharp.Runner.GtkApp/MainWindow.cs",
"src/GeneticSharp.Runner.GtkApp/PropertyEditor.cs",
"Templates/content/**/*.*",
"src/Templates/content/TspBlazorApp/wwwroot/js/canvas-helper.js",
"**/*.xml",
"**/Program.cs",
"**/AssemblyInfo.cs"
})
});
});
Task("SonarEnd")
.Does(() =>
{
SonarEnd(new SonarEndSettings
{
Token = sonarLogin
});
});
Task("Default")
.IsDependentOn("SonarBegin")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("SonarEnd");
RunTarget(target);