microsoft/hve-core

Public

mirrored from https://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
hve-core-v2.3.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/linting/Invoke-LinkLanguageCheck.ps1

150lines · modeblame

66be1367Bill Berry9 months ago1#!/usr/bin/env pwsh
d19c9b3alittleKitchen7 months ago2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: MIT
66be1367Bill Berry9 months ago4#
5# Invoke-LinkLanguageCheck.ps1
6#
7# Purpose: Wrapper for Link-Lang-Check.ps1 with GitHub Actions integration
8# Author: HVE Core Team
9
6e262826little Kitchen6 months ago10#Requires -Version 7.0
11
66be1367Bill Berry9 months ago12[CmdletBinding()]
5b659230Bill Berry7 months ago13param(
14[string[]]$ExcludePaths = @()
15)
66be1367Bill Berry9 months ago16
6e262826little Kitchen6 months ago17$ErrorActionPreference = 'Stop'
18
66be1367Bill Berry9 months ago19# Import shared helpers
20Import-Module (Join-Path $PSScriptRoot "Modules/LintingHelpers.psm1") -Force
fdd75ed7Bill Berry7 months ago21Import-Module (Join-Path $PSScriptRoot "../lib/Modules/CIHelpers.psm1") -Force
66be1367Bill Berry9 months ago22
3587e6abBill Berry6 months ago23function Invoke-LinkLanguageCheckCore {
24[CmdletBinding()]
25param(
26[string[]]$ExcludePaths = @()
27)
66be1367Bill Berry9 months ago28
3587e6abBill Berry6 months ago29$repoRoot = git rev-parse --show-toplevel 2>$null
30if ($LASTEXITCODE -ne 0) {
31Write-Error "Not in a git repository"
32return 1
33}
66be1367Bill Berry9 months ago34
3587e6abBill Berry6 months ago35$logsDir = Join-Path $repoRoot "logs"
36if (-not (Test-Path $logsDir)) {
37New-Item -ItemType Directory -Path $logsDir -Force | Out-Null
35c44178o77 months ago38}
3587e6abBill Berry6 months ago39
40Write-Host "🔍 Checking for URLs with language paths..." -ForegroundColor Cyan
41
42try {
43$scriptArgs = @{}
44if ($ExcludePaths.Count -gt 0) {
45$scriptArgs['ExcludePaths'] = $ExcludePaths
66be1367Bill Berry9 months ago46}
3587e6abBill Berry6 months ago47$jsonOutput = & (Join-Path $PSScriptRoot "Link-Lang-Check.ps1") @scriptArgs 2>&1
48
49$results = $jsonOutput | ConvertFrom-Json
50
51if ($results -and $results.Count -gt 0) {
52Write-Host "Found $($results.Count) URLs with 'en-us' language paths`n" -ForegroundColor Yellow
53
54foreach ($item in $results) {
55Write-CIAnnotation `
56-Message "URL contains language path: $($item.original_url)" `
57-Level Warning `
58-File $item.file `
59-Line $item.line_number
f52352dfBill Berry9 months ago60}
3587e6abBill Berry6 months ago61
62$outputData = @{
63timestamp = (Get-Date).ToUniversalTime().ToString("o")
64script = "link-lang-check"
65summary = @{
66total_issues = $results.Count
67files_affected = ($results | Select-Object -ExpandProperty file -Unique).Count
68}
69issues = $results
70}
71$outputData | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
72
73Set-CIOutput -Name "issues" -Value $results.Count
74Set-CIEnv -Name "LINK_LANG_FAILED" -Value "true"
75
76$uniqueFiles = $results | Select-Object -ExpandProperty file -Unique
77
78Write-CIStepSummary -Content @"
66be1367Bill Berry9 months ago79## 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:**
3587e6abBill Berry6 months ago94$(($uniqueFiles | ForEach-Object {
95$count = ($results | Where-Object file -eq $_).Count
96$safePath = if ((Get-CIPlatform) -eq 'azdo') {
97ConvertTo-AzureDevOpsEscaped -Value $_
98} else { $_ }
99"- $safePath ($count occurrence(s))"
100}) -join "`n")
66be1367Bill Berry9 months ago101"@
3587e6abBill Berry6 months ago102
103return 1
104}
105
66be1367Bill Berry9 months ago106Write-Host "✅ No URLs with language paths found" -ForegroundColor Green
3587e6abBill Berry6 months ago107
f52352dfBill Berry9 months ago108$emptyResults = @{
109timestamp = (Get-Date).ToUniversalTime().ToString("o")
110script = "link-lang-check"
111summary = @{
112total_issues = 0
113files_affected = 0
114}
115issues = @()
116}
117$emptyResults | ConvertTo-Json -Depth 3 | Out-File (Join-Path $logsDir "link-lang-check-results.json") -Encoding utf8
3587e6abBill Berry6 months ago118
119Set-CIOutput -Name "issues" -Value "0"
120
121Write-CIStepSummary -Content @"
66be1367Bill Berry9 months ago122## Link Language Path Check Results
123
124✅ **Status**: Passed
125
126No URLs with language-specific paths detected.
127"@
3587e6abBill Berry6 months ago128
129return 0
66be1367Bill Berry9 months ago130}
3587e6abBill Berry6 months ago131catch {
132Write-Error -ErrorAction Continue "Link-language check failed: $($_.Exception.Message)"
133Write-CIAnnotation -Message "Link-language check failed: $($_.Exception.Message)" -Level Error
134return 1
35c44178o77 months ago135}
66be1367Bill Berry9 months ago136}
35c44178o77 months ago137
3587e6abBill Berry6 months ago138#region Main Execution
6b84a8e4Bill Berry6 months ago139if ($MyInvocation.InvocationName -ne '.') {
140try {
141$exitCode = Invoke-LinkLanguageCheckCore -ExcludePaths $ExcludePaths
142exit $exitCode
143}
144catch {
145Write-Error -ErrorAction Continue "Invoke-LinkLanguageCheck failed: $($_.Exception.Message)"
146Write-CIAnnotation -Message $_.Exception.Message -Level Error
147exit 1
148}
3587e6abBill Berry6 months ago149}
6b84a8e4Bill Berry6 months ago150#endregion Main Execution