Skip to content

Commit 7e03559

Browse files
Copilotdaxian-dbw
andcommitted
Address review feedback: use PowerShell commands directly, add dpkg for Mariner, and add DEB tests
Co-authored-by: daxian-dbw <127450+daxian-dbw@users.noreply.github.com>
1 parent c2f21df commit 7e03559

3 files changed

Lines changed: 55 additions & 11 deletions

File tree

build.psm1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,12 +2425,16 @@ function Start-PSBootstrap {
24252425
}
24262426
}
24272427

2428-
# For Debian-based systems, ensure dpkg-deb is available (usually pre-installed)
2429-
if ($environment.IsLinux -and $environment.IsDebianFamily) {
2428+
# For Debian-based systems and Mariner, ensure dpkg-deb is available
2429+
if ($environment.IsLinux -and ($environment.IsDebianFamily -or $environment.IsMariner)) {
24302430
Write-Verbose -Verbose "Checking for dpkg-deb..."
24312431
if (!(Get-Command dpkg-deb -ErrorAction SilentlyContinue)) {
24322432
Write-Warning "dpkg-deb not found. Installing dpkg package..."
2433-
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo apt-get install -y dpkg")) -IgnoreExitcode
2433+
if ($environment.IsMariner) {
2434+
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager install -y dpkg")) -IgnoreExitcode
2435+
} else {
2436+
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo apt-get install -y dpkg")) -IgnoreExitcode
2437+
}
24342438
}
24352439
}
24362440
}

test/packaging/linux/package-validation.tests.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,43 @@ Describe "Linux Package Name Validation" {
5454
}
5555
}
5656

57+
Context "DEB Package Names" {
58+
It "Should have valid DEB package names" {
59+
$debPackages = Get-ChildItem -Path $artifactsDir -Recurse -Filter *.deb -ErrorAction SilentlyContinue
60+
61+
if ($debPackages.Count -eq 0) {
62+
Set-ItResult -Skipped -Because "No DEB packages found in artifacts directory"
63+
return
64+
}
65+
66+
$invalidPackages = @()
67+
# Regex pattern for valid DEB package names.
68+
# Breakdown:
69+
# ^powershell : Starts with 'powershell'
70+
# (-preview|-lts)? : Optionally '-preview' or '-lts'
71+
# _\d+\.\d+\.\d+ : Underscore followed by version number (e.g., _7.6.0)
72+
# (-[a-z]*\.\d+)? : Optional dash, letters, dot, and digits (e.g., -preview.6)
73+
# -1\. : Literal '-1.'
74+
# (preview\.\d+\.)? : Optional 'preview.' and digits, followed by a dot
75+
# deb\. : Literal 'deb.'
76+
# (amd64|arm64)\.deb$ : Architecture and file extension
77+
$debPackageNamePattern = '^powershell(-preview|-lts)?_\d+\.\d+\.\d+(-[a-z]*\.\d+)?-1\.(preview\.\d+\.)?deb\.(amd64|arm64)\.deb$'
78+
79+
foreach ($package in $debPackages) {
80+
if ($package.Name -notmatch $debPackageNamePattern) {
81+
$invalidPackages += "$($package.Name) is not a valid DEB package name"
82+
Write-Warning "$($package.Name) is not a valid DEB package name"
83+
}
84+
}
85+
86+
if ($invalidPackages.Count -gt 0) {
87+
throw ($invalidPackages | Out-String)
88+
}
89+
90+
$debPackages.Count | Should -BeGreaterThan 0
91+
}
92+
}
93+
5794
Context "Tar.Gz Package Names" {
5895
It "Should have valid tar.gz package names" {
5996
$tarPackages = Get-ChildItem -Path $artifactsDir -Recurse -Filter *.tar.gz -ErrorAction SilentlyContinue

tools/packaging/packaging.psm1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,8 +1845,8 @@ Description: $Description
18451845
# Copy the temporary symlink file that was created by New-LinkInfo
18461846
# The Source contains a temporary symlink that points to the correct target
18471847
if (Test-Path $link.Source) {
1848-
# Use bash cp to preserve the symlink
1849-
bash -c "cp -P '$($link.Source)' '$linkPath'"
1848+
# Use cp to preserve the symlink
1849+
cp -P $link.Source $linkPath
18501850
Write-Verbose "Copied symlink: $linkPath (from $($link.Source))" -Verbose
18511851
} else {
18521852
Write-Warning "Symlink source not found: $($link.Source)"
@@ -1855,10 +1855,13 @@ Description: $Description
18551855

18561856
# Set proper permissions
18571857
Write-Verbose "Setting file permissions..." -Verbose
1858-
bash -c "find '$dataDir' -type d -exec chmod 755 '{}' \;"
1859-
bash -c "find '$dataDir' -type f -exec chmod 644 '{}' \;"
1858+
# 755 = rwxr-xr-x (owner can read/write/execute, group and others can read/execute)
1859+
Get-ChildItem $dataDir -Directory -Recurse | ForEach-Object { chmod 755 $_.FullName }
1860+
# 644 = rw-r--r-- (owner can read/write, group and others can read only)
1861+
Get-ChildItem $dataDir -File -Recurse | ForEach-Object { chmod 644 $_.FullName }
18601862

18611863
# Set executable permission for pwsh if it exists
1864+
# 755 = rwxr-xr-x (executable permission)
18621865
$pwshPath = "$targetPath/pwsh"
18631866
if (Test-Path $pwshPath) {
18641867
chmod 755 "$pwshPath"
@@ -1885,12 +1888,12 @@ Description: $Description
18851888
$buildDir = Join-Path $debBuildRoot "build"
18861889
New-Item -ItemType Directory -Path $buildDir -Force | Out-Null
18871890

1888-
# Use bash cp to preserve symlinks
1889-
bash -c "cp -a '$debianDir' '$buildDir/DEBIAN'"
1890-
bash -c "cp -a '$dataDir'/* '$buildDir/'"
1891+
# Use cp to preserve symlinks
1892+
cp -a $debianDir "$buildDir/DEBIAN"
1893+
cp -a "$dataDir/*" "$buildDir/"
18911894

18921895
# Build package with dpkg-deb
1893-
$dpkgOutput = bash -c "dpkg-deb --build '$buildDir' '$debFilePath' 2>&1"
1896+
$dpkgOutput = dpkg-deb --build $buildDir $debFilePath 2>&1
18941897
$exitCode = $LASTEXITCODE
18951898

18961899
if ($exitCode -ne 0) {

0 commit comments

Comments
 (0)