microsoft/hve-core

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-copilot-code-review

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/linting/Invoke-LinkLanguageCheck.ps1

119lines · modecode

1#!/usr/bin/env pwsh
2#
3# Invoke-LinkLanguageCheck.ps1
4#
5# Purpose: Wrapper for Link-Lang-Check.ps1 with GitHub Actions integration
6# Author: HVE Core Team
7# Created: 2025-11-05
8
9[CmdletBinding()]
10param()
11
12# Import shared helpers
13Import-Module (Join-Path $PSScriptRoot "Modules/LintingHelpers.psm1") -Force
14
15# Get repository root
16$repoRoot = git rev-parse --show-toplevel 2>$null
17if ($LASTEXITCODE -ne 0) {
18 Write-Error "Not in a git repository"
19 exit 1
20}
21
22# Create logs directory if it doesn't exist
23$logsDir = Join-Path $repoRoot "logs"
24if (-not (Test-Path $logsDir)) {
25 New-Item -ItemType Directory -Path $logsDir -Force | Out-Null
26}
27
28Write-Host "🔍 Checking for URLs with language paths..." -ForegroundColor Cyan
29
30# Run the language check script
31$jsonOutput = & (Join-Path $PSScriptRoot "Link-Lang-Check.ps1") 2>&1
32
33try {
34 $results = $jsonOutput | ConvertFrom-Json
35
36 if ($results -and $results.Count -gt 0) {
37 Write-Host "Found $($results.Count) URLs with 'en-us' language paths`n" -ForegroundColor Yellow
38
39 # Create annotations
40 foreach ($item in $results) {
41 Write-GitHubAnnotation `
42 -Type 'warning' `
43 -Message "URL contains language path: $($item.original_url)" `
44 -File $item.file `
45 -Line $item.line_number
46 }
47
48 # Save results
49 $outputData = @{
50 timestamp = (Get-Date).ToUniversalTime().ToString("o")
51 script = "link-lang-check"
52 summary = @{
53 total_issues = $results.Count
54 files_affected = ($results | Select-Object -ExpandProperty file -Unique).Count
55 }
56 issues = $results
57 }
58 $outputData | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
59
60 Set-GitHubOutput -Name "issues" -Value $results.Count
61 Set-GitHubEnv -Name "LINK_LANG_FAILED" -Value "true"
62
63 # Write summary
64 $uniqueFiles = $results | Select-Object -ExpandProperty file -Unique
65
66 Write-GitHubStepSummary -Content @"
67## Link Language Path Check Results
68
69⚠️ **Status**: Issues Found
70
71Found $($results.Count) URL(s) containing language path 'en-us'.
72
73**Why this matters:**
74Language-specific URLs don't adapt to user preferences and may break for non-English users.
75
76**To fix locally:**
77``````powershell
78scripts/linting/Link-Lang-Check.ps1 -Fix
79``````
80
81**Files affected:**
82$(($uniqueFiles | ForEach-Object { $count = ($results | Where-Object file -eq $_).Count; "- $_ ($count occurrence(s))" }) -join "`n")
83"@
84
85 exit 1
86 }
87 else {
88 Write-Host "✅ No URLs with language paths found" -ForegroundColor Green
89
90 # Save empty results
91 $emptyResults = @{
92 timestamp = (Get-Date).ToUniversalTime().ToString("o")
93 script = "link-lang-check"
94 summary = @{
95 total_issues = 0
96 files_affected = 0
97 }
98 issues = @()
99 }
100 $emptyResults | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
101
102 Set-GitHubOutput -Name "issues" -Value "0"
103
104 Write-GitHubStepSummary -Content @"
105## Link Language Path Check Results
106
107✅ **Status**: Passed
108
109No URLs with language-specific paths detected.
110"@
111
112 exit 0
113 }
114}
115catch {
116 Write-Error "Error parsing results: $_"
117 Write-Host "Raw output: $jsonOutput"
118 exit 1
119}
120