microsoft/hve-core
Publicmirrored fromhttps://github.com/microsoft/hve-coreAvailable
.github/workflows/extension-package.yml
199lines · modecode
| 1 | name: Package Extension |
| 2 | |
| 3 | on: |
| 4 | workflow_call: |
| 5 | inputs: |
| 6 | version: |
| 7 | description: "Full version to use (e.g., 1.0.0 or empty to use package.json)" |
| 8 | required: false |
| 9 | type: string |
| 10 | default: "" |
| 11 | dev-patch-number: |
| 12 | description: "Dev patch number to append (creates version like 1.0.0-dev.123)" |
| 13 | required: false |
| 14 | type: string |
| 15 | default: "" |
| 16 | use-changelog: |
| 17 | description: "Whether to download and use changelog artifact" |
| 18 | required: false |
| 19 | type: boolean |
| 20 | default: false |
| 21 | channel: |
| 22 | description: "Release channel (Stable or PreRelease) controlling agent maturity filtering" |
| 23 | required: false |
| 24 | type: string |
| 25 | default: "Stable" |
| 26 | outputs: |
| 27 | version: |
| 28 | description: "Version that was packaged" |
| 29 | value: ${{ jobs.discover-collections.outputs.version }} |
| 30 | collections-matrix: |
| 31 | description: "JSON matrix of collections that were actually packaged (filtered by channel and maturity)" |
| 32 | value: ${{ jobs.discover-collections.outputs.matrix }} |
| 33 | |
| 34 | permissions: |
| 35 | contents: read |
| 36 | |
| 37 | jobs: |
| 38 | discover-collections: |
| 39 | name: Discover Collection Manifests |
| 40 | runs-on: ubuntu-latest |
| 41 | permissions: |
| 42 | contents: read |
| 43 | outputs: |
| 44 | matrix: ${{ steps.discover.outputs.matrix }} |
| 45 | version: ${{ steps.read-version.outputs.version }} |
| 46 | steps: |
| 47 | - name: Checkout code |
| 48 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2 |
| 49 | with: |
| 50 | persist-credentials: false |
| 51 | |
| 52 | - name: Setup PowerShell modules |
| 53 | shell: pwsh |
| 54 | run: | |
| 55 | Install-Module -Name PowerShell-Yaml -Force -Scope CurrentUser |
| 56 | |
| 57 | - name: Resolve effective version |
| 58 | id: read-version |
| 59 | shell: bash |
| 60 | run: | |
| 61 | version="${{ inputs.version }}" |
| 62 | dev_patch="${{ inputs.dev-patch-number }}" |
| 63 | if [ -z "$version" ]; then |
| 64 | version=$(jq -r .version extension/templates/package.template.json) |
| 65 | fi |
| 66 | if [ -n "$dev_patch" ]; then |
| 67 | version="${version}-dev.${dev_patch}" |
| 68 | fi |
| 69 | echo "version=$version" >> "$GITHUB_OUTPUT" |
| 70 | |
| 71 | - name: Discover collection manifests |
| 72 | id: discover |
| 73 | shell: pwsh |
| 74 | run: | |
| 75 | Import-Module PowerShell-Yaml -ErrorAction Stop |
| 76 | |
| 77 | $collectionsDir = 'collections' |
| 78 | $channel = '${{ inputs.channel }}'.Trim() |
| 79 | if (-not $channel) { $channel = 'Stable' } |
| 80 | |
| 81 | if (-not (Test-Path $collectionsDir)) { |
| 82 | Write-Error "Collections directory not found: $collectionsDir" |
| 83 | exit 1 |
| 84 | } |
| 85 | |
| 86 | $collectionFiles = Get-ChildItem -Path $collectionsDir -Filter '*.collection.yml' -File | Sort-Object Name |
| 87 | $matrixItems = @() |
| 88 | |
| 89 | foreach ($file in $collectionFiles) { |
| 90 | $manifest = ConvertFrom-Yaml -Yaml (Get-Content -Path $file.FullName -Raw) |
| 91 | $id = [string]$manifest.id |
| 92 | $name = if ($manifest.ContainsKey('name')) { [string]$manifest.name } else { $id } |
| 93 | $maturity = if ($manifest.ContainsKey('maturity') -and $manifest.maturity) { [string]$manifest.maturity } else { 'stable' } |
| 94 | |
| 95 | if ($maturity -eq 'deprecated') { |
| 96 | Write-Host "::notice::Skipping deprecated collection: $id" |
| 97 | continue |
| 98 | } |
| 99 | |
| 100 | if ($channel -eq 'Stable' -and $maturity -eq 'experimental') { |
| 101 | Write-Host "::notice::Skipping experimental collection '$id' for Stable channel" |
| 102 | continue |
| 103 | } |
| 104 | |
| 105 | $matrixItems += @{ |
| 106 | id = $id |
| 107 | name = $name |
| 108 | manifest = $file.FullName -replace '\\', '/' |
| 109 | maturity = $maturity |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | $matrixJson = @{ include = $matrixItems } | ConvertTo-Json -Depth 5 -Compress |
| 114 | "matrix=$matrixJson" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 |
| 115 | Write-Host "Discovered collections:" |
| 116 | $matrixJson | ConvertFrom-Json | ConvertTo-Json -Depth 5 |
| 117 | |
| 118 | package: |
| 119 | name: Package ${{ matrix.id }} |
| 120 | needs: discover-collections |
| 121 | runs-on: ubuntu-latest |
| 122 | permissions: |
| 123 | contents: read |
| 124 | strategy: |
| 125 | fail-fast: false |
| 126 | matrix: ${{ fromJson(needs.discover-collections.outputs.matrix) }} |
| 127 | steps: |
| 128 | - name: Checkout code |
| 129 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2 |
| 130 | with: |
| 131 | persist-credentials: false |
| 132 | |
| 133 | - name: Setup Node.js |
| 134 | uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v4.1.0 |
| 135 | with: |
| 136 | node-version: "20" |
| 137 | |
| 138 | - name: Install dependencies |
| 139 | run: npm install -g @vscode/vsce@3.7.1 |
| 140 | |
| 141 | - name: Setup PowerShell |
| 142 | shell: pwsh |
| 143 | run: | |
| 144 | Write-Host "PowerShell version: $($PSVersionTable.PSVersion)" |
| 145 | Install-Module -Name PowerShell-Yaml -Force -Scope CurrentUser |
| 146 | |
| 147 | - name: Download changelog artifact |
| 148 | if: inputs.use-changelog |
| 149 | uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 |
| 150 | with: |
| 151 | name: changelog |
| 152 | path: ./ |
| 153 | continue-on-error: true |
| 154 | |
| 155 | - name: Prepare extension resources |
| 156 | id: prepare |
| 157 | shell: pwsh |
| 158 | run: | |
| 159 | $channel = "${{ inputs.channel }}".Trim() |
| 160 | if (-not $channel) { $channel = 'Stable' } |
| 161 | $collection = "${{ matrix.manifest }}" |
| 162 | |
| 163 | Write-Host "🔧 Preparing extension for $channel channel (collection: ${{ matrix.id }})..." |
| 164 | ./scripts/extension/Prepare-Extension.ps1 -Channel $channel -Collection $collection |
| 165 | |
| 166 | - name: Package extension |
| 167 | id: package |
| 168 | shell: pwsh |
| 169 | run: | |
| 170 | $version = "${{ inputs.version }}".Trim() |
| 171 | $devPatch = "${{ inputs.dev-patch-number }}".Trim() |
| 172 | $collection = "${{ matrix.manifest }}" |
| 173 | |
| 174 | Write-Host "📦 Packaging extension (collection: ${{ matrix.id }})..." |
| 175 | |
| 176 | $arguments = @{ |
| 177 | Collection = $collection |
| 178 | } |
| 179 | |
| 180 | if ($version) { |
| 181 | $arguments['Version'] = $version |
| 182 | } |
| 183 | |
| 184 | if ($devPatch) { |
| 185 | $arguments['DevPatchNumber'] = $devPatch |
| 186 | } |
| 187 | |
| 188 | if (Test-Path "./CHANGELOG.md") { |
| 189 | $arguments['ChangelogPath'] = "./CHANGELOG.md" |
| 190 | } |
| 191 | |
| 192 | ./scripts/extension/Package-Extension.ps1 @arguments |
| 193 | |
| 194 | - name: Upload VSIX artifact |
| 195 | uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v4.4.3 |
| 196 | with: |
| 197 | name: extension-vsix-${{ matrix.id }} |
| 198 | path: extension/*.vsix |
| 199 | retention-days: 30 |
| 200 | |