Skip to content

Commit

Permalink
(GH-1932) First stab at publishing docs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gep13 authored and arturcic committed Dec 19, 2019
1 parent 405b8bb commit 1333e08
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build.cake
Expand Up @@ -7,9 +7,11 @@
#addin "nuget:?package=Cake.Coverlet&version=2.3.4"
#addin "nuget:?package=Cake.Docker&version=0.10.1"
#addin "nuget:?package=Cake.Gem&version=0.8.1"
#addin "nuget:?package=Cake.Git&version=0.21.0"
#addin "nuget:?package=Cake.Gitter&version=0.11.1"
#addin "nuget:?package=Cake.Incubator&version=5.1.0"
#addin "nuget:?package=Cake.Json&version=4.0.0"
#addin "nuget:?package=Cake.Kudu&version=0.10.1"
#addin "nuget:?package=Cake.Npm&version=0.17.0"
#addin "nuget:?package=Cake.Tfx&version=0.9.1"
#addin "nuget:?package=Cake.Wyam&version=2.2.9"
Expand All @@ -22,6 +24,7 @@
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.10.0"
#tool "nuget:?package=nuget.commandline&version=5.2.0"
#tool "nuget:?package=Wyam&version=2.2.9"
#tool "nuget:?package=KuduSync.NET&version=1.5.2"

// Install .NET Core Global tools.
#tool "dotnet:?package=Codecov.Tool&version=1.7.2"
Expand Down Expand Up @@ -143,6 +146,7 @@ Task("Publish")
.IsDependentOn("Publish-NuGet")
.IsDependentOn("Publish-Chocolatey")
.IsDependentOn("Publish-Gem")
.IsDependentOn("Publish-Documentation")
.Finally(() =>
{
if (publishingError)
Expand Down
129 changes: 128 additions & 1 deletion build/wyam.cake
Expand Up @@ -12,7 +12,7 @@ Task("Preview-Documentation")
{
Recipe = "Docs",
Theme = "Samson",
OutputPath = MakeAbsolute(MakeAbsolute(Directory("artifacts/Documentation"))),
OutputPath = MakeAbsolute(Directory("artifacts/Documentation")),
RootPath = MakeAbsolute(Directory("docs")),
Preview = true,
Watch = true,
Expand All @@ -29,3 +29,130 @@ Task("Preview-Documentation")
}
});
});

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");
}
}
}

0 comments on commit 1333e08

Please sign in to comment.