microsoft/hve-core
Publicmirrored fromhttps://github.com/microsoft/hve-coreAvailable
scripts/extension/Find-CollectionManifests.ps1
124lines · modecode
| 1 | #!/usr/bin/env pwsh |
| 2 | # Copyright (c) Microsoft Corporation. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | # Find-CollectionManifests.ps1 |
| 6 | # |
| 7 | # Purpose: Discover and filter collection manifests for extension packaging matrix |
| 8 | # Author: HVE Core Team |
| 9 | |
| 10 | #Requires -Version 7.0 |
| 11 | #Requires -Modules PowerShell-Yaml |
| 12 | |
| 13 | [CmdletBinding()] |
| 14 | param( |
| 15 | [Parameter(Mandatory = $false)] |
| 16 | [string]$Channel = 'Stable', |
| 17 | |
| 18 | [Parameter(Mandatory = $false)] |
| 19 | [string]$CollectionsDir = (Join-Path $PSScriptRoot '../../collections') |
| 20 | ) |
| 21 | |
| 22 | $ErrorActionPreference = 'Stop' |
| 23 | |
| 24 | # Import CI helpers for output writing |
| 25 | Import-Module (Join-Path $PSScriptRoot "../lib/Modules/CIHelpers.psm1") -Force |
| 26 | |
| 27 | #region Functions |
| 28 | |
| 29 | function Find-CollectionManifestsCore { |
| 30 | <# |
| 31 | .SYNOPSIS |
| 32 | Discovers collection manifest files and builds a GitHub Actions matrix. |
| 33 | .DESCRIPTION |
| 34 | Reads *.collection.yml files from the specified directory, parses each with |
| 35 | ConvertFrom-Yaml, and filters by maturity against the release channel. |
| 36 | Deprecated collections are always excluded; experimental collections are |
| 37 | excluded for the Stable channel. |
| 38 | .PARAMETER Channel |
| 39 | Release channel controlling maturity filtering (default: Stable). |
| 40 | .PARAMETER CollectionsDir |
| 41 | Directory containing *.collection.yml manifest files. |
| 42 | #> |
| 43 | [CmdletBinding()] |
| 44 | [OutputType([PSCustomObject])] |
| 45 | param( |
| 46 | [Parameter(Mandatory = $false)] |
| 47 | [string]$Channel = 'Stable', |
| 48 | |
| 49 | [Parameter(Mandatory = $false)] |
| 50 | [string]$CollectionsDir = 'collections' |
| 51 | ) |
| 52 | |
| 53 | $channel = $Channel.Trim() |
| 54 | if (-not $channel) { $channel = 'Stable' } |
| 55 | |
| 56 | $collectionFiles = Get-ChildItem -Path $CollectionsDir -Filter '*.collection.yml' -File -ErrorAction SilentlyContinue | Sort-Object Name |
| 57 | if (-not $collectionFiles -or $collectionFiles.Count -eq 0) { |
| 58 | Write-Warning "No collection manifest files found in $CollectionsDir" |
| 59 | return [PSCustomObject]@{ |
| 60 | MatrixJson = '{"include":[]}' |
| 61 | MatrixItems = @() |
| 62 | Skipped = @() |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | $matrixItems = @() |
| 67 | $skipped = @() |
| 68 | |
| 69 | foreach ($file in $collectionFiles) { |
| 70 | $content = Get-Content -Path $file.FullName -Raw |
| 71 | $manifest = ConvertFrom-Yaml -Yaml $content |
| 72 | |
| 73 | $id = [string]$manifest.id |
| 74 | $name = if ($manifest.ContainsKey('name')) { [string]$manifest.name } else { $id } |
| 75 | $maturity = if ($manifest.ContainsKey('maturity') -and $manifest.maturity) { [string]$manifest.maturity } else { 'stable' } |
| 76 | |
| 77 | # Always skip deprecated |
| 78 | if ($maturity -eq 'deprecated') { |
| 79 | $skipped += [PSCustomObject]@{ Id = $id; Name = $name; Reason = 'deprecated' } |
| 80 | Write-Verbose "Skipping deprecated collection: $name ($id)" |
| 81 | continue |
| 82 | } |
| 83 | |
| 84 | # Skip experimental for Stable channel |
| 85 | if ($maturity -eq 'experimental' -and $channel -eq 'Stable') { |
| 86 | $skipped += [PSCustomObject]@{ Id = $id; Name = $name; Reason = 'experimental (Stable channel)' } |
| 87 | Write-Verbose "Skipping experimental collection for Stable channel: $name ($id)" |
| 88 | continue |
| 89 | } |
| 90 | |
| 91 | $matrixItems += @{ |
| 92 | id = $id |
| 93 | name = $name |
| 94 | manifest = $file.FullName -replace '\\', '/' |
| 95 | maturity = $maturity |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | $matrixJson = @{ include = $matrixItems } | ConvertTo-Json -Depth 5 -Compress |
| 100 | |
| 101 | return [PSCustomObject]@{ |
| 102 | MatrixJson = $matrixJson |
| 103 | MatrixItems = $matrixItems |
| 104 | Skipped = $skipped |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | #endregion |
| 109 | |
| 110 | # Script guard: only execute CI output when run directly, not when dot-sourced |
| 111 | if ($MyInvocation.InvocationName -ne '.') { |
| 112 | $result = Find-CollectionManifestsCore -Channel $Channel -CollectionsDir $CollectionsDir |
| 113 | |
| 114 | # Report skipped collections |
| 115 | foreach ($skip in $result.Skipped) { |
| 116 | Write-CIAnnotation -Message "Skipping $($skip.Name) ($($skip.Id)): $($skip.Reason)" -Level Notice |
| 117 | } |
| 118 | |
| 119 | Write-Host "Discovered collections:" |
| 120 | $result.MatrixJson | ConvertFrom-Json | ConvertTo-Json -Depth 5 |
| 121 | |
| 122 | # Write CI output using injection-safe helpers |
| 123 | Set-CIOutput -Name 'matrix' -Value $result.MatrixJson |
| 124 | } |
| 125 | |