-
Notifications
You must be signed in to change notification settings - Fork 43
/
build.cake
83 lines (71 loc) · 2.73 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
#addin nuget:?package=Cake.FileHelpers&version=7.0.0
var target = Argument("target", "Build");
var nugetKey = Argument("nugetKey", "");
var useTmpLocalNuget = Argument("useTmpLocalNuget", false);
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("Cleaning up old build objects");
CleanDirectories(GetDirectories("./**/bin/"));
CleanDirectories(GetDirectories("./**/obj/"));
});
Task("Build")
.IsDependentOn("Cleanup")
.Does(() =>
{
var buildSettings = new DotNetBuildSettings {
MSBuildSettings = new DotNetMSBuildSettings()
};
buildSettings.MSBuildSettings.Targets.Add("build");
buildSettings.MSBuildSettings.Targets.Add("pack");
buildSettings.Configuration = "Release";
DotNetBuild("./Harmony/Harmony.csproj", buildSettings);
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
var targets = FindRegexMatchGroupInFile("./HarmonyTests/HarmonyTests.csproj", @"<TargetFrameworks>(.*)<\/TargetFrameworks>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Captures[0].Value.Split(';');
foreach (var target in targets)
{
Information($"Testing {target}");
DotNetTest("./HarmonyTests/HarmonyTests.csproj", new DotNetTestSettings {
Configuration = "Release",
Framework = target,
Verbosity = DotNetVerbosity.Normal
});
}
});
Task("Publish")
.IsDependentOn("Build")
.Does(() =>
{
var version = FindRegexMatchGroupInFile("./Directory.Build.props", @"<HarmonyXVersion>(.*)<\/HarmonyXVersion>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Captures[0].Value;
version += FindRegexMatchGroupInFile("./Directory.Build.props", @"<HarmonyXVersionSuffix>(.*)<\/HarmonyXVersionSuffix>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Captures[0].Value;
var versionTagPresent = !string.IsNullOrWhiteSpace(RunGit($"ls-remote --tags origin v{version}"));
if(versionTagPresent)
{
Information("New version exists, no need to push.");
return;
}
Information($"Pushing tag v{version}");
RunGit($"tag v{version}");
RunGit($"push origin v{version}");
if(string.IsNullOrWhiteSpace(nugetKey)){
Information("No NuGet key specified, can't publish");
return;
}
NuGetPush($"./Harmony/bin/Release/HarmonyX.{version}.nupkg", new NuGetPushSettings {
Source = "https://api.nuget.org/v3/index.json",
ApiKey = nugetKey
});
});
RunTarget(target);