-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.cake
204 lines (175 loc) · 7.26 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#addin nuget:?package=Octokit&version=7.1.0
#load nuget:?package=Cake.Wyam.Recipe&version=2.0.1
#load build\build.cake
using Octokit;
//////////////////////////////////////////////////////////////////////
// PARAMETERS
//////////////////////////////////////////////////////////////////////
private const string GitReleaseManagerTool = "#tool nuget:?package=gitreleasemanager&version=0.11.0";
// Variables
var addinDir = Directory("./release/addins");
var addinSpecs = new List<AddinSpec>();
// Cake.Wyam.Recipe parameters
Environment.SetVariableNames();
BuildParameters.SetParameters(
context: Context,
buildSystem: BuildSystem,
title: "Cake.Issues.Website",
repositoryOwner: "cake-contrib",
repositoryName: "Cake.Issues.Website",
webHost: "cakeissues.net",
wyamRecipe: "Docs",
wyamTheme: "Samson",
shouldPublishDocumentation: StringComparer.OrdinalIgnoreCase.Equals("master", AppVeyor.Environment.Repository.Branch));
BuildParameters.PrintParameters(Context);
//////////////////////////////////////////////////////////////////////
// CUSTOM TASKS
//////////////////////////////////////////////////////////////////////
Task("CleanAddinPackages")
.Does(() =>
{
CleanDirectory(addinDir);
});
Task("GetAddinSpecs")
.Does(() =>
{
var addinSpecFiles = GetFiles("./addins/*.yml");
addinSpecs
.AddRange(addinSpecFiles
.Select(x =>
{
Verbose("Deserializing addin YAML from " + x);
return DeserializeYamlFromFile<AddinSpec>(x);
})
);
foreach (var addinSpec in addinSpecs.Where(x => x.Assemblies != null).SelectMany(x => x.Assemblies).Select(x => "../release/addins" + x))
{
Verbose("Add '{0}' to Wyam", addinSpec);
BuildParameters.WyamAssemblyFiles.Add(addinSpec);
}
});
Task("GetAddinDocumentation")
.IsDependentOn("CleanAddinPackages")
.IsDependentOn("GetAddinSpecs")
.Does(() =>
{
foreach(var addinSpec in addinSpecs.Where(x => !string.IsNullOrEmpty(x.RepositoryDocumentationPath) && !string.IsNullOrEmpty(x.DocumentationLink)))
{
Information("Cloning " + addinSpec.RepositoryName + "...");
RepositoryHelper.GitCopyFromRepository(
Context,
new Uri("https://github.com/" + addinSpec.RepositoryOwner + "/" + addinSpec.RepositoryName),
new List<DirectoryPath> {addinSpec.RepositoryDocumentationPath},
"input" + addinSpec.DocumentationLink);
}
});
Task("GetAddinPackages")
.IsDependentOn("CleanAddinPackages")
.IsDependentOn("GetAddinSpecs")
.Does(() =>
{
var packagesPath = MakeAbsolute(Directory("./output")).Combine("packages");
foreach(var addinSpec in addinSpecs.Where(x => !string.IsNullOrEmpty(x.NuGet)))
{
Information("Installing addin package " + addinSpec.NuGet);
NuGetInstall(addinSpec.NuGet,
new NuGetInstallSettings
{
OutputDirectory = addinDir,
Prerelease = addinSpec.Prerelease,
Verbosity = NuGetVerbosity.Quiet,
Source = new [] { "https://api.nuget.org/v3/index.json" },
NoCache = true,
EnvironmentVariables =
new Dictionary<string, string>
{
{"EnableNuGetPackageRestore", "true"},
{"NUGET_XMLDOC_MODE", "None"},
{"NUGET_PACKAGES", packagesPath.FullPath},
{"NUGET_EXE", Context.Tools.Resolve("nuget.exe").FullPath }
}
});
}
});
Task("GetReleaseNotes")
.IsDependentOn("GetAddinSpecs")
.WithCriteria(!string.IsNullOrEmpty(BuildParameters.Wyam.AccessToken))
.Does(() => RequireTool(GitReleaseManagerTool, () =>
{
var packagesPath = MakeAbsolute(Directory("./output")).Combine("packages");
foreach(var addinSpec in addinSpecs.Where(x => !string.IsNullOrEmpty(x.RepositoryOwner) && !string.IsNullOrEmpty(x.RepositoryName) && !string.IsNullOrEmpty(x.ReleaseNotesFilePath)))
{
Information("Retrieving release notes for " + addinSpec.Name);
GitReleaseManagerExport(
BuildParameters.Wyam.AccessToken,
addinSpec.RepositoryOwner,
addinSpec.RepositoryName,
addinSpec.ReleaseNotesFilePath);
Information("Adding metadata for " + addinSpec.Name);
string fileContent = FileReadText(addinSpec.ReleaseNotesFilePath);
DeleteFile(addinSpec.ReleaseNotesFilePath);
var frontMatter =
new List<string>
{
"---",
"Title: " + addinSpec.Name + " Release Notes",
"Description: Release notes for " + addinSpec.Name,
"---"
};
var releaseNotesContent = string.Join("\r\n", frontMatter) + "\r\n";
if (addinSpec.ReleaseNotesHeader != null)
{
releaseNotesContent += "<p>" + string.Join("\r\n", addinSpec.ReleaseNotesHeader) + "</p>\r\n";
}
releaseNotesContent += fileContent;
FileWriteText(addinSpec.ReleaseNotesFilePath, releaseNotesContent);
}
}));
Task("GetIssues")
.Does(() => {
CleanDirectory("./input/issues/");
var appName = "cake-issues-websit";
var organization = "cake-contrib";
var label = "help wanted";
var topic = "topic:cake-issues";
var client = new GitHubClient(new Octokit.ProductHeaderValue(appName));
if (!string.IsNullOrEmpty (BuildParameters.Wyam.AccessToken))
{
var tokenAuth = new Octokit.Credentials(BuildParameters.Wyam.AccessToken);
client.Credentials = tokenAuth;
}
var repositoryRequest = new SearchRepositoriesRequest(topic)
{
User = organization
};
var repositoryResult = client.Search.SearchRepo(repositoryRequest).GetAwaiter().GetResult();
var issuesRequest = new SearchIssuesRequest();
issuesRequest.Labels = new []{ label };
issuesRequest.State = ItemState.Open;
foreach (var repoEntry in repositoryResult.Items)
{
issuesRequest.Repos.Add(repoEntry.FullName);
}
var issuesResult = client.Search.SearchIssues(issuesRequest).GetAwaiter().GetResult();
foreach (var issuesEntry in issuesResult.Items)
{
FileWriteText($"./input/issues/{issuesEntry.Id}.yml",
$@"Number: {issuesEntry.Number}
HtmlUrl: {issuesEntry.HtmlUrl}
Title: ""{issuesEntry.Title}""
Repository: {issuesEntry.HtmlUrl.Split('/')[4]}");
}
});
Task("GetArtifacts")
.IsDependentOn("GetAddinDocumentation")
.IsDependentOn("GetAddinPackages")
.IsDependentOn("GetReleaseNotes")
.IsDependentOn("GetIssues");
BuildParameters.Tasks.BuildDocumentationTask
.IsDependentOn("GetArtifacts");
BuildParameters.Tasks.PreviewDocumentationTask
.IsDependentOn("GetAddinSpecs");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
Build.Run();