7d12dedddd
§6.2 - New composite action gitea/actions/local-ci-build/action.yml
Wraps Invoke-CIJob.ps1 for reuse across repos. Inputs: build-command,
artifact-source, submodules, guest-os, use-git-clone, configuration,
template-path, snapshot-name, artifact-name, artifact-retention-days.
Anti-injection: all params via INPUT_* env vars, never interpolated in shell.
§6.4 - Build matrix windows+linux in build-nsis.yml
gitea/workflows/build-nsis.yml rewritten with strategy.matrix target:
[windows, linux], fail-fast: false, routes to {target}-build runner.
Added action inputs: job-id-suffix (matrix disambig for artifact dirs),
repo-url (SSH URL override for gitea-ci alias).
§6.5 - ExtraGuestEnv secret injection chain
New param -ExtraGuestEnv [hashtable] in Invoke-CIJob.ps1 and
Invoke-RemoteBuild.ps1. Windows: SetEnvironmentVariable in WinRM session
ScriptBlock before build command. Linux: export KEY='val'; prefix before
cd && buildcmd (POSIX single-quote escaping). Composite action input
extra-guest-env-json (JSON object -> ConvertFrom-Json -> hashtable),
never logged.
PSScriptAnalyzer fixes: _Common.psm1, Invoke-RetentionPolicy.ps1,
Watch-RunnerHealth.ps1 (empty catch, ShouldProcess suppression, etc.)
Docs/test: TEST-PLAN-v1.3-to-HEAD.md updated §3.3/§6.1/§5.4 status.
TODO.md: §6 fully closed (6.1-6.2 done, 6.3 deferred, 6.4-6.5 done, 6.6 done).
108 lines
3.7 KiB
PowerShell
108 lines
3.7 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])]
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',
|
|
Justification = 'New-CISessionOption creates an in-memory PSSessionOption object; no system state is changed.')]
|
|
[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
|