124 lines
4.4 KiB
PowerShell
124 lines
4.4 KiB
PowerShell
param(
|
|
[string]$ArtifactRoot = "",
|
|
[string]$TenantId = "tenant-demo-001",
|
|
[string]$UserId = "",
|
|
[string]$Username = "admin@example.com",
|
|
[string]$DisplayName = "formal-launch-governance-import",
|
|
[string]$BatchName = "",
|
|
[string]$DatabaseUrl = "",
|
|
[ValidateSet("none", "sqlite_governance")]
|
|
[string]$BootstrapMode = "none"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function New-Utf8NoBomEncoding {
|
|
return New-Object System.Text.UTF8Encoding($false)
|
|
}
|
|
|
|
function Write-Utf8File {
|
|
param(
|
|
[Parameter(Mandatory = $true)][string]$Path,
|
|
[Parameter(Mandatory = $true)][AllowEmptyString()][string]$Text
|
|
)
|
|
[System.IO.File]::WriteAllText($Path, $Text, (New-Utf8NoBomEncoding))
|
|
}
|
|
|
|
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
|
|
$backendRoot = Join-Path $repoRoot "backend"
|
|
$pythonPath = Join-Path $backendRoot ".venv\Scripts\python.exe"
|
|
$helperPath = Join-Path $backendRoot "tools\formal_launch_governance_cli.py"
|
|
$timestamp = Get-Date -Format "yyyy-MM-ddTHH-mm-ss-fff"
|
|
|
|
if ([string]::IsNullOrWhiteSpace($ArtifactRoot)) {
|
|
$ArtifactRoot = Join-Path $repoRoot "project-docs\qa-artifacts\formal-launch-governance-db-import"
|
|
}
|
|
if (-not [System.IO.Path]::IsPathRooted($ArtifactRoot)) {
|
|
$ArtifactRoot = Join-Path $repoRoot $ArtifactRoot
|
|
}
|
|
$artifactDir = Join-Path $ArtifactRoot $timestamp
|
|
New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null
|
|
|
|
$rawOutputPath = Join-Path $artifactDir "formal-launch-governance-db-import.raw.log"
|
|
$summaryJson = Join-Path $artifactDir "formal-launch-governance-db-import-summary.json"
|
|
$summaryMd = Join-Path $artifactDir "formal-launch-governance-db-import-summary.md"
|
|
|
|
if (-not (Test-Path "$HOME\.Codex\skills\gstack\bin")) {
|
|
throw "gstack is required for all AI-assisted work in this repo."
|
|
}
|
|
if (-not (Test-Path -LiteralPath $pythonPath)) {
|
|
throw "backend virtualenv python not found: $pythonPath"
|
|
}
|
|
if (-not (Test-Path -LiteralPath $helperPath)) {
|
|
throw "formal launch governance helper not found: $helperPath"
|
|
}
|
|
|
|
$args = @(
|
|
$helperPath,
|
|
"import",
|
|
"--tenant-id", $TenantId,
|
|
"--username", $Username,
|
|
"--display-name", $DisplayName,
|
|
"--bootstrap-mode", $BootstrapMode
|
|
)
|
|
if (-not [string]::IsNullOrWhiteSpace($UserId)) {
|
|
$args += @("--user-id", $UserId)
|
|
}
|
|
if (-not [string]::IsNullOrWhiteSpace($BatchName)) {
|
|
$args += @("--batch-name", $BatchName)
|
|
}
|
|
if (-not [string]::IsNullOrWhiteSpace($DatabaseUrl)) {
|
|
$args += @("--database-url", $DatabaseUrl)
|
|
}
|
|
|
|
$previousErrorActionPreference = $ErrorActionPreference
|
|
$ErrorActionPreference = "Continue"
|
|
try {
|
|
$output = & $pythonPath @args 2>&1
|
|
$exitCode = $LASTEXITCODE
|
|
} finally {
|
|
$ErrorActionPreference = $previousErrorActionPreference
|
|
}
|
|
|
|
$outputText = ($output -join [Environment]::NewLine)
|
|
Write-Utf8File -Path $rawOutputPath -Text $outputText
|
|
|
|
$jsonLine = @($output | Where-Object { $_ -match '^\{' } | Select-Object -Last 1)
|
|
if ($jsonLine.Count -eq 0) {
|
|
throw "formal launch governance import did not return JSON payload"
|
|
}
|
|
|
|
$payload = $jsonLine[-1] | ConvertFrom-Json
|
|
$status = ([string]$payload.status).ToUpperInvariant()
|
|
$payload | ConvertTo-Json -Depth 12 | Set-Content -Encoding UTF8 -Path $summaryJson
|
|
|
|
$md = New-Object System.Collections.Generic.List[string]
|
|
$md.Add("# Formal Launch Governance DB Import") | Out-Null
|
|
$md.Add("") | Out-Null
|
|
$md.Add("- status: $status") | Out-Null
|
|
$md.Add("- tenant_id: $($payload.tenant_id)") | Out-Null
|
|
$md.Add("- generated_at: $($payload.generated_at)") | Out-Null
|
|
$md.Add("- artifact_dir: $artifactDir") | Out-Null
|
|
$md.Add("") | Out-Null
|
|
$md.Add("## Imported") | Out-Null
|
|
$md.Add("") | Out-Null
|
|
$md.Add("| metric | value |") | Out-Null
|
|
$md.Add("|---|---:|") | Out-Null
|
|
$md.Add("| assets | $($payload.data.imported.assets) |") | Out-Null
|
|
$md.Add("| assignments | $($payload.data.imported.assignments) |") | Out-Null
|
|
$md.Add("| decisions | $($payload.data.imported.decisions) |") | Out-Null
|
|
$md.Add("| evidences | $($payload.data.imported.evidences) |") | Out-Null
|
|
$md.Add("") | Out-Null
|
|
$md.Add("## Release Batch") | Out-Null
|
|
$md.Add("") | Out-Null
|
|
$md.Add("- batch_name: $($payload.data.release_batch.batch_name)") | Out-Null
|
|
$md.Add("- release_status: $($payload.data.release_batch.status)") | Out-Null
|
|
$md.Add("- gate_status: $($payload.data.gate_run.status)") | Out-Null
|
|
Write-Utf8File -Path $summaryMd -Text ($md -join [Environment]::NewLine)
|
|
|
|
Write-Output "FORMAL_LAUNCH_GOVERNANCE_DB_IMPORT_$status $artifactDir"
|
|
|
|
if ($exitCode -ne 0 -or $status -eq "FAIL") {
|
|
exit 1
|
|
}
|