|
| 1 | +/////////////////////////////////////////////////////////////////////////////// |
| 2 | +// DISABLE WYAM |
| 3 | +/////////////////////////////////////////////////////////////////////////////// |
| 4 | + |
| 5 | +BuildParameters.Tasks.PreviewDocumentationTask.WithCriteria(() => false, "Favor Statiq over Wyam"); |
| 6 | +BuildParameters.Tasks.PublishDocumentationTask.WithCriteria(() => false, "Favor Statiq over Wyam"); |
| 7 | +BuildParameters.Tasks.ForcePublishDocumentationTask.WithCriteria(() => false, "Favor Statiq over Wyam"); |
| 8 | + |
| 9 | +/////////////////////////////////////////////////////////////////////////////// |
| 10 | +// TASK DEFINITIONS |
| 11 | +/////////////////////////////////////////////////////////////////////////////// |
| 12 | + |
| 13 | +// No Clean task, we re-use the one provided in Wyam.cake |
| 14 | + |
| 15 | +BuildParameters.Tasks.PublishDocumentationTask = Task("Publish-StatiqDocs") |
| 16 | + .IsDependentOn("Clean-Documentation") |
| 17 | + .WithCriteria(() => BuildParameters.ShouldGenerateDocumentation, "Statiq documentation has been disabled") |
| 18 | + .WithCriteria(() => DirectoryExists(BuildParameters.WyamRootDirectoryPath), "Statiq documentation directory is missing") |
| 19 | + .Does(() => { |
| 20 | + // ensure submodules are in place |
| 21 | + var gitTool = Context.Tools.Resolve("git"); |
| 22 | + if (gitTool == null) |
| 23 | + { |
| 24 | + gitTool = Context.Tools.Resolve("git.exe"); |
| 25 | + } |
| 26 | + if (gitTool == null) |
| 27 | + { |
| 28 | + throw new FileNotFoundException("git/git.exe could not be found!"); |
| 29 | + } |
| 30 | + |
| 31 | + var exitCode = Context.StartProcess( |
| 32 | + gitTool, |
| 33 | + new ProcessSettings { |
| 34 | + Arguments = "submodule update --init --recursive", |
| 35 | + } |
| 36 | + ); |
| 37 | + |
| 38 | + // Check to see if any documentation has changed |
| 39 | + var sourceCommit = GitLogTip("./"); |
| 40 | + Information("Source Commit Sha: {0}", sourceCommit.Sha); |
| 41 | + var filesChanged = GitDiff("./", sourceCommit.Sha); |
| 42 | + Information("Number of changed files: {0}", filesChanged.Count); |
| 43 | + var docFileChanged = false; |
| 44 | + |
| 45 | + var wyamDocsFolderDirectoryName = BuildParameters.WyamRootDirectoryPath.GetDirectoryName(); |
| 46 | + |
| 47 | + var pathsToTestAgainst = new List<string>() { |
| 48 | + string.Format("{0}{1}", wyamDocsFolderDirectoryName, "/input/") |
| 49 | + }; |
| 50 | + |
| 51 | + if (BuildParameters.ShouldDocumentSourceFiles) |
| 52 | + { |
| 53 | + // BuildParameters.WyamSourceFiles can not be used - the wyam globs are different from globs in GetFiles(). |
| 54 | + pathsToTestAgainst.Add(string.Format("{0}{1}", BuildParameters.SourceDirectoryPath.FullPath, '/')); |
| 55 | + } |
| 56 | + |
| 57 | + Verbose("Comparing all file-changes to the following paths:"); |
| 58 | + foreach(var p in pathsToTestAgainst) |
| 59 | + { |
| 60 | + Verbose(" - "+p); |
| 61 | + } |
| 62 | + |
| 63 | + foreach (var file in filesChanged) |
| 64 | + { |
| 65 | + Verbose("Changed File OldPath: {0}, Path: {1}", file.OldPath, file.Path); |
| 66 | + if (pathsToTestAgainst.Any(x => file.OldPath.Contains(x) || file.Path.Contains(x))) |
| 67 | + { |
| 68 | + docFileChanged = true; |
| 69 | + break; |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + if (docFileChanged) |
| 74 | + { |
| 75 | + Information("Detected that documentation files have changed, so running Statiq..."); |
| 76 | + |
| 77 | + Statiq(); |
| 78 | + PublishStatiqDocs(); |
| 79 | + } |
| 80 | + else |
| 81 | + { |
| 82 | + Information("No documentation has changed, so no need to generate documentation"); |
| 83 | + } |
| 84 | + } |
| 85 | +) |
| 86 | +.OnError(exception => |
| 87 | +{ |
| 88 | + Error(exception.Message); |
| 89 | + Information("Publish-StatiqDocs Task failed, but continuing with next Task..."); |
| 90 | + publishingError = true; |
| 91 | +}); |
| 92 | + |
| 93 | +BuildParameters.Tasks.PreviewDocumentationTask = Task("Preview-StatiqDocs") |
| 94 | + .WithCriteria(() => DirectoryExists(BuildParameters.WyamRootDirectoryPath), "Statiq documentation directory is missing") |
| 95 | + .Does(() => { |
| 96 | + Statiq("preview"); |
| 97 | + }); |
| 98 | + |
| 99 | + |
| 100 | +BuildParameters.Tasks.ForcePublishDocumentationTask = Task("Force-Publish-StatiqDocs") |
| 101 | + .IsDependentOn("Clean-Documentation") |
| 102 | + .WithCriteria(() => DirectoryExists(BuildParameters.WyamRootDirectoryPath), "Statiq documentation directory is missing") |
| 103 | + .Does(() => { |
| 104 | + Statiq(); |
| 105 | + PublishStatiqDocs(); |
| 106 | + } |
| 107 | +); |
| 108 | + |
| 109 | +public void PublishStatiqDocs() |
| 110 | +{ |
| 111 | + var canPublishToGitHub = |
| 112 | + !string.IsNullOrEmpty(BuildParameters.Wyam.AccessToken) && |
| 113 | + !string.IsNullOrEmpty(BuildParameters.Wyam.DeployBranch) && |
| 114 | + !string.IsNullOrEmpty(BuildParameters.RepositoryOwner) && |
| 115 | + !string.IsNullOrEmpty(BuildParameters.RepositoryName); |
| 116 | + |
| 117 | + if (!canPublishToGitHub) |
| 118 | + { |
| 119 | + Warning("Unable to publish documentation, as not all Statiq configuration is present"); |
| 120 | + return; |
| 121 | + } |
| 122 | + |
| 123 | + Statiq("deploy"); |
| 124 | +} |
| 125 | + |
| 126 | +// TODO: Do we need Cake.Statiq ? |
| 127 | +public void Statiq(string command = "", IDictionary<string, string> additionalSetting = null) |
| 128 | +{ |
| 129 | + var statiqProj = BuildParameters.WyamRootDirectoryPath.CombineWithFilePath("Docs.csproj").FullPath; // TODO: Configurable! |
| 130 | + var settings = new Dictionary<string, string> |
| 131 | + { |
| 132 | + { "Host", BuildParameters.WebHost }, |
| 133 | + { "LinkRoot", BuildParameters.WebLinkRoot }, |
| 134 | + { "BaseEditUrl", BuildParameters.WebBaseEditUrl }, |
| 135 | + { "Title", BuildParameters.Title }, |
| 136 | + { "IncludeGlobalNamespace", "false" }, |
| 137 | + { "STATIQ_DEPLOY_OWNER", BuildParameters.RepositoryOwner }, |
| 138 | + { "STATIQ_DEPLOY_REPO_NAME", BuildParameters.RepositoryName } |
| 139 | + }; |
| 140 | + |
| 141 | + if (BuildParameters.ShouldDocumentSourceFiles) |
| 142 | + { |
| 143 | + settings.Add("SourceFiles", BuildParameters.WyamSourceFiles); |
| 144 | + } |
| 145 | + |
| 146 | + if(additionalSetting != null) |
| 147 | + { |
| 148 | + settings = new[]{settings, additionalSetting}.SelectMany(x => x).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); |
| 149 | + } |
| 150 | + |
| 151 | + if((command.EqualsIgnoreCase("preview") || command.EqualsIgnoreCase("serve")) && !string.IsNullOrEmpty(BuildParameters.WebLinkRoot)) |
| 152 | + { |
| 153 | + command += $" --virtual-dir={BuildParameters.WebLinkRoot}"; |
| 154 | + } |
| 155 | + |
| 156 | + // TODO: Read log-level from Env/commandline? |
| 157 | + |
| 158 | + DotNetCoreRun(statiqProj, new DotNetCoreRunSettings |
| 159 | + { |
| 160 | + EnvironmentVariables = settings, |
| 161 | + ArgumentCustomization = args=>args |
| 162 | + .Append(" -- ") |
| 163 | + .Append(command) |
| 164 | + .Append($"--root=\"{BuildParameters.WyamRootDirectoryPath}\""), |
| 165 | + }); |
| 166 | +} |
| 167 | + |
| 168 | + |
| 169 | +/////////////////////////////////////////////////////////////////////////////// |
| 170 | +// BAKE STATIQ IN Cake.Recipe |
| 171 | +/////////////////////////////////////////////////////////////////////////////// |
| 172 | + |
| 173 | +BuildParameters.Tasks.PreviewTask.IsDependentOn("Preview-StatiqDocs"); |
| 174 | +BuildParameters.Tasks.PublishDocsTask.IsDependentOn("Force-Publish-StatiqDocs"); |
| 175 | +BuildParameters.Tasks.ContinuousIntegrationTask.IsDependentOn("Publish-StatiqDocs"); |
0 commit comments