1
+ using System ;
1
2
using System . IO ;
2
3
using System . Linq ;
3
4
using System . Text ;
@@ -47,6 +48,11 @@ public class BuildContext : FrostingContext
47
48
48
49
public DirectoryPath ChangeLogDirectory { get ; }
49
50
public DirectoryPath ChangeLogGenDirectory { get ; }
51
+
52
+ public DirectoryPath RedirectRootDirectory { get ; }
53
+ public DirectoryPath RedirectProjectDirectory { get ; }
54
+ public DirectoryPath RedirectSourceDirectory { get ; }
55
+ public DirectoryPath RedirectTargetDirectory { get ; }
50
56
51
57
public FilePath SolutionFile { get ; }
52
58
public FilePath UnitTestsProjectFile { get ; }
@@ -80,6 +86,11 @@ public BuildContext(ICakeContext context)
80
86
81
87
ChangeLogDirectory = RootDirectory . Combine ( "docs" ) . Combine ( "changelog" ) ;
82
88
ChangeLogGenDirectory = RootDirectory . Combine ( "docs" ) . Combine ( "_changelog" ) ;
89
+
90
+ RedirectRootDirectory = RootDirectory . Combine ( "docs" ) . Combine ( "_redirects" ) ;
91
+ RedirectProjectDirectory = RedirectRootDirectory . Combine ( "RedirectGenerator" ) ;
92
+ RedirectSourceDirectory = RedirectRootDirectory . Combine ( "redirects" ) ;
93
+ RedirectTargetDirectory = RootDirectory . Combine ( "docs" ) . Combine ( "_site" ) ;
83
94
84
95
SolutionFile = RootDirectory . CombineWithFilePath ( "BenchmarkDotNet.sln" ) ;
85
96
UnitTestsProjectFile = RootDirectory . Combine ( "tests" ) . Combine ( "BenchmarkDotNet.Tests" )
@@ -132,7 +143,7 @@ public void RunTests(FilePath projectFile, string alias, string tfm)
132
143
public void DocfxChangelogDownload ( string version , string versionPrevious , string lastCommit = "" )
133
144
{
134
145
this . Information ( "DocfxChangelogDownload: " + version ) ;
135
- // Required environment variables: GITHIB_PRODUCT , GITHUB_TOKEN
146
+ // Required environment variables: GITHUB_PRODUCT , GITHUB_TOKEN
136
147
var changeLogBuilderDirectory = ChangeLogGenDirectory . Combine ( "ChangeLogBuilder" ) ;
137
148
var changeLogBuilderProjectFile = changeLogBuilderDirectory . CombineWithFilePath ( "ChangeLogBuilder.csproj" ) ;
138
149
this . DotNetRun ( changeLogBuilderProjectFile . FullPath ,
@@ -198,11 +209,26 @@ public void RunDocfx(FilePath docfxJson, string args = "")
198
209
else
199
210
this . StartProcess ( DocfxExeFile . FullPath , new ProcessSettings { Arguments = docfxJson + " " + args } ) ;
200
211
}
212
+
213
+ public void GenerateRedirects ( )
214
+ {
215
+ var redirectProjectFile = RedirectProjectDirectory . CombineWithFilePath ( "RedirectGenerator.csproj" ) ;
216
+ this . Information ( redirectProjectFile . FullPath ) ;
217
+ this . DotNetBuild ( redirectProjectFile . FullPath ) ;
218
+ this . DotNetRun ( redirectProjectFile . FullPath , new DotNetRunSettings
219
+ {
220
+ WorkingDirectory = RedirectProjectDirectory ,
221
+ } ) ;
222
+
223
+ this . Information ( RedirectTargetDirectory ) ;
224
+ this . EnsureDirectoryExists ( RedirectTargetDirectory ) ;
225
+ this . CopyFiles ( RedirectSourceDirectory + "/**/*" , RedirectTargetDirectory , true ) ;
226
+ }
201
227
}
202
228
203
229
public static class DocumentationHelper
204
230
{
205
- public const string DocFxVersion = "2.59.3 " ;
231
+ public const string DocFxVersion = "2.59.4 " ;
206
232
207
233
public static readonly string [ ] BdnAllVersions =
208
234
{
@@ -428,12 +454,19 @@ public override void Run(BuildContext context)
428
454
context . DocfxChangelogDownload (
429
455
DocumentationHelper . BdnAllVersions [ i ] ,
430
456
DocumentationHelper . BdnAllVersions [ i - 1 ] ) ;
457
+ } else if ( context . Argument ( "LatestVersions" , false ) )
458
+ {
459
+ for ( int i = DocumentationHelper . BdnAllVersions . Length - 2 ; i < DocumentationHelper . BdnAllVersions . Length ; i ++ )
460
+ context . DocfxChangelogDownload (
461
+ DocumentationHelper . BdnAllVersions [ i ] ,
462
+ DocumentationHelper . BdnAllVersions [ i - 1 ] ) ;
431
463
}
432
464
433
- context . DocfxChangelogDownload (
434
- DocumentationHelper . BdnNextVersion ,
435
- DocumentationHelper . BdnAllVersions . Last ( ) ,
436
- "HEAD" ) ;
465
+ if ( ! context . Argument ( "StableVersions" , false ) )
466
+ context . DocfxChangelogDownload (
467
+ DocumentationHelper . BdnNextVersion ,
468
+ DocumentationHelper . BdnAllVersions . Last ( ) ,
469
+ "HEAD" ) ;
437
470
}
438
471
}
439
472
@@ -454,6 +487,15 @@ public override void Run(BuildContext context)
454
487
}
455
488
}
456
489
490
+ [ TaskName ( "DocFX_Generate_Redirects" ) ]
491
+ public class DocfxGenerateRedirectsTask : FrostingTask < BuildContext >
492
+ {
493
+ public override void Run ( BuildContext context )
494
+ {
495
+ context . GenerateRedirects ( ) ;
496
+ }
497
+ }
498
+
457
499
// In order to work around xref issues in DocFx, BenchmarkDotNet and BenchmarkDotNet.Annotations must be build
458
500
// before running the DocFX_Build target. However, including a dependency on BuildTask here may have unwanted
459
501
// side effects (CleanTask).
@@ -466,6 +508,7 @@ public class DocfxChangelogBuildTask : FrostingTask<BuildContext>
466
508
public override void Run ( BuildContext context )
467
509
{
468
510
context . RunDocfx ( context . DocfxJsonFile ) ;
511
+ context . GenerateRedirects ( ) ;
469
512
}
470
513
}
471
514
@@ -476,6 +519,8 @@ public class DocfxChangelogServeTask : FrostingTask<BuildContext>
476
519
{
477
520
public override void Run ( BuildContext context )
478
521
{
522
+ context . RunDocfx ( context . DocfxJsonFile ) ;
523
+ context . GenerateRedirects ( ) ;
479
524
context . RunDocfx ( context . DocfxJsonFile , "--serve" ) ;
480
525
}
481
526
}
0 commit comments