Thanks to visit codestin.com
Credit goes to github.com

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
2 changes: 1 addition & 1 deletion .github/workflows/macos-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ jobs:
}
Import-Module Pester
$pesterConfig = New-PesterConfiguration
$pesterConfig.Run.Path = './tools/packaging/releaseTests/macOSPackage.tests.ps1'
$pesterConfig.Run.Path = './test/packaging/macos/package-validation.tests.ps1'
$pesterConfig.Run.PassThru = $true
$pesterConfig.Output.Verbosity = 'Detailed'
$pesterConfig.TestResult.Enabled = $true
Expand Down
26 changes: 19 additions & 7 deletions .pipelines/templates/mac-package-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,25 @@ jobs:

Start-PSPackage -Type osxpkg -SkipReleaseChecks -MacOSRuntime $macosRuntime -ReleaseTag $(ReleaseTagVar) -PackageBinPath $signedFilesPath -LTS:$LTS
$pkgNameFilter = "powershell-*$macosRuntime.pkg"
$pkgPath = Get-ChildItem -Path $(Pipeline.Workspace) -Filter $pkgNameFilter -Recurse -File | Select-Object -ExpandProperty FullName
Write-Host "##vso[artifact.upload containerfolder=macos-pkgs;artifactname=macos-pkgs]$pkgPath"
Write-Verbose -Verbose "Looking for pkg packages with filter: $pkgNameFilter in '$(Pipeline.Workspace)' to upload..."
$pkgPath = Get-ChildItem -Path $(Pipeline.Workspace) -Filter $pkgNameFilter -Recurse -File

foreach($p in $pkgPath) {
$file = $p.FullName
Write-Verbose -verbose "Uploading $file to macos-pkgs"
Write-Host "##vso[artifact.upload containerfolder=macos-pkgs;artifactname=macos-pkgs]$file"
}

Start-PSPackage -Type tar -SkipReleaseChecks -MacOSRuntime $macosRuntime -ReleaseTag $(ReleaseTagVar) -PackageBinPath $signedFilesPath -LTS:$LTS
$tarPkgNameFilter = "powershell-*$macosRuntime.tar.gz"
$tarPkgPath = Get-ChildItem -Path $(Pipeline.Workspace) -Filter $tarPkgNameFilter -Recurse -File | Select-Object -ExpandProperty FullName
Write-Host "##vso[artifact.upload containerfolder=macos-pkgs;artifactname=macos-pkgs]$tarPkgPath"
Write-Verbose -Verbose "Looking for tar packages with filter: $tarPkgNameFilter in '$(Pipeline.Workspace)' to upload..."
$tarPkgPath = Get-ChildItem -Path $(Pipeline.Workspace) -Filter $tarPkgNameFilter -Recurse -File

foreach($t in $tarPkgPath) {
$file = $t.FullName
Write-Verbose -verbose "Uploading $file to macos-pkgs"
Write-Host "##vso[artifact.upload containerfolder=macos-pkgs;artifactname=macos-pkgs]$file"
}

displayName: 'Package ${{ parameters.buildArchitecture}}'
env:
Expand Down Expand Up @@ -194,14 +206,14 @@ jobs:

- pwsh: |
$signedPkg = Get-ChildItem -Path $(Pipeline.Workspace) -Filter "*osx*.zip" -File

$signedPkg | ForEach-Object {
Write-Verbose -Verbose "Signed package zip: $_"

if (-not (Test-Path $_)) {
throw "Package not found: $_"
}

if (-not (Test-Path $(ob_outputDirectory))) {
$null = New-Item -Path $(ob_outputDirectory) -ItemType Directory
}
Expand Down
11 changes: 8 additions & 3 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2399,17 +2399,22 @@ function Start-PSBootstrap {
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager install -y rpm-build")) -IgnoreExitcode
}
}

