microsoft/hve-core

Public

mirrored fromhttps://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
feat/pr-review-slash-command

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

scripts/extension/Find-CollectionManifests.ps1

131lines · 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 @{ ModuleName='PowerShell-Yaml'; RequiredVersion='0.4.7' }
12
13[CmdletBinding()]
14param(
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
25Import-Module (Join-Path $PSScriptRoot "../lib/Modules/CIHelpers.psm1") -Force
26
27#region Functions
28
29function 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 removed
78 if ($maturity -eq 'removed') {
79 $skipped += [PSCustomObject]@{ Id = $id; Name = $name; Reason = 'removed' }
80 Write-Verbose "Skipping removed collection: $name ($id)"
81 continue
82 }
83
84 # Always skip deprecated
85 if ($maturity -eq 'deprecated') {
86 $skipped += [PSCustomObject]@{ Id = $id; Name = $name; Reason = 'deprecated' }
87 Write-Verbose "Skipping deprecated collection: $name ($id)"
88 continue
89 }
90
91 # Skip experimental for Stable channel
92 if ($maturity -eq 'experimental' -and $channel -eq 'Stable') {
93 $skipped += [PSCustomObject]@{ Id = $id; Name = $name; Reason = 'experimental (Stable channel)' }
94 Write-Verbose "Skipping experimental collection for Stable channel: $name ($id)"
95 continue
96 }
97
98 $matrixItems += @{
99 id = $id
100 name = $name
101 manifest = $file.FullName -replace '\\', '/'
102 maturity = $maturity
103 }
104 }
105
106 $matrixJson = @{ include = $matrixItems } | ConvertTo-Json -Depth 5 -Compress
107
108 return [PSCustomObject]@{
109 MatrixJson = $matrixJson
110 MatrixItems = $matrixItems
111 Skipped = $skipped
112 }
113}
114
115#endregion
116
117# Script guard: only execute CI output when run directly, not when dot-sourced
118if ($MyInvocation.InvocationName -ne '.') {
119 $result = Find-CollectionManifestsCore -Channel $Channel -CollectionsDir $CollectionsDir
120
121 # Report skipped collections
122 foreach ($skip in $result.Skipped) {
123 Write-CIAnnotation -Message "Skipping $($skip.Name) ($($skip.Id)): $($skip.Reason)" -Level Notice
124 }
125
126 Write-Host "Discovered collections:"
127 $result.MatrixJson | ConvertFrom-Json | ConvertTo-Json -Depth 5
128
129 # Write CI output using injection-safe helpers
130 Set-CIOutput -Name 'matrix' -Value $result.MatrixJson
131}
132