-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
144 lines (119 loc) · 5.01 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
#addin nuget:?package=Cake.Coverlet&version=4.0.1
#addin nuget:?package=Cake.AzureDevOps&version=4.0.0
#tool dotnet:?package=GitVersion.Tool&version=5.12.0
#tool dotnet:?package=dotnet-reportgenerator-globaltool&version=5.2.4
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
const string TEST_COVERAGE_OUTPUT_DIR = "coverage";
var solution = "Database.sln";
Task("Clean")
.Does(() => {
if (BuildSystem.GitHubActions.IsRunningOnGitHubActions)
{
Information("Nothing to clean GitHubActions.");
}
else
{
CleanDirectories("./coverage");
CleanDirectories("./artifacts");
DotNetClean(solution);
}
});
Task("Restore")
.IsDependentOn("Clean")
.Description("Restoring the solution dependencies")
.Does(() => {
Information("Restoring the solution dependencies");
var settings = new DotNetRestoreSettings
{
Verbosity = DotNetVerbosity.Minimal,
Sources = new [] { "https://api.nuget.org/v3/index.json" }
};
GetFiles("./**/**/*.csproj").ToList().ForEach(project => {
Information($"Restoring { project.ToString() }");
DotNetRestore(project.ToString(), settings);
});
});
Task("Build")
.IsDependentOn("Restore")
.Does(() => {
var version = GitVersion(new GitVersionSettings {
});
var buildSettings = new DotNetBuildSettings {
Configuration = configuration,
MSBuildSettings = new DotNetMSBuildSettings()
.WithProperty("Version", version.AssemblySemVer)
.WithProperty("AssemblyVersion", version.AssemblySemVer)
.WithProperty("FileVersion", version.AssemblySemVer)
};
var projects = GetFiles("./**/**/*.csproj");
foreach(var project in projects )
{
Information($"Building {project.ToString()}");
DotNetBuild(project.ToString(),buildSettings);
}
});
Task("Test")
.IsDependentOn("Build")
.Does(() => {
var testSettings = new DotNetTestSettings {
Configuration = configuration,
NoBuild = true,
};
var coverageOutput = Directory(TEST_COVERAGE_OUTPUT_DIR);
GetFiles("./tests/**/*.csproj").ToList().ForEach(project => {
Information($"Testing Project : { project.ToString() }");
var codeCoverageOutputName = $"{project.GetFilenameWithoutExtension()}.cobertura.xml";
var coverletSettings = new CoverletSettings {
CollectCoverage = true,
CoverletOutputFormat = CoverletOutputFormat.cobertura,
CoverletOutputDirectory = coverageOutput,
CoverletOutputName =codeCoverageOutputName,
ArgumentCustomization = args => args.Append($"--logger trx"),
ExcludeByFile = ["**/*Migrations/*.cs"]
};
Information($"Running Tests : { project.ToString()}");
DotNetTest(project.ToString(), testSettings, coverletSettings );
});
Information($"Directory Path : { coverageOutput.ToString()}");
var glob = new GlobPattern($"./{ coverageOutput}/*.cobertura.xml");
Information($"Glob Pattern : { glob.ToString()}");
var outputDirectory = Directory("./coverage/reports");
var reportSettings = new ReportGeneratorSettings
{
ArgumentCustomization = args => args.Append($"-reportTypes:HtmlInline_AzurePipelines_Dark;Cobertura")
};
ReportGenerator(glob, outputDirectory, reportSettings);
var summaryDirectory = Directory("./coverage/summary");
var summarySettings = new ReportGeneratorSettings
{
ArgumentCustomization = args => args.Append($"-reportTypes:MarkdownSummaryGithub")
};
ReportGenerator(glob, summaryDirectory, summarySettings);
});
Task("Pack")
.IsDependentOn("Test")
.Does(() => {
var version = GitVersion(new GitVersionSettings {});
Information($"Packing Version : {version.NuGetVersionV2}");
var settings = new DotNetPackSettings
{
Configuration = configuration,
OutputDirectory = "./artifacts",
NoBuild = true,
NoRestore = true,
MSBuildSettings = new DotNetMSBuildSettings()
.WithProperty("PackageVersion", version.NuGetVersionV2)
.WithProperty("Copyright", $"© Copyright nostrfi.net {DateTime.Now.Year}")
.WithProperty("Version", version.NuGetVersionV2)
};
DotNetPack(solution, settings);
Information($"Packed : { solution }");
});
Task("Default")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Pack");
RunTarget(target);