Skip to content

Commit 4d6871f

Browse files
AhmedMustafa249WilliamBerryiiiBill Berry
authored
fix(scripts): add grouped link-lang console diagnostics and failure summary (#661)
# Pull Request ## Description - print per-file and per-issue link-lang findings in terminal output - add workflow JSON-based failure details while preserving exit behavior - extend Pester assertions for issue and no-issue output paths ## Related Issue(s) Fixes #629 ## Type of Change Select all that apply: **Code & Documentation:** - [x] Bug fix (non-breaking change fixing an issue) - [ ] New feature (non-breaking change adding functionality) - [ ] Breaking change (fix or feature causing existing functionality to change) - [ ] Documentation update **Infrastructure & Configuration:** - [x] GitHub Actions workflow - [ ] Linting configuration (markdown, PowerShell, etc.) - [ ] Security configuration - [ ] DevContainer configuration - [ ] Dependency update **Other:** - [x] Script/automation (`.ps1`, `.sh`, `.py`) - [ ] Other (please describe): ## Testing - `npm run lint:links` (with planted language links in markdown files): Returns console output with details about the affected files, line numbers and URL information - Test run shows: ``` 🔍 Checking for URLs with language paths... Found 4 URLs with 'en-us' language paths 📄 .github/CUSTOM-AGENTS.md ⚠️ Line 430: https://docs.microsoft.com/en-us/azure 📄 .github/PULL_REQUEST_TEMPLATE.md ⚠️ Line 43: https://docs.microsoft.com/en-us/azure 📄 CODE_OF_CONDUCT.md ⚠️ Line 28: https://docs.microsoft.com/en-us/azure 📄 SECURITY.md ⚠️ Line 106: https://docs.microsoft.com/en-us/azure WARNING: WARNING [.github/CUSTOM-AGENTS.md:430] URL contains language path: https://docs.microsoft.com/en-us/azure WARNING: WARNING [.github/PULL_REQUEST_TEMPLATE.md:43] URL contains language path: https://docs.microsoft.com/en-us/azure WARNING: WARNING [CODE_OF_CONDUCT.md:28] URL contains language path: https://docs.microsoft.com/en-us/azure WARNING: WARNING [SECURITY.md:106] URL contains language path: https://docs.microsoft.com/en-us/azure ❌ Link language check failed with 4 issue(s) in 4 file(s). ``` ## Checklist ### Required Checks - [ ] Documentation is updated (if applicable) - [x] Files follow existing naming conventions - [x] Changes are backwards compatible (if applicable) - [x] Tests added for new functionality (if applicable) ### Required Automated Checks The following validation commands must pass before merging: - [x] Markdown linting: `npm run lint:md` - [x] Spell checking: `npm run spell-check` - [x] Frontmatter validation: `npm run lint:frontmatter` - [x] Skill structure validation: `npm run validate:skills` - [x] Link validation: `npm run lint:md-links` - [x] PowerShell analysis: `npm run lint:ps` ## Security Considerations <!-- ⚠️ WARNING: Do not commit sensitive information such as API keys, passwords, or personal data --> - [x] This PR does not contain any sensitive or NDA information - [x] Any new dependencies have been reviewed for security issues - [x] Security-related scripts follow the principle of least privilege --------- Co-authored-by: Bill Berry <[email protected]> Co-authored-by: Bill Berry <[email protected]>
1 parent de5cfd6 commit 4d6871f

3 files changed

Lines changed: 70 additions & 8 deletions

File tree

.github/workflows/link-lang-check.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,37 @@ jobs:
4848
shell: pwsh
4949
run: |
5050
if ($env:LINK_LANG_FAILED -eq 'true') {
51-
Write-Host "Link language check failed and soft-fail is false. Failing the job."
51+
$resultsPath = 'logs/link-lang-check-results.json'
52+
53+
if (Test-Path -LiteralPath $resultsPath) {
54+
try {
55+
$results = Get-Content -LiteralPath $resultsPath -Raw | ConvertFrom-Json
56+
$totalIssues = [int]($results.summary.total_issues)
57+
$filesAffected = [int]($results.summary.files_affected)
58+
59+
if ($results.issues -and $results.issues.Count -gt 0) {
60+
if ($totalIssues -le 0) {
61+
$totalIssues = [int]$results.issues.Count
62+
}
63+
64+
if ($filesAffected -le 0) {
65+
$filesAffected = [int](($results.issues | Select-Object -ExpandProperty file -Unique).Count)
66+
}
67+
68+
Write-Host "❌ Link language check failed with $totalIssues issue(s) in $filesAffected file(s)."
69+
70+
foreach ($issue in $results.issues) {
71+
Write-Host " ⚠️ $($issue.file):$($issue.line_number) - $($issue.original_url)"
72+
}
73+
} else {
74+
Write-Host 'Link language check failed and no issue entries were found in logs/link-lang-check-results.json.'
75+
}
76+
} catch {
77+
Write-Host 'Link language check failed and logs/link-lang-check-results.json could not be parsed.'
78+
}
79+
} else {
80+
Write-Host 'Link language check failed and logs/link-lang-check-results.json was not found.'
81+
}
82+
5283
exit 1
5384
}

scripts/linting/Invoke-LinkLanguageCheck.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ function Invoke-LinkLanguageCheckCore {
5151
if ($results -and $results.Count -gt 0) {
5252
Write-Host "Found $($results.Count) URLs with 'en-us' language paths`n" -ForegroundColor Yellow
5353

54+
$fileGroups = $results | Group-Object -Property file
55+
$uniqueFiles = $fileGroups | ForEach-Object { $_.Name }
56+
57+
foreach ($fileGroup in $fileGroups) {
58+
Write-Host "📄 $($fileGroup.Name)" -ForegroundColor Cyan
59+
foreach ($item in $fileGroup.Group) {
60+
Write-Host " ⚠️ Line $($item.line_number): $($item.original_url)" -ForegroundColor Yellow
61+
}
62+
}
63+
5464
foreach ($item in $results) {
5565
Write-CIAnnotation `
5666
-Message "URL contains language path: $($item.original_url)" `
@@ -64,7 +74,7 @@ function Invoke-LinkLanguageCheckCore {
6474
script = "link-lang-check"
6575
summary = @{
6676
total_issues = $results.Count
67-
files_affected = ($results | Select-Object -ExpandProperty file -Unique).Count
77+
files_affected = $uniqueFiles.Count
6878
}
6979
issues = $results
7080
}
@@ -73,8 +83,6 @@ function Invoke-LinkLanguageCheckCore {
7383
Set-CIOutput -Name "issues" -Value $results.Count
7484
Set-CIEnv -Name "LINK_LANG_FAILED" -Value "true"
7585

76-
$uniqueFiles = $results | Select-Object -ExpandProperty file -Unique
77-
7886
Write-CIStepSummary -Content @"
7987
## Link Language Path Check Results
8088
@@ -100,6 +108,8 @@ $(($uniqueFiles | ForEach-Object {
100108
}) -join "`n")
101109
"@
102110

111+
Write-Host "❌ Link language check failed with $($results.Count) issue(s) in $($uniqueFiles.Count) file(s)." -ForegroundColor Red
112+
103113
return 1
104114
}
105115

scripts/tests/linting/Invoke-LinkLanguageCheck.Tests.ps1

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules Pester
1+
#Requires -Modules Pester
22
# Copyright (c) Microsoft Corporation.
33
# SPDX-License-Identifier: MIT
44
<#
@@ -70,7 +70,8 @@ Describe 'Invoke-LinkLanguageCheckCore' -Tag 'Unit' {
7070
Context 'Issues found in link scan' {
7171
BeforeEach {
7272
$script:RepoRoot = $TestDrive
73-
$script:MockLinkLang = Join-Path $TestDrive 'mock-link-lang.ps1'
73+
$script:MockLinkLang = Join-Path $TestDrive 'mock-link-lang.ps1'
74+
$script:WriteHostMessages = @()
7475

7576
@'
7677
param([string[]]$ExcludePaths = @())
@@ -97,14 +98,27 @@ Write-Output $json
9798
Mock Set-CIOutput { }
9899
Mock Set-CIEnv { }
99100
Mock Write-CIStepSummary { }
100-
Mock Write-Host { }
101+
Mock Write-Host {
102+
param($Object)
103+
$script:WriteHostMessages += [string]$Object
104+
}
101105
}
102106

103107
It 'Returns failure exit code and records outputs' {
104108
Invoke-LinkLanguageCheckCore -ExcludePaths @('scripts/tests/**') | Should -Be 1
105109
Should -Invoke Set-CIOutput -Times 1
106110
Should -Invoke Set-CIEnv -Times 1
107111
Should -Invoke Write-CIAnnotation -Times 2
112+
Should -Invoke Write-CIStepSummary -Times 1
113+
114+
Should -Invoke Write-Host -Times 1 -ParameterFilter { $Object -like '*📄 docs/a.md*' }
115+
Should -Invoke Write-Host -Times 1 -ParameterFilter { $Object -like '*📄 docs/b.md*' }
116+
Should -Invoke Write-Host -ParameterFilter { $Object -like '*Line 1:*' }
117+
Should -Invoke Write-Host -ParameterFilter { $Object -like '*Line 2:*' }
118+
Should -Invoke Write-Host -Times 1 -ParameterFilter { $Object -like '*failed with 2 issue*' }
119+
120+
$script:WriteHostMessages | Should -Contain '📄 docs/a.md'
121+
$script:WriteHostMessages | Should -Contain '📄 docs/b.md'
108122
}
109123
}
110124

@@ -133,13 +147,20 @@ Write-Output $json
133147

134148
Mock Set-CIOutput { }
135149
Mock Write-CIStepSummary { }
136-
Mock Write-Host { }
150+
Mock Write-Host {
151+
param($Object)
152+
$script:WriteHostMessages += [string]$Object
153+
}
137154
}
138155

139156
It 'Returns success exit code and records outputs' {
157+
$script:WriteHostMessages = @()
140158
Invoke-LinkLanguageCheckCore -ExcludePaths @() | Should -Be 0
141159
Should -Invoke Set-CIOutput -Times 1
142160
Should -Invoke Write-CIStepSummary -Times 1
161+
Should -Invoke Write-Host -Times 1 -ParameterFilter { $Object -like '*✅ No URLs with language paths found*' }
162+
Should -Invoke Write-Host -Times 0 -ParameterFilter { $Object -like '*📄*' }
163+
Should -Invoke Write-Host -Times 0 -ParameterFilter { $Object -like '*⚠️*' }
143164
}
144165
}
145166
}

0 commit comments

Comments
 (0)