microsoft/hve-core

Public

mirrored fromhttps://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
hve-core-v3.3.41

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

scripts/linting/Invoke-LinkLanguageCheck.ps1

160lines · modecode

1#!/usr/bin/env pwsh
2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: MIT
4#
5# Invoke-LinkLanguageCheck.ps1
6#
7# Purpose: Wrapper for Link-Lang-Check.ps1 with GitHub Actions integration
8# Author: HVE Core Team
9
10#Requires -Version 7.0
11
12[CmdletBinding()]
13param(
14 [string[]]$ExcludePaths = @()
15)
16
17$ErrorActionPreference = 'Stop'
18
19# Import shared helpers
20Import-Module (Join-Path $PSScriptRoot "Modules/LintingHelpers.psm1") -Force
21Import-Module (Join-Path $PSScriptRoot "../lib/Modules/CIHelpers.psm1") -Force
22
23function Invoke-LinkLanguageCheckCore {
24 [CmdletBinding()]
25 param(
26 [string[]]$ExcludePaths = @()
27 )
28
29 $repoRoot = git rev-parse --show-toplevel 2>$null
30 if ($LASTEXITCODE -ne 0) {
31 Write-Error "Not in a git repository"
32 return 1
33 }
34
35 $logsDir = Join-Path $repoRoot "logs"
36 if (-not (Test-Path $logsDir)) {
37 New-Item -ItemType Directory -Path $logsDir -Force | Out-Null
38 }
39
40 Write-Host "🔍 Checking for URLs with language paths..." -ForegroundColor Cyan
41
42 try {
43 $scriptArgs = @{}
44 if ($ExcludePaths.Count -gt 0) {
45 $scriptArgs['ExcludePaths'] = $ExcludePaths
46 }
47 $jsonOutput = & (Join-Path $PSScriptRoot "Link-Lang-Check.ps1") @scriptArgs 2>&1
48
49 $results = $jsonOutput | ConvertFrom-Json
50
51 if ($results -and $results.Count -gt 0) {
52 Write-Host "Found $($results.Count) URLs with 'en-us' language paths`n" -ForegroundColor Yellow
53
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
64 foreach ($item in $results) {
65 Write-CIAnnotation `
66 -Message "URL contains language path: $($item.original_url)" `
67 -Level Warning `
68 -File $item.file `
69 -Line $item.line_number
70 }
71
72 $outputData = @{
73 timestamp = (Get-Date).ToUniversalTime().ToString("o")
74 script = "link-lang-check"
75 summary = @{
76 total_issues = $results.Count
77 files_affected = $uniqueFiles.Count
78 }
79 issues = $results
80 }
81 $outputData | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
82
83 Set-CIOutput -Name "issues" -Value $results.Count
84 Set-CIEnv -Name "LINK_LANG_FAILED" -Value "true"
85
86 Write-CIStepSummary -Content @"
87## Link Language Path Check Results
88
89⚠️ **Status**: Issues Found
90
91Found $($results.Count) URL(s) containing language path 'en-us'.
92
93**Why this matters:**
94Language-specific URLs don't adapt to user preferences and may break for non-English users.
95
96**To fix locally:**
97``````powershell
98scripts/linting/Link-Lang-Check.ps1 -Fix
99``````
100
101**Files affected:**
102$(($uniqueFiles | ForEach-Object {
103 $count = ($results | Where-Object file -eq $_).Count
104 $safePath = if ((Get-CIPlatform) -eq 'azdo') {
105 ConvertTo-AzureDevOpsEscaped -Value $_
106 } else { $_ }
107 "- $safePath ($count occurrence(s))"
108}) -join "`n")
109"@
110
111 Write-Host "❌ Link language check failed with $($results.Count) issue(s) in $($uniqueFiles.Count) file(s)." -ForegroundColor Red
112
113 return 1
114 }
115
116 Write-Host "✅ No URLs with language paths found" -ForegroundColor Green
117
118 $emptyResults = @{
119 timestamp = (Get-Date).ToUniversalTime().ToString("o")
120 script = "link-lang-check"
121 summary = @{
122 total_issues = 0
123 files_affected = 0
124 }
125 issues = @()
126 }
127 $emptyResults | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
128
129 Set-CIOutput -Name "issues" -Value "0"
130
131 Write-CIStepSummary -Content @"
132## Link Language Path Check Results
133
134✅ **Status**: Passed
135
136No URLs with language-specific paths detected.
137"@
138
139 return 0
140 }
141 catch {
142 Write-Error -ErrorAction Continue "Link-language check failed: $($_.Exception.Message)"
143 Write-CIAnnotation -Message "Link-language check failed: $($_.Exception.Message)" -Level Error
144 return 1
145 }
146}
147
148#region Main Execution
149if ($MyInvocation.InvocationName -ne '.') {
150 try {
151 $exitCode = Invoke-LinkLanguageCheckCore -ExcludePaths $ExcludePaths
152 exit $exitCode
153 }
154 catch {
155 Write-Error -ErrorAction Continue "Invoke-LinkLanguageCheck failed: $($_.Exception.Message)"
156 Write-CIAnnotation -Message $_.Exception.Message -Level Error
157 exit 1
158 }
159}
160#endregion Main Execution
161