microsoft/hve-core

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/address-powershell-test-comments

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/linting/Invoke-LinkLanguageCheck.ps1

145lines · 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
23$script:SkipMain = $env:HVE_SKIP_MAIN -eq '1'
24
25function Invoke-LinkLanguageCheckCore {
26 [CmdletBinding()]
27 param(
28 [string[]]$ExcludePaths = @()
29 )
30
31 $repoRoot = git rev-parse --show-toplevel 2>$null
32 if ($LASTEXITCODE -ne 0) {
33 Write-Error "Not in a git repository"
34 return 1
35 }
36
37 $logsDir = Join-Path $repoRoot "logs"
38 if (-not (Test-Path $logsDir)) {
39 New-Item -ItemType Directory -Path $logsDir -Force | Out-Null
40 }
41
42 Write-Host "🔍 Checking for URLs with language paths..." -ForegroundColor Cyan
43
44 try {
45 $scriptArgs = @{}
46 if ($ExcludePaths.Count -gt 0) {
47 $scriptArgs['ExcludePaths'] = $ExcludePaths
48 }
49 $jsonOutput = & (Join-Path $PSScriptRoot "Link-Lang-Check.ps1") @scriptArgs 2>&1
50
51 $results = $jsonOutput | ConvertFrom-Json
52
53 if ($results -and $results.Count -gt 0) {
54 Write-Host "Found $($results.Count) URLs with 'en-us' language paths`n" -ForegroundColor Yellow
55
56 foreach ($item in $results) {
57 Write-CIAnnotation `
58 -Message "URL contains language path: $($item.original_url)" `
59 -Level Warning `
60 -File $item.file `
61 -Line $item.line_number
62 }
63
64 $outputData = @{
65 timestamp = (Get-Date).ToUniversalTime().ToString("o")
66 script = "link-lang-check"
67 summary = @{
68 total_issues = $results.Count
69 files_affected = ($results | Select-Object -ExpandProperty file -Unique).Count
70 }
71 issues = $results
72 }
73 $outputData | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
74
75 Set-CIOutput -Name "issues" -Value $results.Count
76 Set-CIEnv -Name "LINK_LANG_FAILED" -Value "true"
77
78 $uniqueFiles = $results | Select-Object -ExpandProperty file -Unique
79
80 Write-CIStepSummary -Content @"
81## Link Language Path Check Results
82
83⚠️ **Status**: Issues Found
84
85Found $($results.Count) URL(s) containing language path 'en-us'.
86
87**Why this matters:**
88Language-specific URLs don't adapt to user preferences and may break for non-English users.
89
90**To fix locally:**
91``````powershell
92scripts/linting/Link-Lang-Check.ps1 -Fix
93``````
94
95**Files affected:**
96$(($uniqueFiles | ForEach-Object {
97 $count = ($results | Where-Object file -eq $_).Count
98 $safePath = if ((Get-CIPlatform) -eq 'azdo') {
99 ConvertTo-AzureDevOpsEscaped -Value $_
100 } else { $_ }
101 "- $safePath ($count occurrence(s))"
102}) -join "`n")
103"@
104
105 return 1
106 }
107
108 Write-Host "✅ No URLs with language paths found" -ForegroundColor Green
109
110 $emptyResults = @{
111 timestamp = (Get-Date).ToUniversalTime().ToString("o")
112 script = "link-lang-check"
113 summary = @{
114 total_issues = 0
115 files_affected = 0
116 }
117 issues = @()
118 }
119 $emptyResults | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
120
121 Set-CIOutput -Name "issues" -Value "0"
122
123 Write-CIStepSummary -Content @"
124## Link Language Path Check Results
125
126✅ **Status**: Passed
127
128No URLs with language-specific paths detected.
129"@
130
131 return 0
132 }
133 catch {
134 Write-Error -ErrorAction Continue "Link-language check failed: $($_.Exception.Message)"
135 Write-CIAnnotation -Message "Link-language check failed: $($_.Exception.Message)" -Level Error
136 return 1
137 }
138}
139
140#region Main Execution
141if (-not $script:SkipMain) {
142 $exitCode = Invoke-LinkLanguageCheckCore -ExcludePaths $ExcludePaths
143 exit $exitCode
144}
145#endregion
146