Skip to content

Commit 1333e08

Browse files
gep13arturcic
authored andcommitted
(GH-1932) First stab at publishing docs
This may well break, and we won't be able to test this until merged since it isn't meant to work on PR builds.
1 parent 405b8bb commit 1333e08

File tree

2 files changed

+132
-1
lines changed

2 files changed

+132
-1
lines changed

build.cake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
#addin "nuget:?package=Cake.Coverlet&version=2.3.4"
88
#addin "nuget:?package=Cake.Docker&version=0.10.1"
99
#addin "nuget:?package=Cake.Gem&version=0.8.1"
10+
#addin "nuget:?package=Cake.Git&version=0.21.0"
1011
#addin "nuget:?package=Cake.Gitter&version=0.11.1"
1112
#addin "nuget:?package=Cake.Incubator&version=5.1.0"
1213
#addin "nuget:?package=Cake.Json&version=4.0.0"
14+
#addin "nuget:?package=Cake.Kudu&version=0.10.1"
1315
#addin "nuget:?package=Cake.Npm&version=0.17.0"
1416
#addin "nuget:?package=Cake.Tfx&version=0.9.1"
1517
#addin "nuget:?package=Cake.Wyam&version=2.2.9"
@@ -22,6 +24,7 @@
2224
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.10.0"
2325
#tool "nuget:?package=nuget.commandline&version=5.2.0"
2426
#tool "nuget:?package=Wyam&version=2.2.9"
27+
#tool "nuget:?package=KuduSync.NET&version=1.5.2"
2528

