feat(sprint4-6): quality, reliability, perf baseline
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>
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
#Requires -Version 5.1
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Configures VMware shared folder entries in the CI template VMX for build cache sharing.
|
||||
|
||||
.DESCRIPTION
|
||||
Adds two shared folder mappings to the template VM's .vmx file:
|
||||
nuget-cache host: F:\CI\Cache\NuGet guest: \\vmware-host\Shared Folders\nuget-cache
|
||||
pip-cache host: F:\CI\Cache\pip guest: \\vmware-host\Shared Folders\pip-cache
|
||||
|
||||
These UNC paths are used by Invoke-RemoteBuild.ps1 -UseSharedCache to redirect
|
||||
dotnet's NuGet package store and pip's download cache to persistent host-side
|
||||
directories, avoiding repeat downloads across builds.
|
||||
|
||||
The script is idempotent: existing sharedFolder.* lines are removed before
|
||||
the new block is written. A .bak copy of the original VMX is kept alongside it.
|
||||
|
||||
Prerequisites:
|
||||
- Template VM must NOT be running when this script runs.
|
||||
- VMware Tools (HGFS driver) must be installed in the template guest.
|
||||
- Run once; all subsequent linked clones inherit the shared folder config.
|
||||
|
||||
After running: use Invoke-RemoteBuild.ps1 -UseSharedCache on builds that
|
||||
target VMs cloned from this updated template.
|
||||
|
||||
.PARAMETER TemplatePath
|
||||
Full path to the template VM's .vmx file.
|
||||
Default: F:\CI\Templates\WinBuild\CI-WinBuild.vmx
|
||||
|
||||
.PARAMETER NuGetCacheDir
|
||||
Host-side path for the NuGet package cache directory.
|
||||
Default: F:\CI\Cache\NuGet
|
||||
|
||||
.PARAMETER PipCacheDir
|
||||
Host-side path for the pip download cache directory.
|
||||
Default: F:\CI\Cache\pip
|
||||
|
||||
.EXAMPLE
|
||||
# Configure template (run from elevated PowerShell — template must be stopped)
|
||||
.\Set-TemplateSharedFolders.ps1
|
||||
|
||||
# Preview changes without modifying files
|
||||
.\Set-TemplateSharedFolders.ps1 -WhatIf
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess)]
|
||||
param(
|
||||
[string] $TemplatePath = 'F:\CI\Templates\WinBuild\CI-WinBuild.vmx',
|
||||
[string] $NuGetCacheDir = 'F:\CI\Cache\NuGet',
|
||||
[string] $PipCacheDir = 'F:\CI\Cache\pip'
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
if (-not (Test-Path $TemplatePath -PathType Leaf)) {
|
||||
throw "Template VMX not found: $TemplatePath"
|
||||
}
|
||||
|
||||
# ── Step 1: Ensure host cache directories exist ───────────────────────────────
|
||||
foreach ($dir in @($NuGetCacheDir, $PipCacheDir)) {
|
||||
if (-not (Test-Path $dir)) {
|
||||
if ($PSCmdlet.ShouldProcess($dir, 'Create host cache directory')) {
|
||||
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
||||
Write-Host "[SharedFolders] Created host cache dir: $dir"
|
||||
}
|
||||
} else {
|
||||
Write-Host "[SharedFolders] Host cache dir exists: $dir"
|
||||
}
|
||||
}
|
||||
|
||||
# ── Step 2: Read VMX, strip existing sharedFolder + HGFS lines ───────────────
|
||||
$lines = [System.IO.File]::ReadAllLines($TemplatePath, [System.Text.Encoding]::UTF8)
|
||||
$stripped = $lines | Where-Object {
|
||||
$_ -notmatch '^sharedFolder' -and
|
||||
$_ -notmatch '^isolation\.tools\.hgfs\.disable'
|
||||
}
|
||||
|
||||
# ── Step 3: Build replacement sharedFolder block ──────────────────────────────
|
||||
# VMX hostPath requires double-escaped backslashes
|
||||
$nugetEsc = $NuGetCacheDir.Replace('\', '\\')
|
||||
$pipEsc = $PipCacheDir.Replace('\', '\\')
|
||||
|
||||
$sharedBlock = @(
|
||||
'sharedFolder.maxNum = "2"'
|
||||
'sharedFolder0.present = "TRUE"'
|
||||
'sharedFolder0.enabled = "TRUE"'
|
||||
'sharedFolder0.readAccess = "TRUE"'
|
||||
'sharedFolder0.writeAccess = "TRUE"'
|
||||
"sharedFolder0.hostPath = `"$nugetEsc`""
|
||||
'sharedFolder0.guestName = "nuget-cache"'
|
||||
'sharedFolder0.expiration = "never"'
|
||||
'sharedFolder1.present = "TRUE"'
|
||||
'sharedFolder1.enabled = "TRUE"'
|
||||
'sharedFolder1.readAccess = "TRUE"'
|
||||
'sharedFolder1.writeAccess = "TRUE"'
|
||||
"sharedFolder1.hostPath = `"$pipEsc`""
|
||||
'sharedFolder1.guestName = "pip-cache"'
|
||||
'sharedFolder1.expiration = "never"'
|
||||
'isolation.tools.hgfs.disable = "FALSE"'
|
||||
)
|
||||
|
||||
$newLines = @($stripped) + $sharedBlock
|
||||
|
||||
# ── Step 4: Backup and write VMX ─────────────────────────────────────────────
|
||||
if ($PSCmdlet.ShouldProcess($TemplatePath, 'Write updated VMX with shared folder entries')) {
|
||||
$backupPath = "$TemplatePath.bak"
|
||||
Copy-Item $TemplatePath $backupPath -Force
|
||||
Write-Host "[SharedFolders] Original backed up: $backupPath"
|
||||
|
||||
[System.IO.File]::WriteAllLines($TemplatePath, $newLines, [System.Text.Encoding]::UTF8)
|
||||
|
||||
Write-Host "[SharedFolders] VMX updated: $TemplatePath"
|
||||
Write-Host "[SharedFolders] Mappings:"
|
||||
Write-Host " nuget-cache $NuGetCacheDir -> \\vmware-host\Shared Folders\nuget-cache"
|
||||
Write-Host " pip-cache $PipCacheDir -> \\vmware-host\Shared Folders\pip-cache"
|
||||
Write-Host "[SharedFolders] Next: run Invoke-RemoteBuild.ps1 -UseSharedCache to activate."
|
||||
}
|
||||
Reference in New Issue
Block a user