Private/Read-PCReleaseConfig.ps1
|
function Read-PCReleaseConfig { <# .SYNOPSIS Read the optional .powercraft/release.json config file from a repository. .DESCRIPTION Loads per-repo overrides from .powercraft/release.json. Returns defaults for any unspecified values. If the file doesn't exist, returns all defaults. .PARAMETER Path Repository root directory. .OUTPUTS [PSCustomObject] with ci, release, and disabled properties. #> [CmdletBinding()] [OutputType([PSCustomObject])] param( [Parameter()] [string]$Path = (Get-Location).Path ) $defaults = [PSCustomObject]@{ schema_version = 1 technology = $null # auto-detect if null ci = [PSCustomObject]@{ runner = 'ubuntu-latest' branches = @('main') secrets = $null # auto-detect if null } release = [PSCustomObject]@{ registry = $null # auto-detect from technology } disabled = @() } $configPath = Join-Path $Path '.powercraft' 'release.json' if (-not (Test-Path $configPath)) { Write-Verbose "No .powercraft/release.json found — using defaults" return $defaults } Write-Verbose "Loading config from: $configPath" $config = Get-Content $configPath -Raw | ConvertFrom-Json # Merge config over defaults if ($config.ci) { if ($config.ci.runner) { $defaults.ci.runner = $config.ci.runner } if ($config.ci.branches) { $defaults.ci.branches = @($config.ci.branches) } if ($config.ci.secrets) { $defaults.ci.secrets = $config.ci.secrets } } if ($config.release) { if ($config.release.registry) { $defaults.release.registry = $config.release.registry } } if ($config.disabled) { $defaults.disabled = @($config.disabled) } if ($config.technology) { $defaults.technology = $config.technology } $defaults } |