552eb628b7
Sprint 4 — qualità codice: - scripts/_Common.psm1: New-CISessionOption, Resolve-VmrunPath, Invoke-Vmrun - PSScriptAnalyzerSettings.psd1: project-wide PSSA rules (security + formatting) - Remove-BuildVM.ps1: SupportsShouldProcess (-WhatIf support) - Invoke-RemoteBuild.ps1, Get-BuildArtifacts.ps1: use New-CISessionOption from module - New-BuildVM.ps1: use Resolve-VmrunPath + Invoke-Vmrun from module Sprint 5 — affidabilità: - Backup-CITemplate.ps1: stop runner, timestamped VMDK backup, prune old, restart - Watch-RunnerHealth.ps1: auto-restart act_runner, cooldown 3/h, EventLog + webhook - Register-CIScheduledTasks.ps1: add CI-RunnerHealth task (every 15 min) Sprint 6 — perf baseline: - Set-TemplateSharedFolders.ps1: idempotent VMX editor for NuGet/pip shared folders - Invoke-RemoteBuild.ps1: -UseSharedCache injects NUGET_PACKAGES + PIP_CACHE_DIR in guest - Measure-CIBenchmark.ps1: times clone/start/IP/WinRM/destroy, appends to benchmark.jsonl Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
106 lines
3.5 KiB
PowerShell
106 lines
3.5 KiB
PowerShell
#Requires -Version 5.1
|
|
<#
|
|
.SYNOPSIS
|
|
Shared helper functions for the Local CI/CD System scripts.
|
|
|
|
.DESCRIPTION
|
|
Import this module at the top of any CI script that needs WinRM session
|
|
options or vmrun wrappers:
|
|
|
|
Import-Module (Join-Path $PSScriptRoot '_Common.psm1') -Force
|
|
|
|
Exported functions:
|
|
New-CISessionOption — PSSessionOption for WinRM over self-signed TLS
|
|
Resolve-VmrunPath — Validates vmrun.exe path, throws if missing
|
|
Invoke-Vmrun — Uniform vmrun -T ws wrapper; returns ExitCode + Output
|
|
#>
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
function New-CISessionOption {
|
|
<#
|
|
.SYNOPSIS
|
|
Returns a PSSessionOption for WinRM HTTPS with self-signed certificate.
|
|
.DESCRIPTION
|
|
All CI build VMs use a self-signed TLS cert on WinRM port 5986.
|
|
This option set skips CA, CN, and revocation checks — appropriate for
|
|
an isolated lab network where PKI is not present.
|
|
.OUTPUTS
|
|
[System.Management.Automation.Remoting.PSSessionOption]
|
|
#>
|
|
[OutputType([System.Management.Automation.Remoting.PSSessionOption])]
|
|
[CmdletBinding()]
|
|
param()
|
|
New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck
|
|
}
|
|
|
|
function Resolve-VmrunPath {
|
|
<#
|
|
.SYNOPSIS
|
|
Validates that vmrun.exe exists at the specified path and returns it.
|
|
.DESCRIPTION
|
|
Throws a descriptive error if the file is not found, rather than letting
|
|
a later & call fail with a less useful message.
|
|
.PARAMETER VmrunPath
|
|
Full path to vmrun.exe.
|
|
Default: C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe
|
|
.OUTPUTS
|
|
[string] The validated VmrunPath.
|
|
#>
|
|
[OutputType([string])]
|
|
[CmdletBinding()]
|
|
param(
|
|
[string] $VmrunPath = 'C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe'
|
|
)
|
|
if (-not (Test-Path $VmrunPath -PathType Leaf)) {
|
|
throw "vmrun.exe not found at: $VmrunPath`nInstall VMware Workstation Pro and update -VmrunPath."
|
|
}
|
|
return $VmrunPath
|
|
}
|
|
|
|
function Invoke-Vmrun {
|
|
<#
|
|
.SYNOPSIS
|
|
Runs a vmrun -T ws <Operation> command and returns output and exit code.
|
|
.DESCRIPTION
|
|
Uniform wrapper so all vmrun calls share the same -T ws flag and output
|
|
capture pattern. Use -ThrowOnError for operations that must succeed
|
|
(clone, start); omit it for best-effort operations (stop, getState).
|
|
.PARAMETER VmrunPath
|
|
Full path to vmrun.exe.
|
|
.PARAMETER Operation
|
|
vmrun sub-command: clone, start, stop, deleteVM, list, getState,
|
|
listSnapshots, getGuestIPAddress, etc.
|
|
.PARAMETER Arguments
|
|
Additional positional arguments after the operation name.
|
|
.PARAMETER ThrowOnError
|
|
When set, throws if vmrun exits non-zero.
|
|
.OUTPUTS
|
|
[pscustomobject] with:
|
|
ExitCode [int] — vmrun exit code
|
|
Output [string[]] — combined stdout/stderr lines
|
|
#>
|
|
[OutputType([pscustomobject])]
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)] [string] $VmrunPath,
|
|
[Parameter(Mandatory)] [string] $Operation,
|
|
[string[]] $Arguments = @(),
|
|
[switch] $ThrowOnError
|
|
)
|
|
$cmdArgs = @('-T', 'ws', $Operation) + $Arguments
|
|
$output = & $VmrunPath @cmdArgs 2>&1
|
|
$exit = $LASTEXITCODE
|
|
|
|
if ($ThrowOnError -and $exit -ne 0) {
|
|
throw "vmrun $Operation failed (exit $exit): $($output -join '; ')"
|
|
}
|
|
|
|
return [pscustomobject]@{
|
|
ExitCode = $exit
|
|
Output = $output
|
|
}
|
|
}
|
|
|
|
Export-ModuleMember -Function New-CISessionOption, Resolve-VmrunPath, Invoke-Vmrun
|