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