@@ -17,13 +17,13 @@ namespace Documentation.Assembler.Cli;
1717internal sealed class InboundLinkCommands ( ILoggerFactory logger , ICoreService githubActionsService )
1818{
1919 private readonly LinkIndexLinkChecker _linkIndexLinkChecker = new ( logger ) ;
20+ private readonly ILogger < Program > _log = logger . CreateLogger < Program > ( ) ;
2021
2122 [ SuppressMessage ( "Usage" , "CA2254:Template should be a static expression" ) ]
2223 private void AssignOutputLogger ( )
2324 {
24- var log = logger . CreateLogger < Program > ( ) ;
25- ConsoleApp . Log = msg => log . LogInformation ( msg ) ;
26- ConsoleApp . LogError = msg => log . LogError ( msg ) ;
25+ ConsoleApp . Log = msg => _log . LogInformation ( msg ) ;
26+ ConsoleApp . LogError = msg => _log . LogError ( msg ) ;
2727 }
2828
2929 /// <summary> Validate all published cross_links in all published links.json files. </summary>
@@ -64,19 +64,30 @@ public async Task<int> ValidateRepoInboundLinks(string? from = null, string? to
6464 /// Validate a locally published links.json file against all published links.json files in the registry
6565 /// </summary>
6666 /// <param name="file">Path to `links.json` defaults to '.artifacts/docs/html/links.json'</param>
67+ /// <param name="path"> -p, Defaults to the `{pwd}` folder</param>
6768 /// <param name="ctx"></param>
6869 [ Command ( "validate-link-reference" ) ]
69- public async Task < int > ValidateLocalLinkReference ( [ Argument ] string ? file = null , Cancel ctx = default )
70+ public async Task < int > ValidateLocalLinkReference ( string ? file = null , string ? path = null , Cancel ctx = default )
7071 {
7172 AssignOutputLogger ( ) ;
7273 file ??= ".artifacts/docs/html/links.json" ;
7374 var fs = new FileSystem ( ) ;
74- var root = fs . DirectoryInfo . New ( Paths . WorkingDirectoryRoot . FullName ) ;
75+ var root = ! string . IsNullOrEmpty ( path ) ? fs . DirectoryInfo . New ( path ) : fs . DirectoryInfo . New ( Paths . WorkingDirectoryRoot . FullName ) ;
7576 var repository = GitCheckoutInformation . Create ( root , new FileSystem ( ) , logger . CreateLogger ( nameof ( GitCheckoutInformation ) ) ) . RepositoryName
7677 ?? throw new Exception ( "Unable to determine repository name" ) ;
7778
79+ var runningOnCi = ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( "GITHUB_ACTIONS" ) ) ;
80+ if ( runningOnCi && ! Paths . TryFindDocsFolderFromRoot ( fs , root , out _ , out _ ) )
81+ {
82+ _log . LogInformation ( "Running in CI on a folder with no docset.yml file in {Directory}, skipping the validation" , root . FullName ) ;
83+ return 0 ;
84+ }
85+
86+ var resolvedFile = Path . Combine ( root . FullName , file ) ;
87+ _log . LogInformation ( "Validating {File} in {Directory}" , file , root . FullName ) ;
88+
7889 await using var collector = new ConsoleDiagnosticsCollector ( logger , githubActionsService ) . StartAsync ( ctx ) ;
79- await _linkIndexLinkChecker . CheckWithLocalLinksJson ( collector , repository , file , ctx ) ;
90+ await _linkIndexLinkChecker . CheckWithLocalLinksJson ( collector , repository , resolvedFile , ctx ) ;
8091 await collector . StopAsync ( ctx ) ;
8192 return collector . Errors ;
8293 }
0 commit comments