This repository has been archived by the owner on Oct 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.cake
183 lines (166 loc) · 6.66 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//////////////////////////////////////////////////////////////////////
// NUGET PACKAGES
//////////////////////////////////////////////////////////////////////
#tool nuget:?package=NUnit.ConsoleRunner&version=3.10.0
#tool nuget:?package=JetBrains.dotCover.CommandLineTools&version=2019.2.3
#tool nuget:?package=ReportGenerator&version=4.3.6
#tool nuget:?package=Codecov&version=1.8.0
#tool nuget:?package=GitVersion.CommandLine&version=5.1.2
//////////////////////////////////////////////////////////////////////
// CAKE ADDINS
//////////////////////////////////////////////////////////////////////
#addin nuget:?package=Octokit&version=0.32.0
#addin nuget:?package=Cake.Codecov&version=0.7.0
//////////////////////////////////////////////////////////////////////
// IMPORTS
//////////////////////////////////////////////////////////////////////
using Octokit;
using System.Xml;
//////////////////////////////////////////////////////////////////////
// PROJECT VARIABLES
//////////////////////////////////////////////////////////////////////
var projectName = "Kapture";
var authorName = "kalilistic";
var packageName = "Kapture";
var packageDescription = "FFXIV ACT Loot Tracker Plugin";
var packageTags = "FFXIV ACT plugin loot";
//////////////////////////////////////////////////////////////////////
// ARGUMENT VARIABLES
//////////////////////////////////////////////////////////////////////
var target = Argument ("target", "Default");
var configuration = Argument ("configuration", "Release");
var verbosity = Argument<string> ("verbosity", "Information");
//////////////////////////////////////////////////////////////////////
// ENVIRONMENT VARIABLES
//////////////////////////////////////////////////////////////////////
var githubToken = EnvironmentVariable ("GITHUB_TOKEN");
//////////////////////////////////////////////////////////////////////
// BUILD SYSTEM VARIABLES
//////////////////////////////////////////////////////////////////////
var isLocalBuild = BuildSystem.IsLocalBuild;
//////////////////////////////////////////////////////////////////////
// OTHER GLOBAL VARIABLES
//////////////////////////////////////////////////////////////////////
var buildDir = Directory ("./src") + Directory (projectName) + Directory ("bin") + Directory (configuration);
var buildFilePath = Directory (buildDir) + File (projectName + ".dll");
var solutionFile = Directory ("./src") + File (projectName + ".sln");
var testResultDir = Directory ("./test-result");
var testResultFile = testResultDir + File ("NUnitResults.xml");
var coverageReportXML = testResultDir + File ("result.xml");
var version = string.Empty;
var buildSuccess = true;
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task ("Clean")
.Does (() => {
CleanDirectory (buildDir);
Information ("Build directory cleaned.");
});
Task ("Restore-Nuget-Packages")
.IsDependentOn ("Clean")
.Does (() => {
NuGetRestore (solutionFile);
});
Task ("Set-Version")
.IsDependentOn ("Restore-Nuget-Packages")
.Does (() => {
if (isLocalBuild) {
version = "1.0.0-LOCAL";
} else {
version = GitVersion ().SemVer;
}
Information ("Version set to " + version);
});
Task ("Create-Assembly-Info")
.WithCriteria (!isLocalBuild)
.IsDependentOn ("Set-Version")
.Does (() => {
GitVersion (new GitVersionSettings {
UpdateAssemblyInfo = true
});
Information ("Assembly info updated.");
});
Task ("Build")
.IsDependentOn ("Create-Assembly-Info")
.Does (() => {
MSBuild (solutionFile, settings =>
settings.SetConfiguration (configuration));
})
.OnError (exception => {
buildSuccess = false;
});
Task ("Run-Unit-Tests")
.WithCriteria (buildSuccess)
.IsDependentOn ("Build")
.Does (() => {
MSBuild (solutionFile, settings =>
settings.SetConfiguration ("Debug"));
var testsPath = "./src/**/bin/Debug/*.Test.dll";
var coverageReportDCVR = testResultDir + File ("result.dcvr");
DotCoverCover (tool => {
tool.NUnit3 (
testsPath,
new NUnit3Settings {
Results = new [] { new NUnit3Result { FileName = testResultFile } },
ShadowCopy = false
});
},
new FilePath (coverageReportDCVR),
new DotCoverCoverSettings ()
.WithFilter("+:" + projectName)
.WithFilter("-:" + projectName + ".Test"));
DotCoverReport (new FilePath (coverageReportDCVR),
new FilePath (coverageReportXML),
new DotCoverReportSettings {
ReportType = DotCoverReportType.DetailedXML
});
})
.OnError (exception => {
buildSuccess = false;
});
Task ("Publish-Github-Release")
.WithCriteria (buildSuccess)
.WithCriteria (!isLocalBuild)
.IsDependentOn ("Run-Unit-Tests")
.Does (async () => {
var gitTag = "v" + version;
var client = new GitHubClient (new ProductHeaderValue (projectName));
var tokenAuth = new Credentials (githubToken);
client.Credentials = tokenAuth;
var newRelease = new NewRelease (gitTag);
newRelease.Name = "Version " + version;
newRelease.Body = "This is a pre-release and may not be stable.";
newRelease.Draft = false;
newRelease.Prerelease = true;
await client.Repository.Release.Create (authorName, projectName, newRelease);
using (var fileStream = System.IO.File.OpenRead (buildFilePath)) {
var assetUpload = new ReleaseAssetUpload () {
FileName = projectName + ".dll",
ContentType = "application/x-msdownload",
RawData = fileStream
};
var release = await client.Repository.Release.Get (authorName, projectName, gitTag);
await client.Repository.Release.UploadAsset (release, assetUpload);
}
Information ("Created GitHub release.");
});
Task ("Check-Build-Status")
.IsDependentOn ("Publish-Github-Release")
.Does (() => {
if (buildSuccess) {
Information ("Tasks complete.");
} else {
throw new Exception ("Build failed.");
}
});
Task ("Default")
.IsDependentOn ("Clean")
.IsDependentOn ("Restore-Nuget-Packages")
.IsDependentOn ("Set-Version")
.IsDependentOn ("Create-Assembly-Info")
.IsDependentOn ("Build")
.IsDependentOn ("Run-Unit-Tests")
.IsDependentOn ("Publish-Github-Release")
.IsDependentOn ("Check-Build-Status");
RunTarget (target);