1
1
using System ;
2
+ using System . Linq ;
2
3
using Cake . Common . Diagnostics ;
3
4
using Cake . Common . IO ;
4
5
using Cake . Core ;
5
6
using Cake . Core . IO ;
6
7
using Cake . Frosting ;
7
8
using Cake . Git ;
8
- using Cake . Kudu ;
9
- using Cake . Kudu . KuduSync ;
9
+ using Cake . Wyam ;
10
10
using Common . Utilities ;
11
11
12
12
namespace Docs . Tasks
13
13
{
14
14
[ TaskName ( nameof ( PublishDocs ) ) ]
15
15
[ TaskDescription ( "Published the docs changes to docs specific branch" ) ]
16
- [ IsDependentOn ( typeof ( BuildDocs ) ) ]
16
+ [ IsDependentOn ( typeof ( Clean ) ) ]
17
17
public sealed class PublishDocs : FrostingTask < BuildContext >
18
18
{
19
19
public override bool ShouldRun ( BuildContext context )
20
20
{
21
21
var shouldRun = true ;
22
22
shouldRun &= context . ShouldRun ( context . DirectoryExists ( Paths . Docs ) , "Wyam documentation directory is missing" ) ;
23
+ shouldRun &= context . ShouldRun ( context . IsStableRelease || context . IsPreRelease , $ "{ nameof ( PublishDocs ) } works only for releases.") ;
23
24
24
25
return shouldRun ;
25
26
}
26
27
27
28
public override void Run ( BuildContext context )
28
29
{
29
- PublishDocumentation ( context ) ;
30
+ if ( context . ForcePublish is false )
31
+ {
32
+ if ( AnyDocsChanged ( context ) )
33
+ {
34
+ context . Information ( "Performing a docs publish. Detected docs changes" ) ;
35
+ PublishDocumentation ( context ) ;
36
+ }
37
+ else
38
+ {
39
+ context . Information ( "No docs have changed, so no need to generate documentation" ) ;
40
+ }
41
+ }
42
+ else
43
+ {
44
+ context . Information ( "Performing a forced docs publish..." ) ;
45
+ PublishDocumentation ( context ) ;
46
+ }
47
+ }
48
+ private static bool AnyDocsChanged ( ICakeContext context )
49
+ {
50
+ var sourceCommit = context . GitLogTip ( Paths . Root ) ;
51
+ var filesChanged = context . GitDiff ( Paths . Root , sourceCommit . Sha ) ;
52
+
53
+ const string path = "docs/" ;
54
+ var docFileChanged = filesChanged . Any ( file => file . OldPath . StartsWith ( path ) || file . Path . StartsWith ( path ) || file . Path . Contains ( "config.wyam" ) ) ;
55
+ return docFileChanged ;
30
56
}
31
57
32
58
private static void PublishDocumentation ( BuildContext context )
@@ -42,32 +68,31 @@ private static void PublishDocumentation(BuildContext context)
42
68
BranchName = publishBranchName
43
69
} ) ;
44
70
45
- context . Information ( "Sync output files..." ) ;
46
- context . Kudu ( ) . Sync ( context . MakeAbsolute ( Paths . ArtifactsDocs . Combine ( "preview" ) ) , publishFolder , new KuduSyncSettings
71
+ if ( context . WyamSettings is not null )
47
72
{
48
- ArgumentCustomization = args => args . Append ( "--ignore" ) . AppendQuoted ( ".git;CNAME;_git2" )
49
- } ) ;
73
+ context . WyamSettings . OutputPath = publishFolder ;
74
+ context . WyamSettings . NoClean = true ;
75
+ context . Wyam ( context . WyamSettings ) ;
76
+ }
50
77
51
- if ( context . GitHasUncommitedChanges ( publishFolder ) )
52
- {
53
- context . Information ( "Stage all changes..." ) ;
54
- context . GitAddAll ( publishFolder ) ;
78
+ if ( ! context . GitHasUncommitedChanges ( publishFolder ) ) return ;
55
79
56
- if ( context . GitHasStagedChanges ( publishFolder ) )
57
- {
58
- context . Information ( "Commit all changes..." ) ;
59
- context . GitCommit (
60
- publishFolder ,
61
- sourceCommit . Committer . Name ,
62
- sourceCommit . Committer . Email ,
63
- $ "Continuous Integration Publish: { sourceCommit . Sha } \r \n { sourceCommit . Message } "
64
- ) ;
80
+ context . Information ( "Stage all changes..." ) ;
81
+ context . GitAddAll ( publishFolder ) ;
65
82
66
- PublishToGitHub ( context , publishFolder , publishBranchName ) ;
67
- }
68
- }
83
+ if ( ! context . GitHasStagedChanges ( publishFolder ) ) return ;
84
+
85
+ context . Information ( "Commit all changes..." ) ;
86
+ context . GitCommit (
87
+ publishFolder ,
88
+ sourceCommit . Committer . Name ,
89
+ sourceCommit . Committer . Email ,
90
+ $ "Continuous Integration Publish: { sourceCommit . Sha } \r \n { sourceCommit . Message } "
91
+ ) ;
92
+
93
+ PublishToGitHub ( context , publishFolder , publishBranchName ) ;
69
94
}
70
-
95
+
71
96
private static void PublishToGitHub ( BuildContext context , DirectoryPath publishFolder , string publishBranchName )
72
97
{
73
98
var username = context . Credentials ? . GitHub ? . UserName ;
0 commit comments