-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
193 lines (169 loc) · 6.58 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
// The following environment variables need to be set for Publish target:
// GH_ACCESS_TOKEN
#tool "nuget:https://api.nuget.org/v3/index.json?package=Wyam2&version=3.0.0&prerelease"
#addin "nuget:https://api.nuget.org/v3/index.json?package=Cake.Wyam2&version=3.0.0&prerelease"
#addin "nuget:https://api.nuget.org/v3/index.json?package=Octokit"
using Octokit;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Define directories.
var releaseDir = Directory("./release");
var sourceDir = releaseDir + Directory("repo");
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("CleanSource")
.Does(() =>
{
if(DirectoryExists(sourceDir))
{
Information($"Deleting {sourceDir}");
DeleteDirectory(sourceDir, new DeleteDirectorySettings
{
Force = true,
Recursive = true
});
}
var subDirs = GetSubDirectories(releaseDir);
if(subDirs != null && subDirs.Count > 0)
{
foreach (var subDir in subDirs)
{
Information($"Deleting {subDir}");
DeleteDirectory(subDir, new DeleteDirectorySettings
{
Force = true,
Recursive = true
});
}
}
});
Task("GetSource")
.IsDependentOn("CleanSource")
.Does(() =>
{
var githubToken = EnvironmentVariable("GH_ACCESS_TOKEN");
GitHubClient github = new GitHubClient(new ProductHeaderValue("Wyam2-wyam-Docs"))
{
Credentials = new Credentials(githubToken)
};
// The GitHub releases API returns Not Found for Wyam2. Better use tags
var tag = github.Repository.GetAllTags("Wyam2", "wyam").Result.First();
FilePath releaseZip = DownloadFile(tag.ZipballUrl);
Unzip(releaseZip, releaseDir);
// Need to rename the container directory in the zip file to something consistent
var containerDir = GetDirectories(releaseDir.Path.FullPath + "/*").First(x => x.GetDirectoryName().StartsWith("Wyam2"));
MoveDirectory(containerDir, sourceDir);
Information($"Downloaded and unzipped { GetFiles(sourceDir.Path.FullPath + "/**/*").Count } files in { GetSubDirectories(sourceDir).Count } directories");
});
Task("Generate-Themes")
.Does(() =>
{
// Clean the output directory
var output = Directory("./output");
if(DirectoryExists(output))
{
CleanDirectory(output);
}
// Clean/create the scaffold directory
var scaffold = Directory("./scaffold");
if(!DirectoryExists(scaffold))
{
CreateDirectory(scaffold);
}
// Iterate the recipes
foreach(DirectoryPath recipe in GetDirectories("./input/recipes/*"))
{
// Scaffold the recipe into a temporary directory
CleanDirectory(scaffold);
Wyam(new WyamSettings
{
Recipe = recipe.GetDirectoryName(),
RootPath = scaffold,
ArgumentCustomization = args => args.Prepend("new")
});
// Iterate the themes
foreach(FilePath theme in GetFiles(recipe.FullPath + "/themes/*.md"))
{
// See if this is a built-in theme by checking for "Preview" metadata
if(!Context.FileSystem
.GetFile(theme)
.ReadLines(Encoding.UTF8)
.TakeWhile(x => !x.StartsWith("---"))
.Any(x => x.StartsWith("Preview:")))
{
// Build the theme preview
string linkRoot = "/recipes/" + recipe.GetDirectoryName() + "/themes/preview/" + theme.GetFilenameWithoutExtension().FullPath;
Wyam(new WyamSettings
{
Recipe = recipe.GetDirectoryName(),
RootPath = scaffold,
Theme = theme.GetFilenameWithoutExtension().FullPath,
OutputPath = MakeAbsolute(Directory("./output" + linkRoot)).FullPath,
Settings = new Dictionary<string, object>
{
{ "LinkRoot", linkRoot }
}
});
}
}
}
CleanDirectory(scaffold);
DeleteDirectory(scaffold, new DeleteDirectorySettings
{
Force = true,
Recursive = true
});
});
Task("Build")
.IsDependentOn("GetSource")
.IsDependentOn("Generate-Themes")
.Does(() =>
{
Wyam(new WyamSettings
{
NoClean = true, // Cleaned in Generate-Themes task
Recipe = "Docs",
Theme = "Samson",
UpdatePackages = true
});
});
Task("Preview")
.IsDependentOn("Generate-Themes")
.Does(() =>
{
Wyam(new WyamSettings
{
NoClean = true, // Cleaned in Generate-Themes task
Recipe = "Docs",
Theme = "Samson",
UpdatePackages = true,
Preview = true
});
});
Task("Debug")
.Does(() =>
{
DotNetCoreBuild("../Wyam/tests/integration/Wyam.Examples.Tests/Wyam.Examples.Tests.csproj");
DotNetCoreExecute("../Wyam/tests/integration/Wyam.Examples.Tests/bin/Debug/netcoreapp2.1/Wyam.dll",
"-a \"../Wyam/tests/integration/Wyam.Examples.Tests/bin/Debug/netcoreapp2.1/**/*.dll\" -r \"docs -i\" -t \"../Wyam/themes/Docs/Samson\" -p");
});
Task("Deploy")
.Does(() => { Information("Ran Deploy target"); });
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Build");
Task("BuildServer")
.IsDependentOn("Build")
.IsDependentOn("Deploy");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);