1+ using System ;
12using System . IO ;
23using System . Linq ;
34using System . Text ;
@@ -47,6 +48,11 @@ public class BuildContext : FrostingContext
4748
4849 public DirectoryPath ChangeLogDirectory { get ; }
4950 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 ; }
5056
5157 public FilePath SolutionFile { get ; }
5258 public FilePath UnitTestsProjectFile { get ; }
@@ -80,6 +86,11 @@ public BuildContext(ICakeContext context)
8086
8187 ChangeLogDirectory = RootDirectory . Combine ( "docs" ) . Combine ( "changelog" ) ;
8288 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" ) ;
8394
8495 SolutionFile = RootDirectory . CombineWithFilePath ( "BenchmarkDotNet.sln" ) ;
8596 UnitTestsProjectFile = RootDirectory . Combine ( "tests" ) . Combine ( "BenchmarkDotNet.Tests" )
@@ -132,7 +143,7 @@ public void RunTests(FilePath projectFile, string alias, string tfm)
132143 public void DocfxChangelogDownload ( string version , string versionPrevious , string lastCommit = "" )
133144 {
134145 this . Information ( "DocfxChangelogDownload: " + version ) ;
135- // Required environment variables: GITHIB_PRODUCT , GITHUB_TOKEN
146+ // Required environment variables: GITHUB_PRODUCT , GITHUB_TOKEN
136147 var changeLogBuilderDirectory = ChangeLogGenDirectory . Combine ( "ChangeLogBuilder" ) ;
137148 var changeLogBuilderProjectFile = changeLogBuilderDirectory . CombineWithFilePath ( "ChangeLogBuilder.csproj" ) ;
138149 this . DotNetRun ( changeLogBuilderProjectFile . FullPath ,
@@ -198,11 +209,26 @@ public void RunDocfx(FilePath docfxJson, string args = "")
198209 else
199210 this . StartProcess ( DocfxExeFile . FullPath , new ProcessSettings { Arguments = docfxJson + " " + args } ) ;
200211 }
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+ }
201227}
202228
203229public static class DocumentationHelper
204230{
205- public const string DocFxVersion = "2.59.3 " ;
231+ public const string DocFxVersion = "2.59.4 " ;
206232
207233 public static readonly string [ ] BdnAllVersions =
208234 {
@@ -428,12 +454,19 @@ public override void Run(BuildContext context)
428454 context . DocfxChangelogDownload (
429455 DocumentationHelper . BdnAllVersions [ i ] ,
430456 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 ] ) ;
431463 }
432464
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" ) ;
437470 }
438471}
439472
@@ -454,6 +487,15 @@ public override void Run(BuildContext context)
454487 }
455488}
456489
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+
457499// In order to work around xref issues in DocFx, BenchmarkDotNet and BenchmarkDotNet.Annotations must be build
458500// before running the DocFX_Build target. However, including a dependency on BuildTask here may have unwanted
459501// side effects (CleanTask).
@@ -466,6 +508,7 @@ public class DocfxChangelogBuildTask : FrostingTask<BuildContext>
466508 public override void Run ( BuildContext context )
467509 {
468510 context . RunDocfx ( context . DocfxJsonFile ) ;
511+ context . GenerateRedirects ( ) ;
469512 }
470513}
471514
@@ -476,6 +519,8 @@ public class DocfxChangelogServeTask : FrostingTask<BuildContext>
476519{
477520 public override void Run ( BuildContext context )
478521 {
522+ context . RunDocfx ( context . DocfxJsonFile ) ;
523+ context . GenerateRedirects ( ) ;
479524 context . RunDocfx ( context . DocfxJsonFile , "--serve" ) ;
480525 }
481526}
0 commit comments