-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
168 lines (134 loc) · 5.16 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
166
167
168
// For inspiration see: https://github.com/Jericho/Picton/blob/develop/build.cake
// Install addins.
#addin "nuget:?package=Cake.Coveralls&version=0.5.0"
#addin "nuget:?package=Cake.Json&version=1.0.2.13"
// Install tools.
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0-beta0012"
#tool "nuget:?package=OpenCover&version=4.6.519"
#tool "nuget:?package=coveralls.io&version=1.3.4"
#tool "nuget:?package=xunit.runner.console&version=2.2.0"
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var libraryName = "PinSharp";
var sourceFolder = "./";
var xunitRunnerJsonFile = "./PinSharp.Tests/xunit.runner.json";
var testProjectFile = "./PinSharp.Tests/PinSharp.Tests.csproj";
var codeCoverageOutput = "coverage.xml";
var codeCoverageFilter = "+[*]* -[*.Tests]*";
var cakeVersion = typeof(ICakeContext).Assembly.GetName().Version.ToString();
var versionInfo = GitVersion(new GitVersionSettings() { OutputType = GitVersionOutput.Json });
var milestone = string.Concat("v", versionInfo.MajorMinorPatch);
var buildVersion = $"{versionInfo.SemVer}+{AppVeyor.Environment.Build.Number}";
var packageVersion = versionInfo.LegacySemVer;
var isLocalBuild = BuildSystem.IsLocalBuild;
var isPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest;
var isTagged = (
BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag &&
!string.IsNullOrWhiteSpace(BuildSystem.AppVeyor.Environment.Repository.Tag.Name)
);
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
Information($"Building version {packageVersion} of {libraryName} using version {cakeVersion} of Cake" + Environment.NewLine);
Information("Variables:" + Environment.NewLine
+ $"\t IsLocalBuild: {isLocalBuild}" + Environment.NewLine
+ $"\t IsPullRequest: {isPullRequest}" + Environment.NewLine
+ $"\t IsTagged: {isTagged}" + Environment.NewLine
);
Information("Versions:" + Environment.NewLine
+ $"\t Milestone: {milestone}" + Environment.NewLine
+ $"\t BuildNumber: {AppVeyor.Environment.Build.Number}" + Environment.NewLine
+ $"\t BuildVersion: {buildVersion}" + Environment.NewLine
+ $"\t PackageVersion: {packageVersion}" + Environment.NewLine
);
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("AppVeyor_Set-Build-Version")
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
AppVeyor.UpdateBuildVersion(buildVersion);
});
Task("Restore-NuGet-Packages")
.Does(() =>
{
DotNetCoreRestore();
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
DotNetCoreBuild(sourceFolder + libraryName + ".sln", new DotNetCoreBuildSettings
{
Configuration = configuration,
ArgumentCustomization = args => args.Append("/p:SemVer=" + packageVersion)
});
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
DotNetCoreTest(testProjectFile, new DotNetCoreTestSettings
{
NoBuild = true,
Configuration = configuration
});
});
Task("Disable-xUnit-ShadowCopy")
.Does(() =>
{
Information("Disabling xUnit shadow copying assemblies for code coverage to work...");
SerializeJsonToFile(xunitRunnerJsonFile, new { shadowCopy = false });
});
Task("Run-Code-Coverage")
.IsDependentOn("Disable-xUnit-ShadowCopy")
.IsDependentOn("Build")
.Does(() =>
{
Action<ICakeContext> testAction = ctx => ctx.DotNetCoreTest(testProjectFile, new DotNetCoreTestSettings
{
NoBuild = true,
Configuration = configuration
});
OpenCover(testAction,
codeCoverageOutput,
new OpenCoverSettings
{
OldStyle = true,
SkipAutoProps = true,
MergeOutput = false
}
.WithFilter(codeCoverageFilter)
);
if (FileExists(xunitRunnerJsonFile))
DeleteFile(xunitRunnerJsonFile);
});
Task("Upload-Coverage-Result")
.WithCriteria(() => !isLocalBuild)
.Does(() =>
{
CoverallsIo(codeCoverageOutput);
});
///////////////////////////////////////////////////////////////////////////////
// TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("AppVeyor")
.IsDependentOn("AppVeyor_Set-Build-Version")
.IsDependentOn("Run-Code-Coverage")
.IsDependentOn("Upload-Coverage-Result");
Task("Default")
.IsDependentOn("AppVeyor");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);