forked from BepInEx/BepInEx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.cake
More file actions
187 lines (156 loc) · 7.26 KB
/
build.cake
File metadata and controls
187 lines (156 loc) · 7.26 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
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
184
185
186
187
#addin nuget:?package=Cake.FileHelpers&version=5.0.0
#addin nuget:?package=SharpZipLib&version=1.4.2
#addin nuget:?package=Cake.Compression&version=0.3.0
#addin nuget:?package=Cake.Json&version=7.0.1
#addin nuget:?package=Newtonsoft.Json&version=13.0.3
var target = Argument("target", "Build");
var isBleedingEdge = Argument("bleeding_edge", false);
var buildId = Argument("build_id", 0);
var lastBuildCommit = Argument("last_build_commit", "");
var buildVersion = "";
var currentCommit = RunGit("rev-parse HEAD");
var currentCommitShort = RunGit("log -n 1 --pretty=\"format:%h\"").Trim();
var currentBranch = RunGit("rev-parse --abbrev-ref HEAD");
var latestTag = RunGit("describe --tags --abbrev=0");
string RunGit(string command, string separator = "")
{
using(var process = StartAndReturnProcess("git", new ProcessSettings { Arguments = command, RedirectStandardOutput = true }))
{
process.WaitForExit();
return string.Join(separator, process.GetStandardOutput());
}
}
Task("Cleanup")
.Does(() =>
{
Information("Removing old binaries");
CreateDirectory("./bin");
CleanDirectory("./bin");
Information("Cleaning up old build objects");
CleanDirectories(GetDirectories("./**/bin/"));
CleanDirectories(GetDirectories("./**/obj/"));
});
Task("PullDependencies")
.Does(() =>
{
Information("Updating git submodules");
StartProcess("git", "submodule update --init --recursive");
Information("Restoring NuGet packages");
DotNetRestore("./BepInEx.sln");
});
Task("Build")
.IsDependentOn("Cleanup")
.IsDependentOn("PullDependencies")
.Does(() =>
{
var bepinExProperties = Directory("./BepInEx/Properties");
buildVersion = FindRegexMatchGroupInFile(File("Directory.Build.props"), "<BepInExVersionPrefix>(.+?)<\\/BepInExVersionPrefix>", 1, System.Text.RegularExpressions.RegexOptions.None).Value;
var settings = new DotNetPublishSettings
{
Configuration = "Release",
};
if(isBleedingEdge)
{
settings.MSBuildSettings = new DotNetMSBuildSettings().WithProperty("BepInExVersionSuffix", "be." + buildId);
buildVersion = buildVersion + "-be." + buildId;
CopyFile(bepinExProperties + File("AssemblyInfo.cs"), bepinExProperties + File("AssemblyInfo.cs.bak"));
FileAppendText(bepinExProperties + File("AssemblyInfo.cs"),
TransformText("\n[assembly: BepInEx.BuildInfo(\"BLEEDING EDGE Build #<%buildNumber%> from <%shortCommit%> at <%branchName%>\")]\n")
.WithToken("buildNumber", buildId)
.WithToken("shortCommit", currentCommit)
.WithToken("branchName", currentBranch)
.ToString());
}
settings.OutputDirectory = "./bin/";
DotNetPublish("./BepInEx.Preloader/BepInEx.Preloader.csproj", settings);
settings.OutputDirectory = "./bin/patcher/";
DotNetPublish("./BepInEx.Patcher/BepInEx.Patcher.csproj", settings);
})
.Finally(() =>
{
var bepinExProperties = Directory("./BepInEx/Properties");
if(isBleedingEdge)
{
DeleteFile(bepinExProperties + File("AssemblyInfo.cs"));
MoveFile(bepinExProperties + File("AssemblyInfo.cs.bak"), bepinExProperties + File("AssemblyInfo.cs"));
}
});
Task("MakeDist")
.IsDependentOn("Build")
.Does(() =>
{
var distDir = Directory("./bin/dist");
var distPatcherDir = distDir + Directory("patcher");
CreateDirectory(distDir);
CreateDirectory(distPatcherDir);
var changelog = TransformText("<%commit_count%> commits since <%last_tag%>\r\n\r\nChangelog (excluding merges):\r\n<%commit_log%>")
.WithToken("commit_count", RunGit($"rev-list --count {latestTag}..HEAD"))
.WithToken("last_tag", latestTag)
.WithToken("commit_log", RunGit($"--no-pager log --no-merges --pretty=\"format:* (%h) [%an] %s\" {latestTag}..HEAD", "\r\n"))
.ToString();
void PackageBepin(string os, string arch)
{
var distArchDir = distDir + Directory($"{os}_{arch}");
var bepinDir = distArchDir + Directory("BepInEx");
CreateDirectory(distArchDir);
CreateDirectory(bepinDir + Directory("core"));
CopyFiles("./bin/*.*", bepinDir + Directory("core"));
FileWriteText(distArchDir + File("changelog.txt"), changelog);
}
PackageBepin("win", "x64");
PackageBepin("win", "x86");
PackageBepin("linux", "x64");
PackageBepin("linux", "x86");
PackageBepin("macos", "x64");
CopyFileToDirectory(File("./bin/patcher/BepInEx.Patcher.exe"), distPatcherDir);
});
Task("Pack")
.IsDependentOn("MakeDist")
.Does(() =>
{
var distDir = Directory("./bin/dist");
var commitPrefix = isBleedingEdge ? $"_{currentCommitShort}_" : "_";
Information("Packing BepInEx");
ZipCompress(distDir + Directory("win_x86"), distDir + File($"BepInEx_win_x86{commitPrefix}{buildVersion}.zip"));
ZipCompress(distDir + Directory("win_x64"), distDir + File($"BepInEx_win_x64{commitPrefix}{buildVersion}.zip"));
ZipCompress(distDir + Directory("linux_x86"), distDir + File($"BepInEx_linux_x86{commitPrefix}{buildVersion}.zip"));
ZipCompress(distDir + Directory("linux_x64"), distDir + File($"BepInEx_linux_x64{commitPrefix}{buildVersion}.zip"));
ZipCompress(distDir + Directory("macos_x64"), distDir + File($"BepInEx_macos_x64{commitPrefix}{buildVersion}.zip"));
Information("Packing BepInEx.Patcher");
ZipCompress(distDir + Directory("patcher"), distDir + File($"BepInEx_Patcher{commitPrefix}{buildVersion}.zip"));
if(isBleedingEdge)
{
var changelog = "";
if(!string.IsNullOrEmpty(lastBuildCommit)) {
changelog = TransformText("<ul><%changelog%></ul>")
.WithToken("changelog", RunGit($"--no-pager log --no-merges --pretty=\"format:<li>(<code>%h</code>) [%an] %s</li>\" {lastBuildCommit}..HEAD"))
.ToString();
}
FileWriteText(distDir + File("info.json"),
SerializeJsonPretty(new Dictionary<string, object>{
["id"] = buildId.ToString(),
["date"] = DateTime.Now.ToString("o"),
["changelog"] = changelog,
["hash"] = currentCommit,
["artifacts"] = new Dictionary<string, object>[] {
new Dictionary<string, object> {
["file"] = $"BepInEx_x64{commitPrefix}{buildVersion}.zip",
["description"] = "BepInEx for x64 machines"
},
new Dictionary<string, object> {
["file"] = $"BepInEx_x86{commitPrefix}{buildVersion}.zip",
["description"] = "BepInEx for x86 machines"
},
new Dictionary<string, object> {
["file"] = $"BepInEx_unix{commitPrefix}{buildVersion}.zip",
["description"] = "BepInEx for Unix with GCC (Linux, MacOS)"
},
new Dictionary<string, object> {
["file"] = $"BepInEx_Patcher{commitPrefix}{buildVersion}.zip",
["description"] = "Hardpatcher for BepInEx. IMPORTANT: USE ONLY IF DOORSTOP DOES NOT WORK FOR SOME REASON!"
}
}
}));
}
});
RunTarget(target);