# For Debian-based systems and Mariner, ensure dpkg-deb is available
if ($environment.IsLinux -and ($environment.IsDebianFamily -or $environment.IsMariner)) {
Write-Verbose -Verbose "Checking for dpkg-deb..."
if (!(Get-Command dpkg-deb -ErrorAction SilentlyContinue)) {
Write-Warning "dpkg-deb not found. Installing dpkg package..."
if ($environment.IsMariner) {
# For Mariner (Azure Linux), install the extended repo first to access dpkg.
Write-Verbose -verbose "BEGIN: /etc/os-release content:"
Get-Content /etc/os-release | Write-Verbose -verbose
Write-Verbose -verbose "END: /etc/os-release content"

Write-Verbose -Verbose "Installing azurelinux-repos-extended for Mariner..."
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager azurelinux-repos-extended")) -IgnoreExitcode
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager dpkg")) -IgnoreExitcode

Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager azurelinux-repos-extended")) -IgnoreExitcode -Verbose
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager dpkg")) -IgnoreExitcode -Verbose
} else {
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo apt-get install -y dpkg")) -IgnoreExitcode
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe "Verify macOS Package" {
BeforeAll {
Write-Verbose "In Describe BeforeAll" -Verbose
Import-Module $PSScriptRoot/../../../build.psm1

# Find the macOS package
$packagePath = $env:PACKAGE_FOLDER
if (-not $packagePath) {
$packagePath = Get-Location
}

Write-Verbose "Looking for package in: $packagePath" -Verbose
$package = Get-ChildItem -Path $packagePath -Filter "*.pkg" -ErrorAction SilentlyContinue | Select-Object -First 1

if (-not $package) {
Write-Warning "No .pkg file found in $packagePath"
} else {
Write-Verbose "Found package: $($package.FullName)" -Verbose
}

# Set up test directories
$script:package = $package
$script:expandDir = $null
$script:payloadDir = $null
$script:extractedFiles = @()

if ($package) {
# Use TestDrive for temporary directories - pkgutil will create the expand directory
$script:expandDir = Join-Path "TestDrive:" -ChildPath "package-contents-test"
$expandDirResolved = (Resolve-Path "TestDrive:").ProviderPath
$script:expandDir = Join-Path $expandDirResolved -ChildPath "package-contents-test"

Write-Verbose "Expanding package to: $($script:expandDir)" -Verbose
# pkgutil will create the directory itself, so don't pre-create it
Start-NativeExecution {
pkgutil --expand $package.FullName $script:expandDir
}

# Extract the payload to verify files
$script:payloadDir = Join-Path "TestDrive:" -ChildPath "package-payload-test"
$payloadDirResolved = (Resolve-Path "TestDrive:").ProviderPath
$script:payloadDir = Join-Path $payloadDirResolved -ChildPath "package-payload-test"

# Create payload directory since cpio needs it
if (-not (Test-Path $script:payloadDir)) {
$null = New-Item -ItemType Directory -Path $script:payloadDir -Force
}

$componentPkg = Get-ChildItem -Path $script:expandDir -Filter "*.pkg" -Recurse | Select-Object -First 1
if ($componentPkg) {
Write-Verbose "Extracting payload from: $($componentPkg.FullName)" -Verbose
Expand All @@ -57,18 +60,18 @@ Describe "Verify macOS Package" {
Pop-Location
}
}

# Get all extracted files for verification
$script:extractedFiles = Get-ChildItem -Path $script:payloadDir -Recurse -ErrorAction SilentlyContinue
Write-Verbose "Extracted $($script:extractedFiles.Count) files" -Verbose
}
}

AfterAll {
# TestDrive automatically cleans up, but we can ensure cleanup happens
# No manual cleanup needed as TestDrive handles it
}

Context "Package existence and structure" {
It "Package file should exist" {
$script:package | Should -Not -BeNullOrEmpty -Because "A .pkg file should be created"
Expand All @@ -79,13 +82,12 @@ Describe "Verify macOS Package" {
$script:package | Should -Not -BeNullOrEmpty

# Regex pattern for valid macOS PKG package names.
# This pattern matches the validation used in release-validate-packagenames.yml
# Valid examples:
# - powershell-7.4.13-osx-x64.pkg (Stable release)
# - powershell-7.6.0-preview.6-osx-x64.pkg (Preview version string)
# - powershell-7.4.13-rebuild.5-osx-arm64.pkg (Rebuild version)
# - powershell-lts-7.4.13-osx-arm64.pkg (LTS package)
$pkgPackageNamePattern = '^powershell-(lts-)?\d+\.\d+\.\d+\-([a-z]*.\d+\-)?osx\-(x64|arm64)\.pkg$'
# - powershell-7.4.13-osx-x64.pkg (Intel x64 - note: x64 with hyphens for compatibility)
# - powershell-7.4.13-osx-arm64.pkg (Apple Silicon)
# - powershell-preview-7.6.0-preview.6-osx-x64.pkg
# - powershell-lts-7.4.13-osx-arm64.pkg
$pkgPackageNamePattern = '^powershell(-preview|-lts)?-\d+\.\d+\.\d+(-[a-z]+\.\d+)?-osx-(x64|arm64)\.pkg$'

$script:package.Name | Should -Match $pkgPackageNamePattern -Because "Package name should follow the standard naming convention"
}
Expand All @@ -100,18 +102,18 @@ Describe "Verify macOS Package" {
$script:expandDir | Should -Exist
Get-ChildItem -Path $script:expandDir | Should -Not -BeNullOrEmpty
}

It "Package should have a component package" {
$componentPkg = Get-ChildItem -Path $script:expandDir -Filter "*.pkg" -Recurse -ErrorAction SilentlyContinue
$componentPkg | Should -Not -BeNullOrEmpty -Because "Package should contain a component.pkg"
}

It "Payload should extract successfully" {
$script:payloadDir | Should -Exist
$script:extractedFiles | Should -Not -BeNullOrEmpty -Because "Package payload should contain files"
}
}

Context "Required files in package" {
BeforeAll {
$expectedFilePatterns = @{
Expand All @@ -120,31 +122,31 @@ Describe "Verify macOS Package" {
"Man page" = "usr/local/share/man/man1/pwsh*.gz"
"Launcher application plist" = "Applications/PowerShell*.app/Contents/Info.plist"
}

$testCases = @()
foreach ($key in $expectedFilePatterns.Keys) {
$testCases += @{
Description = $key
Pattern = $expectedFilePatterns[$key]
}
}

$script:testCases = $testCases
}

It "Should contain <Description>" -TestCases $script:testCases {
param($Description, $Pattern)

$found = $script:extractedFiles | Where-Object { $_.FullName -like "*$Pattern*" }
$found | Should -Not -BeNullOrEmpty -Because "$Description should exist in the package at path matching '$Pattern'"
}
}

Context "PowerShell binary verification" {
It "PowerShell executable should be executable" {
$pwshBinary = $script:extractedFiles | Where-Object { $_.FullName -like "*/pwsh" -and $_.FullName -like "*/microsoft/powershell/*" }
$pwshBinary | Should -Not -BeNullOrEmpty

# Check if file has executable permissions (on Unix-like systems)
if ($IsLinux -or $IsMacOS) {
$permissions = (Get-Item $pwshBinary[0].FullName).UnixFileMode
Expand All @@ -153,31 +155,31 @@ Describe "Verify macOS Package" {
}
}
}

Context "Launcher application" {
It "Launcher app should have proper bundle structure" {
$plistFile = $script:extractedFiles | Where-Object { $_.FullName -like "*PowerShell*.app/Contents/Info.plist" }
$plistFile | Should -Not -BeNullOrEmpty

# Verify the bundle has required components
$appPath = Split-Path (Split-Path $plistFile[0].FullName -Parent) -Parent
$macOSDir = Join-Path $appPath "Contents/MacOS"
$resourcesDir = Join-Path $appPath "Contents/Resources"

Test-Path $macOSDir | Should -Be $true -Because "App bundle should have Contents/MacOS directory"
Test-Path $resourcesDir | Should -Be $true -Because "App bundle should have Contents/Resources directory"
}

It "Launcher script should exist and be executable" {
$launcherScript = $script:extractedFiles | Where-Object {
$_.FullName -like "*PowerShell*.app/Contents/MacOS/PowerShell.sh"
$launcherScript = $script:extractedFiles | Where-Object {
$_.FullName -like "*PowerShell*.app/Contents/MacOS/PowerShell.sh"
}
$launcherScript | Should -Not -BeNullOrEmpty -Because "Launcher script should exist"

if ($IsLinux -or $IsMacOS) {
$permissions = (Get-Item $launcherScript[0].FullName).UnixFileMode
$permissions.ToString() | Should -Match 'x' -Because "Launcher script should have execute permissions"
}
}
}
}
}
Loading
Loading