Skip to content

Commit d71a8e9

Browse files
🩹 [Patch]: Refactor relative settings file path handling in PSScriptAnalyzer tests for improved clarity and logging
1 parent 1ec9058 commit d71a8e9

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

‎scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,23 @@ BeforeDiscovery {
6565

6666
Describe 'PSScriptAnalyzer' {
6767
BeforeAll {
68-
$relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, 'Action/').Trim('\').Trim('/')
69-
$relativeSettingsFilePath = $SettingsFilePath.Replace($env:GITHUB_WORKSPACE, 'Workspace/').Trim('\').Trim('/')
68+
$relativeSettingsFilePath = if ($SettingsFilePath.StartsWith($PSScriptRoot)) {
69+
$SettingsFilePath.Replace($PSScriptRoot, 'Action:').Trim('\').Trim('/')
70+
} elseif ($SettingsFilePath.StartsWith($env:GITHUB_WORKSPACE)) {
71+
$SettingsFilePath.Replace($env:GITHUB_WORKSPACE, 'Workspace:').Trim('\').Trim('/')
72+
} else {
73+
$SettingsFilePath
74+
}
75+
[pscustomobject]@{
76+
relativeSettingsFilePath = $relativeSettingsFilePath
77+
SettingsFilePath = $SettingsFilePath
78+
PSScriptRoot = $PSScriptRoot
79+
GITHUB_WORKSPACE = $env:GITHUB_WORKSPACE
80+
}
7081
LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" {
7182
$testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose
72-
Write-Warning "Found [$($testResults.Count)] issues"
7383
}
74-
LogGroup "TestResults" {
84+
LogGroup "TestResults [$($testResults.Count)]" {
7585
$testResults
7686
}
7787
}

0 commit comments

Comments
 (0)