microsoft/hve-core

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
3156d989fcde1e181d04ebf56ab4ad29b0084d04

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/linting/Invoke-LinkLanguageCheck.ps1

150lines · 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 foreach ($item in $results) {
55 Write-CIAnnotation `
56 -Message "URL contains language path: $($item.original_url)" `
57 -Level Warning `
58 -File $item.file `
59 -Line $item.line_number
60 }
61
62 $outputData = @{
63 timestamp = (Get-Date).ToUniversalTime().ToString("o")
64 script = "link-lang-check"
65 summary = @{
66 total_issues = $results.Count
67 files_affected = ($results | Select-Object -ExpandProperty file -Unique).Count
68 }
69 issues = $results
70 }
71 $outputData | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
72
73 Set-CIOutput -Name "issues" -Value $results.Count
74 Set-CIEnv -Name "LINK_LANG_FAILED" -Value "true"
75
76 $uniqueFiles = $results | Select-Object -ExpandProperty file -Unique
77
78 Write-CIStepSummary -Content @"
79## Link Language Path Check Results
80
81⚠️ **Status**: Issues Found
82
83Found $($results.Count) URL(s) containing language path 'en-us'.
84
85**Why this matters:**
86Language-specific URLs don't adapt to user preferences and may break for non-English users.
87
88**To fix locally:**
89``````powershell
90scripts/linting/Link-Lang-Check.ps1 -Fix
91``````
92
93**Files affected:**
94$(($uniqueFiles | ForEach-Object {
95 $count = ($results | Where-Object file -eq $_).Count
96 $safePath = if ((Get-CIPlatform) -eq 'azdo') {
97 ConvertTo-AzureDevOpsEscaped -Value $_
98 } else { $_ }
99 "- $safePath ($count occurrence(s))"
100}) -join "`n")
101"@
102
103 return 1
104 }
105
106 Write-Host "✅ No URLs with language paths found" -ForegroundColor Green
107
108 $emptyResults = @{
109 timestamp = (Get-Date).ToUniversalTime().ToString("o")
110 script = "link-lang-check"
111 summary = @{
112 total_issues = 0
113 files_affected = 0
114 }
115 issues = @()
116 }
117 $emptyResults | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
118
119 Set-CIOutput -Name "issues" -Value "0"
120
121 Write-CIStepSummary -Content @"
122## Link Language Path Check Results
123
124✅ **Status**: Passed
125
126No URLs with language-specific paths detected.
127"@
128
129 return 0
130 }
131 catch {
132 Write-Error -ErrorAction Continue "Link-language check failed: $($_.Exception.Message)"
133 Write-CIAnnotation -Message "Link-language check failed: $($_.Exception.Message)" -Level Error
134 return 1
135 }
136}
137
138#region Main Execution
139if ($MyInvocation.InvocationName -ne '.') {
140 try {
141 $exitCode = Invoke-LinkLanguageCheckCore -ExcludePaths $ExcludePaths
142 exit $exitCode
143 }
144 catch {
145 Write-Error -ErrorAction Continue "Invoke-LinkLanguageCheck failed: $($_.Exception.Message)"
146 Write-CIAnnotation -Message $_.Exception.Message -Level Error
147 exit 1
148 }
149}
150#endregion Main Execution
151