@@ -12,7 +12,7 @@ Task("Preview-Documentation")
12
12
{
13
13
Recipe = "Docs" ,
14
14
Theme = "Samson" ,
15
- OutputPath = MakeAbsolute ( MakeAbsolute ( Directory ( "artifacts/Documentation" ) ) ) ,
15
+ OutputPath = MakeAbsolute ( Directory ( "artifacts/Documentation" ) ) ,
16
16
RootPath = MakeAbsolute ( Directory ( "docs" ) ) ,
17
17
Preview = true ,
18
18
Watch = true ,
@@ -29,3 +29,130 @@ Task("Preview-Documentation")
29
29
}
30
30
} ) ;
31
31
} ) ;
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