-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.cake
146 lines (125 loc) · 5.51 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
#addin nuget:?package=Cake.Git&version=0.22.0
#addin nuget:?package=Cake.XmlDocMarkdown&version=2.3.0
using System.Text.RegularExpressions;
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var nugetApiKey = Argument("nugetApiKey", "");
var trigger = Argument("trigger", "");
var versionSuffix = Argument("versionSuffix", "");
var updateDocs = Argument("updateDocs", false);
var solutionFileName = "Faithlife.ApiDiffTools.sln";
var docsProjects = new[] { "Faithlife.ApiDiffTool", "Faithlife.FacadeGenerator", "Faithlife.PackageDiffTool" };
var docsRepoUri = "https://github.com/Faithlife/FaithlifeApiDiffTools.git";
var docsSourceUri = "https://github.com/Faithlife/FaithlifeApiDiffTools/tree/master/src";
var nugetIgnore = new string[0];
var nugetSource = "https://api.nuget.org/v3/index.json";
var buildBotUserName = "faithlifebuildbot";
var buildBotPassword = EnvironmentVariable("BUILD_BOT_PASSWORD");
var buildBotDisplayName = "Faithlife Build Bot";
var buildBotEmail = "[email protected]";
var docsBranchName = "gh-pages";
DirectoryPath docsDirectory = null;
Task("Clean")
.Does(() =>
{
CleanDirectories("src/**/bin");
CleanDirectories("src/**/obj");
CleanDirectories("tests/**/bin");
CleanDirectories("tests/**/obj");
CleanDirectories("release");
});
Task("Restore")
.Does(() =>
{
DotNetCoreRestore(solutionFileName);
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetCoreBuild(solutionFileName, new DotNetCoreBuildSettings { Configuration = configuration, NoRestore = true, ArgumentCustomization = args => args.Append("--verbosity normal") });
});
Task("Rebuild")
.IsDependentOn("Clean")
.IsDependentOn("Build");
Task("UpdateDocs")
.WithCriteria(updateDocs)
.IsDependentOn("Build")
.Does(() =>
{
docsDirectory = new DirectoryPath(docsBranchName);
if (DirectoryExists(docsDirectory))
DeleteDirectory(docsDirectory, new DeleteDirectorySettings { Recursive = true, Force = true });
GitClone(docsRepoUri, docsDirectory, new GitCloneSettings { BranchName = docsBranchName });
Information($"Updating documentation at {docsDirectory}.");
foreach (var docsProject in docsProjects)
{
XmlDocMarkdownGenerate(File($"src/{docsProject}/bin/{configuration}/netstandard2.0/{docsProject}.dll").ToString(), $"{docsDirectory}{System.IO.Path.DirectorySeparatorChar}",
new XmlDocMarkdownSettings { SourceCodePath = $"{docsSourceUri}/{docsProject}", NewLine = "\n", ShouldClean = true });
}
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
foreach (var projectPath in GetFiles("tests/TestLibrary.*/*.csproj").Select(x => x.FullPath))
DotNetCorePack(projectPath, new DotNetCorePackSettings { Configuration = configuration, NoRestore = true, MSBuildSettings = new DotNetCoreMSBuildSettings { Properties = { ["AssemblyName"] = new[] { "TestLibrary" } } } });
foreach (var projectPath in GetFiles("tests/**/*Tests.csproj").Select(x => x.FullPath))
DotNetCoreTest(projectPath, new DotNetCoreTestSettings { Configuration = configuration, NoRestore = true });
});
Task("NuGetPackage")
.IsDependentOn("Rebuild")
.IsDependentOn("Test")
.IsDependentOn("UpdateDocs")
.Does(() =>
{
if (string.IsNullOrEmpty(versionSuffix) && !string.IsNullOrEmpty(trigger))
versionSuffix = Regex.Match(trigger, @"^v[^\.]+\.[^\.]+\.[^\.]+-(.+)").Groups[1].ToString();
foreach (var projectPath in GetFiles("src/**/*.csproj").Where(x => !nugetIgnore.Contains(x.GetFilenameWithoutExtension().ToString())).Select(x => x.FullPath))
DotNetCorePack(projectPath, new DotNetCorePackSettings { Configuration = configuration, NoBuild = true, NoRestore = true, OutputDirectory = "release", VersionSuffix = versionSuffix });
});
Task("NuGetPackageTest")
.IsDependentOn("NuGetPackage")
.Does(() =>
{
var firstProject = GetFiles("src/**/*.csproj").First().FullPath;
foreach (var nupkg in GetFiles("release/**/*.nupkg").Select(x => x.FullPath).Where(x => !(x.Contains(".Tool.") || x.Contains("Faithlife.ApiDiffTools."))))
DotNetCoreTool(firstProject, "sourcelink", $"test {nupkg}");
});
Task("NuGetPublish")
.IsDependentOn("NuGetPackageTest")
.Does(() =>
{
var nupkgPaths = GetFiles("release/*.nupkg").Select(x => x.FullPath).ToList();
string version = null;
foreach (var nupkgPath in nupkgPaths)
{
string nupkgVersion = Regex.Match(nupkgPath, @"\.([^\.]+\.[^\.]+\.[^\.]+)\.nupkg$").Groups[1].ToString();
if (version == null)
version = nupkgVersion;
else if (version != nupkgVersion)
throw new InvalidOperationException($"Mismatched package versions '{version}' and '{nupkgVersion}'.");
}
if (!string.IsNullOrEmpty(nugetApiKey) && (trigger == null || Regex.IsMatch(trigger, "^v[0-9]")))
{
if (trigger != null && trigger != $"v{version}")
throw new InvalidOperationException($"Trigger '{trigger}' doesn't match package version '{version}'.");
var pushSettings = new NuGetPushSettings { ApiKey = nugetApiKey, Source = nugetSource };
foreach (var nupkgPath in nupkgPaths)
NuGetPush(nupkgPath, pushSettings);
if (docsDirectory != null && GitHasUncommitedChanges(docsDirectory))
{
Information("Pushing updated documentation to GitHub.");
GitAddAll(docsDirectory);
GitCommit(docsDirectory, buildBotDisplayName, buildBotEmail, $"Automatic documentation update for {version}.");
GitPush(docsDirectory, buildBotUserName, buildBotPassword, docsBranchName);
}
}
else
{
Information("To publish this package, push this git tag: v" + version);
}
});
Task("Default")
.IsDependentOn("Test");
RunTarget(target);