/ .pipelines / generateDscManifests.ps1
generateDscManifests.ps1
1 [CmdletBinding()] 2 param( 3 [Parameter(Mandatory = $true)] 4 [string]$BuildPlatform, 5 6 [Parameter(Mandatory = $true)] 7 [string]$BuildConfiguration, 8 9 [Parameter()] 10 [string]$RepoRoot = (Get-Location).Path 11 ) 12 13 $ErrorActionPreference = 'Stop' 14 15 function Resolve-PlatformDirectory { 16 param( 17 [string]$Root, 18 [string]$Platform 19 ) 20 21 $normalized = $Platform.Trim() 22 $candidates = @() 23 $candidates += Join-Path $Root $normalized 24 $candidates += Join-Path $Root ($normalized.ToUpperInvariant()) 25 $candidates += Join-Path $Root ($normalized.ToLowerInvariant()) 26 $candidates = $candidates | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique 27 28 foreach ($candidate in $candidates) { 29 if (Test-Path $candidate) { 30 return $candidate 31 } 32 } 33 34 return $candidates[0] 35 } 36 37 Write-Host "Repo root: $RepoRoot" 38 Write-Host "Requested build platform: $BuildPlatform" 39 Write-Host "Requested configuration: $BuildConfiguration" 40 41 # Always use x64 PowerToys.DSC.exe since CI/CD machines are x64 42 $exePlatform = 'x64' 43 $exeRoot = Resolve-PlatformDirectory -Root $RepoRoot -Platform $exePlatform 44 $exeOutputDir = Join-Path $exeRoot $BuildConfiguration 45 $exePath = Join-Path $exeOutputDir 'PowerToys.DSC.exe' 46 47 Write-Host "Using x64 PowerToys.DSC.exe to generate DSC manifests for $BuildPlatform build" 48 49 if (-not (Test-Path $exePath)) { 50 throw "PowerToys.DSC.exe not found at '$exePath'. Make sure it has been built first." 51 } 52 53 Write-Host "Using PowerToys.DSC.exe at '$exePath'." 54 55 # Output DSC manifests to the target build platform directory (x64, ARM64, etc.) 56 $outputRoot = Resolve-PlatformDirectory -Root $RepoRoot -Platform $BuildPlatform 57 if (-not (Test-Path $outputRoot)) { 58 Write-Host "Creating missing platform output root at '$outputRoot'." 59 New-Item -Path $outputRoot -ItemType Directory -Force | Out-Null 60 } 61 62 $outputDir = Join-Path $outputRoot $BuildConfiguration 63 if (-not (Test-Path $outputDir)) { 64 Write-Host "Creating missing configuration output directory at '$outputDir'." 65 New-Item -Path $outputDir -ItemType Directory -Force | Out-Null 66 } 67 68 # DSC v3 manifests go to DSCModules subfolder 69 $dscOutputDir = Join-Path $outputDir 'DSCModules' 70 if (-not (Test-Path $dscOutputDir)) { 71 Write-Host "Creating DSCModules subfolder at '$dscOutputDir'." 72 New-Item -Path $dscOutputDir -ItemType Directory -Force | Out-Null 73 } 74 75 Write-Host "DSC manifests will be generated to: '$dscOutputDir'" 76 77 Write-Host "Cleaning previously generated DSC manifest files from '$dscOutputDir'." 78 Get-ChildItem -Path $dscOutputDir -Filter 'microsoft.powertoys.*.settings.dsc.resource.json' -ErrorAction SilentlyContinue | Remove-Item -Force 79 80 $arguments = @('manifest', '--resource', 'settings', '--outputDir', $dscOutputDir) 81 Write-Host "Invoking DSC manifest generator: '$exePath' $($arguments -join ' ')" 82 & $exePath @arguments 83 if ($LASTEXITCODE -ne 0) { 84 throw "PowerToys.DSC.exe exited with code $LASTEXITCODE" 85 } 86 87 $generatedFiles = Get-ChildItem -Path $dscOutputDir -Filter 'microsoft.powertoys.*.settings.dsc.resource.json' -ErrorAction Stop 88 if ($generatedFiles.Count -eq 0) { 89 throw "No DSC manifest files were generated in '$dscOutputDir'." 90 } 91 92 Write-Host "Generated $($generatedFiles.Count) DSC manifest file(s):" 93 foreach ($file in $generatedFiles) { 94 Write-Host " - $($file.FullName)" 95 }