microsoft/hve-core

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
docs/227-add-governance

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/linting/Invoke-LinkLanguageCheck.ps1

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