-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwrite_set_from_pass.ps1
More file actions
45 lines (38 loc) · 1.96 KB
/
Copy pathwrite_set_from_pass.ps1
File metadata and controls
45 lines (38 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
param(
[Parameter(Mandatory=$true)][string]$InputsPath,
[Parameter(Mandatory=$true)][string]$PassCsv,
[Parameter(Mandatory=$true)][int]$PassId,
[Parameter(Mandatory=$true)][string]$OutSetPath
)
$ErrorActionPreference = "Stop"
if (-not (Test-Path $InputsPath)) { Write-Error "Inputs file not found: $InputsPath" }
if (-not (Test-Path $PassCsv)) { Write-Error "Pass CSV not found: $PassCsv" }
$inputs = @(& "$PSScriptRoot\tester_inputs_parser.ps1" -InputPath $InputsPath)
if ($inputs.Count -eq 0) { Write-Error "No tester inputs parsed from $InputsPath" }
$rows = @(Import-Csv $PassCsv)
foreach ($row in $rows) {
$bomPass = $row.PSObject.Properties | Where-Object { $_.Name.TrimStart([char]0xFEFF) -eq 'Pass' } | Select-Object -First 1
if ($bomPass -and $bomPass.Name -ne 'Pass') { $row | Add-Member -NotePropertyName 'Pass' -NotePropertyValue $bomPass.Value -Force }
}
$pass = $rows | Where-Object { [int]$_.Pass -eq $PassId } | Select-Object -First 1
if (-not $pass) { Write-Error "Pass $PassId not found in $PassCsv" }
$properties = @($pass.PSObject.Properties.Name | ForEach-Object { $_.TrimStart([char]0xFEFF) })
$lines = @()
foreach ($input in $inputs) {
$value = $input.Current
if ($properties -contains $input.Name) {
$candidate = [string]$pass.($input.Name)
if ($candidate -ne '') { $value = $candidate }
}
if ($null -ne $input.Start -and $null -ne $input.Step -and $null -ne $input.Stop) {
$flag = if ($input.Optimize) { 'Y' } else { 'N' }
$lines += "$($input.Name)=$value||$($input.Start)||$($input.Step)||$($input.Stop)||$flag"
} else {
$lines += "$($input.Name)=$value"
}
}
$outDir = Split-Path $OutSetPath -Parent
if ($outDir -and -not (Test-Path $outDir)) { New-Item -ItemType Directory -Path $outDir -Force | Out-Null }
$lines -join "`r`n" | Set-Content -Path $OutSetPath -Encoding Unicode
Write-Host " [SET] Best pass $PassId written: $OutSetPath" -ForegroundColor Green
Get-Item $OutSetPath