-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
165 lines (135 loc) · 5.04 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
#tool "dotnet:?package=GitVersion.Tool&version=5.12.0"
#tool "nuget:?package=NuGet.CommandLine&version=6.7.0"
#tool "nuget:?package=dotnet-sonarscanner&version=5.14.0"
#addin "nuget:?package=Cake.Sonar&version=1.1.32"
var target = Argument("target", "Default");
var sonarLoginToken = Argument("sonarLogin", EnvironmentVariable("SONAR_LOGIN") ?? "");
var nugetApiKey = Argument("nugetApiKey", EnvironmentVariable("NUGET_API_KEY") ?? "");
//////////////////////////////////////////////////////////////////////
// Build Variables
/////////////////////////////////////////////////////////////////////
var solution = "./NServiceBus.Persistence.Sqlite.sln";
var project = "./src/NServiceBus.Persistence.Sqlite/NServiceBus.Persistence.Sqlite.csproj";
var outputDir = MakeAbsolute(Directory("./buildArtifacts/"));
var outputDirNuget = outputDir.Combine("NuGet");
var sonarProjectKey = "CHG-MERIDIAN_NServiceBus.Persistence.Sqlite";
var sonarUrl = "https://sonarcloud.io";
var sonarOrganization = "chg-meridian";
var outputDirTemp = outputDir.Combine("Temp");
var outputDirTests = outputDirTemp.Combine("Tests");
var codeCoverageResultFilePath = MakeAbsolute(outputDirTests).Combine("**/").CombineWithFilePath("coverage.opencover.xml");
var testResultsPath = MakeAbsolute(outputDirTests).CombineWithFilePath("*.trx");
var nugetPublishFeed = "https://api.nuget.org/v3/index.json";
var isLocalBuild = BuildSystem.IsLocalBuild;
var isMainBranch = StringComparer.OrdinalIgnoreCase.Equals("refs/heads/main", BuildSystem.GitHubActions.Environment.Workflow.Ref);
var isPullRequest = BuildSystem.GitHubActions.Environment.PullRequest.IsPullRequest;
var runSonar = !string.IsNullOrWhiteSpace(sonarLoginToken);
var gitHubEvent = EnvironmentVariable("GITHUB_EVENT_NAME");
var isReleaseCreation = string.Equals(gitHubEvent, "release");
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Setup(context =>
{
Information($"Local build: {isLocalBuild}");
Information($"Main branch: {isMainBranch}");
Information($"Pull request: {isPullRequest}");
Information($"Run sonar: {runSonar}");
Information($"ref: {BuildSystem.GitHubActions.Environment.Workflow.Ref}");
Information($"Is release creation: {isReleaseCreation}");
});
Task("Clean")
.Description("Removes the output directory")
.Does(() => {
EnsureDirectoryDoesNotExist(outputDir, new DeleteDirectorySettings {
Recursive = true,
Force = true
});
CreateDirectory(outputDir);
});
GitVersion versionInfo = null;
Task("Version")
.Description("Retrieves the current version from the git repository")
.Does(() => {
versionInfo = GitVersion(new GitVersionSettings {
UpdateAssemblyInfo = false
});
Information("Version: "+ versionInfo.FullSemVer);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Version")
.Does(() => {
var msBuildSettings = new DotNetMSBuildSettings()
{
Version = versionInfo.AssemblySemVer,
InformationalVersion = versionInfo.InformationalVersion,
PackageVersion = versionInfo.NuGetVersionV2
}.WithProperty("PackageOutputPath", outputDirNuget.FullPath);
var settings = new DotNetBuildSettings {
Configuration = "Release",
MSBuildSettings = msBuildSettings
};
DotNetBuild(solution, settings);
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new DotNetTestSettings {
Configuration = "Release",
Loggers = new[]{"trx;"},
ResultsDirectory = outputDirTests,
Collectors = new[] {"XPlat Code Coverage"},
ArgumentCustomization = a => a.Append("-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover"),
NoBuild = true
};
DotNetTest(solution, settings);
});
Task("SonarBegin")
.WithCriteria(runSonar)
.Does(() => {
SonarBegin(new SonarBeginSettings {
Key = sonarProjectKey,
Url = sonarUrl,
Organization = sonarOrganization,
Token = sonarLoginToken,
UseCoreClr = true,
VsTestReportsPath = testResultsPath.ToString(),
OpenCoverReportsPath = codeCoverageResultFilePath.ToString()
});
});
Task("SonarEnd")
.WithCriteria(runSonar)
.Does(() => {
SonarEnd(new SonarEndSettings {
Token = sonarLoginToken
});
});
Task("Publish")
.WithCriteria(isReleaseCreation)
.IsDependentOn("Test")
.IsDependentOn("Version")
.Description("Pushes the created NuGet packages to nuget.org")
.Does(() => {
Information($"Upload packages from {outputDirNuget.FullPath}");
// Get the paths to the packages ordered by the file names in order to get the nupkg first.
var packages = GetFiles(outputDirNuget.CombineWithFilePath("*.*nupkg").ToString()).OrderBy(x => x.FullPath).ToArray();
if (packages.Length == 0)
{
Error("No packages found to upload");
return;
}
// Push the package and symbols
NuGetPush(packages, new NuGetPushSettings {
Source = nugetPublishFeed,
ApiKey = nugetApiKey,
SkipDuplicate = true
});
});
Task("Default")
.IsDependentOn("SonarBegin")
.IsDependentOn("Test")
.IsDependentOn("SonarEnd")
.IsDependentOn("Publish");
RunTarget(target);