microsoft/hve-core

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
hve-core-v2.0.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/linting/Invoke-LinkLanguageCheck.ps1

131lines · 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#region Main Execution
33
34try {
35 # Run the language check script
36 $scriptArgs = @{}
37 if ($ExcludePaths.Count -gt 0) {
38 $scriptArgs['ExcludePaths'] = $ExcludePaths
39 }
40 $jsonOutput = & (Join-Path $PSScriptRoot "Link-Lang-Check.ps1") @scriptArgs 2>&1
41
42 $results = $jsonOutput | ConvertFrom-Json
43
44 if ($results -and $results.Count -gt 0) {
45 Write-Host "Found $($results.Count) URLs with 'en-us' language paths`n" -ForegroundColor Yellow
46
47 # Create annotations
48 foreach ($item in $results) {
49 Write-GitHubAnnotation `
50 -Type 'warning' `
51 -Message "URL contains language path: $($item.original_url)" `
52 -File $item.file `
53 -Line $item.line_number
54 }
55
56 # Save results
57 $outputData = @{
58 timestamp = (Get-Date).ToUniversalTime().ToString("o")
59 script = "link-lang-check"
60 summary = @{
61 total_issues = $results.Count
62 files_affected = ($results | Select-Object -ExpandProperty file -Unique).Count
63 }
64 issues = $results
65 }
66 $outputData | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
67
68 Set-GitHubOutput -Name "issues" -Value $results.Count
69 Set-GitHubEnv -Name "LINK_LANG_FAILED" -Value "true"
70
71 # Write summary
72 $uniqueFiles = $results | Select-Object -ExpandProperty file -Unique
73
74 Write-GitHubStepSummary -Content @"
75## Link Language Path Check Results
76
77⚠️ **Status**: Issues Found
78
79Found $($results.Count) URL(s) containing language path 'en-us'.
80
81**Why this matters:**
82Language-specific URLs don't adapt to user preferences and may break for non-English users.
83
84**To fix locally:**
85``````powershell
86scripts/linting/Link-Lang-Check.ps1 -Fix
87``````
88
89**Files affected:**
90$(($uniqueFiles | ForEach-Object { $count = ($results | Where-Object file -eq $_).Count; "- $_ ($count occurrence(s))" }) -join "`n")
91"@
92
93 exit 1
94 }
95 else {
96 Write-Host "✅ No URLs with language paths found" -ForegroundColor Green
97
98 # Save empty results
99 $emptyResults = @{
100 timestamp = (Get-Date).ToUniversalTime().ToString("o")
101 script = "link-lang-check"
102 summary = @{
103 total_issues = 0
104 files_affected = 0
105 }
106 issues = @()
107 }
108 $emptyResults | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
109
110 Set-GitHubOutput -Name "issues" -Value "0"
111
112 Write-GitHubStepSummary -Content @"
113## Link Language Path Check Results
114
115✅ **Status**: Passed
116
117No URLs with language-specific paths detected.
118"@
119
120 exit 0
121 }
122}
123catch {
124 Write-Error "Link-language check failed: $($_.Exception.Message)"
125 if ($env:GITHUB_ACTIONS -eq 'true') {
126 Write-Output "::error::$($_.Exception.Message)"
127 }
128 exit 1
129}
130
131#endregion