@@ -17,13 +17,13 @@ namespace Documentation.Assembler.Cli;
17
17
internal sealed class InboundLinkCommands ( ILoggerFactory logger , ICoreService githubActionsService )
18
18
{
19
19
private readonly LinkIndexLinkChecker _linkIndexLinkChecker = new ( logger ) ;
20
+ private readonly ILogger < Program > _log = logger . CreateLogger < Program > ( ) ;
20
21
21
22
[ SuppressMessage ( "Usage" , "CA2254:Template should be a static expression" ) ]
22
23
private void AssignOutputLogger ( )
23
24
{
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 ) ;
27
27
}
28
28
29
29
/// <summary> Validate all published cross_links in all published links.json files. </summary>
@@ -64,19 +64,36 @@ public async Task<int> ValidateRepoInboundLinks(string? from = null, string? to
64
64
/// Validate a locally published links.json file against all published links.json files in the registry
65
65
/// </summary>
66
66
/// <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>
67
68
/// <param name="ctx"></param>
68
69
[ 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 )
70
71
{
71
72
AssignOutputLogger ( ) ;
72
73
file ??= ".artifacts/docs/html/links.json" ;
73
74
var fs = new FileSystem ( ) ;
74
- var root = fs . DirectoryInfo . New ( Paths . WorkingDirectoryRoot . FullName ) ;
75
- var repository = GitCheckoutInformation . Create ( root , new FileSystem ( ) , logger . CreateLogger ( nameof ( GitCheckoutInformation ) ) ) . RepositoryName
75
+ var root = ! string . IsNullOrEmpty ( path ) ? fs . DirectoryInfo . New ( path ) : fs . DirectoryInfo . New ( Paths . WorkingDirectoryRoot . FullName ) ;
76
+ var repository = GitCheckoutInformation . Create ( root , fs , logger . CreateLogger ( nameof ( GitCheckoutInformation ) ) ) . RepositoryName
76
77
?? throw new Exception ( "Unable to determine repository name" ) ;
77
78
79
+ var resolvedFile = fs . FileInfo . New ( Path . Combine ( root . FullName , file ) ) ;
80
+
81
+ var runningOnCi = ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( "GITHUB_ACTIONS" ) ) ;
82
+ if ( runningOnCi && ! resolvedFile . Exists )
83
+ {
84
+ _log . LogInformation ( "Running on CI after a build that produced no {File}, skipping the validation" , resolvedFile . FullName ) ;
85
+ return 0 ;
86
+ }
87
+ if ( runningOnCi && ! Paths . TryFindDocsFolderFromRoot ( fs , root , out _ , out _ ) )
88
+ {
89
+ _log . LogInformation ( "Running on CI, {Directory} has no documentation, skipping the validation" , root . FullName ) ;
90
+ return 0 ;
91
+ }
92
+
93
+ _log . LogInformation ( "Validating {File} in {Directory}" , file , root . FullName ) ;
94
+
78
95
await using var collector = new ConsoleDiagnosticsCollector ( logger , githubActionsService ) . StartAsync ( ctx ) ;
79
- await _linkIndexLinkChecker . CheckWithLocalLinksJson ( collector , repository , file , ctx ) ;
96
+ await _linkIndexLinkChecker . CheckWithLocalLinksJson ( collector , repository , resolvedFile . FullName , ctx ) ;
80
97
await collector . StopAsync ( ctx ) ;
81
98
return collector . Errors ;
82
99
}
0 commit comments