@@ -155,28 +155,50 @@ jobs:
155155 $ErrorActionPreference = 'Stop'
156156
157157 $version = "${{ steps.set_version.outputs.version }}"
158- $outDir = "$env:GITHUB_WORKSPACE\Installer\Builds"
158+ $root = $env:GITHUB_WORKSPACE
159+ $outDir = Join-Path $root 'Installer\Builds'
159160 New-Item -ItemType Directory -Force -Path $outDir | Out-Null
160161
161- # Find the built MSI in the output directory
162- $msis = Get-ChildItem -Path $outDir -Filter *.msi -File -ErrorAction SilentlyContinue
163- if (-not $msis -or $msis.Count -eq 0) {
164- $listing = (Get-ChildItem -Force $outDir | Select-Object Name,Length,LastWriteTime | Format-Table | Out-String)
165- throw "No MSI found in $outDir. Current contents:`n$listing"
162+ # Look for the latest MSI in common WiX output locations
163+ $searchRoots = @(
164+ (Join-Path $root 'Installer\Builds'),
165+ (Join-Path $root 'Installer\bin'),
166+ (Join-Path $root 'Installer') # fallback
167+ ) | Get-Unique
168+
169+ $candidates = @()
170+ foreach ($dir in $searchRoots) {
171+ if (Test-Path $dir) {
172+ $candidates += Get-ChildItem -Path $dir -Filter *.msi -File -Recurse -ErrorAction SilentlyContinue
173+ }
166174 }
167- if ($msis.Count -gt 1) {
168- Write-Warning "Multiple MSIs found in $outDir. Using the first one: $($msis[0].Name)"
175+
176+ if (-not $candidates -or $candidates.Count -eq 0) {
177+ throw "No MSI found under: `n - $($searchRoots -join "`n - ")"
169178 }
170179
171- $msi = $msis[0]
180+ # Pick the most recently written MSI
181+ $msi = $candidates | Sort-Object LastWriteTimeUtc -Descending | Select-Object -First 1
182+
172183 $target = Join-Path $outDir "dmdext-v$version-${{ matrix.platform }}.msi"
173184
174- if (Test-Path $target) { Remove-Item $target -Force }
185+ if ($msi.FullName -ieq $target) {
186+ Write-Host "MSI already has the correct name: $target"
187+ exit 0
188+ }
189+
190+ # Copy to the target name (more reliable on hosted runners), then remove the original
191+ Copy-Item -Path $msi.FullName -Destination $target -Force
192+ if (-not (Test-Path $target)) {
193+ throw "Failed to create target MSI at: $target"
194+ }
175195
176- # Use Move-Item with a full destination path (more reliable than Rename-Item + -NewName)
177- Move-Item -Path $msi.FullName -Destination $target
178- Write-Host "MSI renamed to: $target"
196+ # Clean up the original if it lives elsewhere
197+ if ($msi.FullName -ne $target) {
198+ Remove-Item -Path $msi.FullName -Force
199+ }
179200
201+ Write-Host "MSI placed at: $target"
180202
181203 # Upload the already-zipped bundle WITHOUT re-compressing
182204 - name : Upload ZIP artifact
0 commit comments