Files
MercuryToolbox/scripts/check-ai-skill.ps1
T

75 lines
1.9 KiB
PowerShell

[CmdletBinding()]
param(
[ValidateSet('Debug', 'Release', 'ReleaseFast', 'ReleaseSize')]
[string]$Configuration = 'ReleaseFast',
[switch]$SkipBuild
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$generatorScriptName = 'generate-ai-skill.ps1'
$assetLabel = 'Mercury Toolbox skill'
function Invoke-GeneratorCheck {
param(
[Parameter(Mandatory = $true)]
[string]$ScriptPath,
[Parameter(Mandatory = $true)]
[hashtable]$InvokeArgs
)
try {
& $ScriptPath @InvokeArgs
if ($LASTEXITCODE -ne 0) {
throw "$generatorScriptName exited with $LASTEXITCODE"
}
return $true
}
catch {
Write-Host "$assetLabel check found drift: $($_.Exception.Message)"
return $false
}
}
function Invoke-GeneratorWrite {
param(
[Parameter(Mandatory = $true)]
[string]$ScriptPath,
[Parameter(Mandatory = $true)]
[hashtable]$InvokeArgs
)
$writeArgs = @{}
foreach ($key in $InvokeArgs.Keys) {
if ($key -ne 'Check') {
$writeArgs[$key] = $InvokeArgs[$key]
}
}
& $ScriptPath @writeArgs
if ($LASTEXITCODE -ne 0) {
throw "$generatorScriptName exited with $LASTEXITCODE while regenerating $assetLabel"
}
}
$scriptPath = Join-Path $PSScriptRoot $generatorScriptName
$invokeArgs = @{
Configuration = $Configuration
Check = $true
}
if ($SkipBuild) {
$invokeArgs.SkipBuild = $true
}
if (Invoke-GeneratorCheck -ScriptPath $scriptPath -InvokeArgs $invokeArgs) {
return
}
Write-Host "Regenerating $assetLabel before rechecking."
Invoke-GeneratorWrite -ScriptPath $scriptPath -InvokeArgs $invokeArgs
if (-not (Invoke-GeneratorCheck -ScriptPath $scriptPath -InvokeArgs $invokeArgs)) {
throw "Generated $assetLabel is still out of date after regeneration; manual intervention is required."
}