[release/v7.5] Fix macOS preview package identifier detection to use version string by daxian-dbw · Pull Request #26835 · PowerShell/PowerShell · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions test/packaging/packaging.tests.ps1
69 changes: 52 additions & 17 deletions tools/packaging/packaging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,7 @@ function New-UnixPackage {
AppsFolder = $AppsFolder
HostArchitecture = $HostArchitecture
CurrentLocation = $CurrentLocation
LTS = $LTS
}

try {
Expand Down Expand Up @@ -1503,7 +1504,12 @@ function New-MacOsDistributionPackage

# Get package ID if not provided
if (-not $PackageIdentifier) {
$PackageIdentifier = Get-MacOSPackageId -IsPreview:$IsPreview.IsPresent
if ($IsPreview.IsPresent) {
$PackageIdentifier = 'com.microsoft.powershell-preview'
}
else {
$PackageIdentifier = 'com.microsoft.powershell'
}
Comment on lines +1507 to +1512
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New-MacOsDistributionPackage now hardcodes com.microsoft.powershell(-preview) even though the same identifiers are also produced by Get-MacOSPackageIdentifierInfo below. This duplicates the source of truth for identifiers and risks future drift. Consider reusing the shared helper (or a shared constant) when $PackageIdentifier is not provided, so the identifier mapping is centralized in one place.

Suggested change

Copilot uses AI. Check for mistakes.
}

# Minimum OS version
Expand Down Expand Up @@ -1972,7 +1978,9 @@ function New-MacOSPackage
[Parameter(Mandatory)]
[string]$HostArchitecture,

[string]$CurrentLocation = (Get-Location)
[string]$CurrentLocation = (Get-Location),

[switch]$LTS
)

Write-Log "Creating macOS package using pkgbuild and productbuild..."
Expand Down Expand Up @@ -2047,8 +2055,10 @@ function New-MacOSPackage
Copy-Item -Path "$AppsFolder/*" -Destination $appsInPkg -Recurse -Force
}

# Build the component package using pkgbuild
$pkgIdentifier = Get-MacOSPackageId -IsPreview:($Name -like '*-preview')
# Get package identifier info based on version and LTS flag
$packageInfo = Get-MacOSPackageIdentifierInfo -Version $Version -LTS:$LTS
$IsPreview = $packageInfo.IsPreview
$pkgIdentifier = $packageInfo.PackageIdentifier
Comment on lines +2058 to +2061
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description says preview macOS packages will install to /usr/local/microsoft/powershell/7-preview/, but this change only fixes the package identifier determination. The install location is determined earlier by New-UnixPackage via $Suffix/$Destination (which depends on $IsPreview), and New-UnixPackage does not currently compute $IsPreview from the version string (so it stays $null/false and yields the stable 7/ suffix). To fully fix issue #26673, compute $IsPreview in New-UnixPackage using Test-IsPreview -Version $Version -IsLTS:$LTS and use that value consistently for $Suffix/$Destination (and for macOS launcher generation as needed).

Copilot uses AI. Check for mistakes.

if ($PSCmdlet.ShouldProcess("Build component package with pkgbuild")) {
Write-Log "Running pkgbuild to create component package..."
Expand All @@ -2073,7 +2083,7 @@ function New-MacOSPackage
-OutputDirectory $CurrentLocation `
-HostArchitecture $HostArchitecture `
-PackageIdentifier $pkgIdentifier `
-IsPreview:($Name -like '*-preview')
-IsPreview:$IsPreview

return $distributionPackage
}
Expand Down Expand Up @@ -2275,20 +2285,44 @@ function New-ManGzip
}
}

# Returns the macOS Package Identifier
function Get-MacOSPackageId
<#
.SYNOPSIS
Determines the package identifier and preview status for macOS packages.
.DESCRIPTION
This function determines if a package is a preview build based on the version string
and LTS flag, then returns the appropriate package identifier.
.PARAMETER Version
The version string (e.g., "7.6.0-preview.6" or "7.6.0")
.PARAMETER LTS
Whether this is an LTS build
.OUTPUTS
Hashtable with IsPreview (boolean) and PackageIdentifier (string) properties
.EXAMPLE
Get-MacOSPackageIdentifierInfo -Version "7.6.0-preview.6" -LTS:$false
Returns @{ IsPreview = $true; PackageIdentifier = "com.microsoft.powershell-preview" }
#>
function Get-MacOSPackageIdentifierInfo
{
param(
[switch]
$IsPreview
[Parameter(Mandatory)]
[string]$Version,

[switch]$LTS
)
if ($IsPreview.IsPresent)
{
return 'com.microsoft.powershell-preview'

$IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS

# Determine package identifier based on preview status
if ($IsPreview) {
$PackageIdentifier = 'com.microsoft.powershell-preview'
}
else
{
return 'com.microsoft.powershell'
else {
$PackageIdentifier = 'com.microsoft.powershell'
}

return @{
IsPreview = $IsPreview
PackageIdentifier = $PackageIdentifier
}
}

Expand All @@ -2302,8 +2336,9 @@ function New-MacOSLauncher
[switch]$LTS
)

$IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS
$packageId = Get-MacOSPackageId -IsPreview:$IsPreview
$packageInfo = Get-MacOSPackageIdentifierInfo -Version $Version -LTS:$LTS
$IsPreview = $packageInfo.IsPreview
$packageId = $packageInfo.PackageIdentifier

# Define folder for launcher application.
$suffix = if ($IsPreview) { "-preview" } elseif ($LTS) { "-lts" }
Expand Down
Loading