-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.cake
77 lines (65 loc) · 2.24 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
#addin nuget:?package=Cake.FileHelpers&version=3.2.1
#addin "nuget:?package=Cake.Incubator&version=5.1.0"
var target = Argument("target", "Build");
var nugetKey = Argument("nugetKey", "");
var nugetSource = Argument("nugetSource", "https://api.nuget.org/v3/index.json");
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("PullDependencies")
.Does(() =>
{
Information("Restoring NuGet packages");
NuGetRestore("./BepInEx.Analyzers.sln");
});
Task("Build")
.IsDependentOn("Cleanup")
.IsDependentOn("PullDependencies")
.Does(() =>
{
var buildSettings = new MSBuildSettings {
Configuration = "Nuget",
Restore = true
};
MSBuild("./BepInEx.Analyzers.sln", buildSettings);
});
Task("Publish")
.IsDependentOn("Build")
.Does(() =>
{
var version = FindRegexMatchGroupInFile("./BepInEx.Analyzers/BepInEx.Analyzers.Package/BepInEx.Analyzers.Package.csproj", @"<PackageVersion>(.*)<\/PackageVersion>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
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;
}
if(string.IsNullOrWhiteSpace(nugetSource)){
Information("No NuGet push source specified, can't publish");
return;
}
NuGetPush($"./BepInEx.Analyzers/BepInEx.Analyzers.Package/bin/Nuget/BepInEx.Analyzers.{version}.nupkg", new NuGetPushSettings {
Source = nugetSource,
ApiKey = nugetKey
});
});
RunTarget(target);