-
Notifications
You must be signed in to change notification settings - Fork 641
/
wyam.cake
158 lines (143 loc) · 6.1 KB
/
wyam.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
Task("Clean-Documentation")
.Does(() =>
{
EnsureDirectoryExists(MakeAbsolute(Directory("artifacts/temp/_PublishedDocumentation")));
});
Task("Preview-Documentation")
.WithCriteria(() => DirectoryExists(MakeAbsolute(Directory("docs"))), "Wyam documentation directory is missing")
.Does<BuildParameters>((parameters) =>
{
Wyam(new WyamSettings
{
Recipe = "Docs",
Theme = "Samson",
OutputPath = MakeAbsolute(Directory("artifacts/Documentation")),
RootPath = MakeAbsolute(Directory("docs")),
Preview = true,
Watch = true,
ConfigurationFile = MakeAbsolute((FilePath)"config.wyam"),
PreviewVirtualDirectory = "GitVersion",
Settings = new Dictionary<string, object>
{
{ "Host", "gittools.github.io" },
{ "LinkRoot", "GitVersion" },
{ "BaseEditUrl", "https://github.com/gittools/GitVersion/tree/master/docs/input/" },
{ "SourceFiles", MakeAbsolute(parameters.Paths.Directories.Source) + "/**/{!bin,!obj,!packages,!*.Tests,}/**/*.cs" },
{ "Title", "GitVersion" },
{ "IncludeGlobalNamespace", false }
}
});
});
Task("Force-Publish-Documentation")
.IsDependentOn("Clean-Documentation")
.WithCriteria(() => DirectoryExists(MakeAbsolute(Directory("docs"))), "Wyam documentation directory is missing")
.WithCriteria<BuildParameters>((context, parameters) => !parameters.IsPullRequest, "Publish-Documentation works only for non-PR commits.")
.Does<BuildParameters>((parameters) =>
{
Wyam(new WyamSettings
{
Recipe = "Docs",
Theme = "Samson",
OutputPath = MakeAbsolute(Directory("artifacts/Documentation")),
RootPath = MakeAbsolute(Directory("docs")),
ConfigurationFile = MakeAbsolute((FilePath)"config.wyam"),
PreviewVirtualDirectory = "GitVersion",
Settings = new Dictionary<string, object>
{
{ "Host", "gittools.github.io" },
{ "LinkRoot", "GitVersion" },
{ "BaseEditUrl", "https://github.com/gittools/GitVersion/tree/master/docs/input/" },
{ "SourceFiles", MakeAbsolute(parameters.Paths.Directories.Source) + "/**/{!bin,!obj,!packages,!*.Tests,}/**/*.cs" },
{ "Title", "GitVersion" },
{ "IncludeGlobalNamespace", false }
}
});
PublishDocumentation(parameters);
});
Task("Publish-Documentation")
.IsDependentOn("Clean-Documentation")
.WithCriteria(() => DirectoryExists(MakeAbsolute(Directory("docs"))), "Wyam documentation directory is missing")
.Does<BuildParameters>((parameters) =>
{
// Check to see if any documentation has changed
var sourceCommit = GitLogTip("./");
Information("Source Commit Sha: {0}", sourceCommit.Sha);
var filesChanged = GitDiff("./", sourceCommit.Sha);
Information("Number of changed files: {0}", filesChanged.Count);
var docFileChanged = false;
var wyamDocsFolderDirectoryName = "docs";
foreach (var file in filesChanged)
{
var forwardSlash = '/';
Verbose("Changed File OldPath: {0}, Path: {1}", file.OldPath, file.Path);
if (file.OldPath.Contains(string.Format("{0}{1}", wyamDocsFolderDirectoryName, forwardSlash)) ||
file.Path.Contains(string.Format("{0}{1}", wyamDocsFolderDirectoryName, forwardSlash)) ||
file.Path.Contains("config.wyam"))
{
docFileChanged = true;
break;
}
}
if (docFileChanged)
{
Information("Detected that documentation files have changed, so running Wyam...");
Wyam(new WyamSettings
{
Recipe = "Docs",
Theme = "Samson",
OutputPath = MakeAbsolute(Directory("artifacts/Documentation")),
RootPath = MakeAbsolute(Directory("docs")),
ConfigurationFile = MakeAbsolute((FilePath)"config.wyam"),
PreviewVirtualDirectory = "GitVersion",
Settings = new Dictionary<string, object>
{
{ "Host", "gittools.github.io" },
{ "LinkRoot", "GitVersion" },
{ "BaseEditUrl", "https://github.com/gittools/GitVersion/tree/master/docs/input/" },
{ "SourceFiles", MakeAbsolute(parameters.Paths.Directories.Source) + "/**/{!bin,!obj,!packages,!*.Tests,}/**/*.cs" },
{ "Title", "GitVersion" },
{ "IncludeGlobalNamespace", false }
}
});
PublishDocumentation(parameters);
}
else
{
Information("No documentation has changed, so no need to generate documentation");
}
})
.OnError(exception =>
{
Error(exception.Message);
Information("Publish-Documentation Task failed, but continuing with next Task...");
publishingError = true;
});
public void PublishDocumentation(BuildParameters parameters)
{
var sourceCommit = GitLogTip("./");
var publishFolder = MakeAbsolute(Directory("artifacts/temp/_PublishedDocumentation")).Combine(DateTime.Now.ToString("yyyyMMdd_HHmmss"));
Information("Publishing Folder: {0}", publishFolder);
Information("Getting publish branch...");
GitClone("https://github.com/gittools/GitVersion", publishFolder, new GitCloneSettings{ BranchName = "gh-pages" });
Information("Sync output files...");
Kudu.Sync(MakeAbsolute(Directory("artifacts/Documentation")), publishFolder, new KuduSyncSettings {
ArgumentCustomization = args=>args.Append("--ignore").AppendQuoted(".git;CNAME")
});
if (GitHasUncommitedChanges(publishFolder))
{
Information("Stage all changes...");
GitAddAll(publishFolder);
if (GitHasStagedChanges(publishFolder))
{
Information("Commit all changes...");
GitCommit(
publishFolder,
sourceCommit.Committer.Name,
sourceCommit.Committer.Email,
string.Format("Continuous Integration Publish: {0}\r\n{1}", sourceCommit.Sha, sourceCommit.Message)
);
Information("Pushing all changes...");
GitPush(publishFolder, parameters.Credentials.GitHub.Token, "x-oauth-basic", "gh-pages");
}
}
}