2629
// Install .NET Core Global tools.
2730
#tool "dotnet:?package=Codecov.Tool&version=1.7.2"
@@ -143,6 +146,7 @@ Task("Publish")
143146
.IsDependentOn("Publish-NuGet")
144147
.IsDependentOn("Publish-Chocolatey")
145148
.IsDependentOn("Publish-Gem")
149+
.IsDependentOn("Publish-Documentation")
146150
.Finally(() =>
147151
{
148152
if (publishingError)

build/wyam.cake

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Task("Preview-Documentation")
1212
{
1313
Recipe = "Docs",
1414
Theme = "Samson",
15-
OutputPath = MakeAbsolute(MakeAbsolute(Directory("artifacts/Documentation"))),
15+
OutputPath = MakeAbsolute(Directory("artifacts/Documentation")),
1616
RootPath = MakeAbsolute(Directory("docs")),
1717
Preview = true,
1818
Watch = true,
@@ -29,3 +29,130 @@ Task("Preview-Documentation")
2929
}
3030
});
3131
});
32+
33+
Task("Force-Publish-Documentation")
34+
.IsDependentOn("Clean-Documentation")
35+
.WithCriteria(() => DirectoryExists(MakeAbsolute(Directory("docs"))), "Wyam documentation directory is missing")
36+
.WithCriteria<BuildParameters>((context, parameters) => !parameters.IsPullRequest, "Publish-Documentation works only for non-PR commits.")
37+
.Does<BuildParameters>((parameters) =>
38+
{
39+
Wyam(new WyamSettings
40+
{
41+
Recipe = "Docs",
42+
Theme = "Samson",
43+
OutputPath = MakeAbsolute(Directory("artifacts/Documentation")),
44+
RootPath = MakeAbsolute(Directory("docs")),
45+
ConfigurationFile = MakeAbsolute((FilePath)"config.wyam"),
46+
PreviewVirtualDirectory = "GitVersion",
47+
Settings = new Dictionary<string, object>
48+
{
49+
{ "Host", "gittools.github.io" },
50+
{ "LinkRoot", "GitVersion" },
51+
{ "BaseEditUrl", "https://github.com/gittools/GitVersion/tree/master/docs/input/" },
52+
{ "SourceFiles", MakeAbsolute(parameters.Paths.Directories.Source) + "/**/{!bin,!obj,!packages,!*.Tests,}/**/*.cs" },
53+
{ "Title", "GitVersion" },
54+
{ "IncludeGlobalNamespace", false }
55+
}
56+
});
57+
58+
PublishDocumentation(parameters);
59+
});
60+
61+
Task("Publish-Documentation")
62+
.IsDependentOn("Clean-Documentation")
63+
.WithCriteria(() => DirectoryExists(MakeAbsolute(Directory("docs"))), "Wyam documentation directory is missing")
64+
.Does<BuildParameters>((parameters) =>
65+
{
66+
// Check to see if any documentation has changed
67+
var sourceCommit = GitLogTip("./");
68+
Information("Source Commit Sha: {0}", sourceCommit.Sha);
69+
var filesChanged = GitDiff("./", sourceCommit.Sha);
70+
Information("Number of changed files: {0}", filesChanged.Count);
71+
var docFileChanged = false;
72+
73+
var wyamDocsFolderDirectoryName = "docs";
74+
75+
foreach (var file in filesChanged)
76+
{
77+
var forwardSlash = '/';
78+
Verbose("Changed File OldPath: {0}, Path: {1}", file.OldPath, file.Path);
79+
if (file.OldPath.Contains(string.Format("{0}{1}", wyamDocsFolderDirectoryName, forwardSlash)) ||
80+
file.Path.Contains(string.Format("{0}{1}", wyamDocsFolderDirectoryName, forwardSlash)) ||
81+
file.Path.Contains("config.wyam"))
82+
{
83+
docFileChanged = true;
84+
break;
85+
}
86+
}
87+
88+
if (docFileChanged)
89+
{
90+
Information("Detected that documentation files have changed, so running Wyam...");
91+
92+
Wyam(new WyamSettings
93+
{
94+
Recipe = "Docs",
95+
Theme = "Samson",
96+
OutputPath = MakeAbsolute(Directory("artifacts/Documentation")),
97+
RootPath = MakeAbsolute(Directory("docs")),
98+
ConfigurationFile = MakeAbsolute((FilePath)"config.wyam"),
99+
PreviewVirtualDirectory = "GitVersion",
100+
Settings = new Dictionary<string, object>
101+
{
102+
{ "Host", "gittools.github.io" },
103+
{ "LinkRoot", "GitVersion" },
104+
{ "BaseEditUrl", "https://github.com/gittools/GitVersion/tree/master/docs/input/" },
105+
{ "SourceFiles", MakeAbsolute(parameters.Paths.Directories.Source) + "/**/{!bin,!obj,!packages,!*.Tests,}/**/*.cs" },
106+
{ "Title", "GitVersion" },
107+
{ "IncludeGlobalNamespace", false }
108+
}
109+
});
110+
111+
PublishDocumentation(parameters);
112+
}
113+
else
114+
{
115+
Information("No documentation has changed, so no need to generate documentation");
116+
}
117+
})
118+
.OnError(exception =>
119+
{
120+
Error(exception.Message);
121+
Information("Publish-Documentation Task failed, but continuing with next Task...");
122+
publishingError = true;
123+
});
124+
125+
public void PublishDocumentation(BuildParameters parameters)
126+
{
127+
var sourceCommit = GitLogTip("./");
128+
129+
var publishFolder = MakeAbsolute(Directory("artifacts/temp/_PublishedDocumentation")).Combine(DateTime.Now.ToString("yyyyMMdd_HHmmss"));
130+
Information("Publishing Folder: {0}", publishFolder);
131+
Information("Getting publish branch...");
132+
GitClone("https://github.com/gittools/GitVersion", publishFolder, new GitCloneSettings{ BranchName = "gh-pages" });
133+
134+
Information("Sync output files...");
135+
Kudu.Sync(MakeAbsolute(Directory("artifacts/Documentation")), publishFolder, new KuduSyncSettings {
136+
ArgumentCustomization = args=>args.Append("--ignore").AppendQuoted(".git;CNAME")
137+
});
138+
139+
if (GitHasUncommitedChanges(publishFolder))
140+
{
141+
Information("Stage all changes...");
142+
GitAddAll(publishFolder);
143+
144+
if (GitHasStagedChanges(publishFolder))
145+
{
146+
Information("Commit all changes...");
147+
GitCommit(
148+
publishFolder,
149+
sourceCommit.Committer.Name,
150+
sourceCommit.Committer.Email,
151+
string.Format("Continuous Integration Publish: {0}\r\n{1}", sourceCommit.Sha, sourceCommit.Message)
152+
);
153+
154+
Information("Pushing all changes...");
155+
GitPush(publishFolder, parameters.Credentials.GitHub.Token, "x-oauth-basic", "gh-pages");
156+
}
157+
}
158+
}

0 commit comments

Comments
 (0)