Skip to content

Commit 7e1ef1f

Browse files
authored
Replace fpm with dpkg-deb for DEB package generation (PowerShell#26281)
1 parent 47e8e90 commit 7e1ef1f

File tree

3 files changed

+315
-271
lines changed

3 files changed

+315
-271
lines changed

build.psm1

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,43 +2234,6 @@ function Get-RedHatPackageManager {
22342234
}
22352235
}
22362236

2237-
function Install-GlobalGem {
2238-
param(
2239-
[Parameter()]
2240-
[string]
2241-
$Sudo = "",
2242-
2243-
[Parameter(Mandatory)]
2244-
[string]
2245-
$GemName,
2246-
2247-
[Parameter(Mandatory)]
2248-
[string]
2249-
$GemVersion
2250-
)
2251-
try {
2252-
# We cannot guess if the user wants to run gem install as root on linux and windows,
2253-
# but macOs usually requires sudo
2254-
$gemsudo = ''
2255-
if($environment.IsMacOS -or $env:TF_BUILD -or $env:GITHUB_ACTIONS) {
2256-
$gemsudo = $sudo
2257-
}
2258-
2259-
Start-NativeExecution ([ScriptBlock]::Create("$gemsudo gem install $GemName -v $GemVersion --no-document"))
2260-
2261-
} catch {
2262-
Write-Warning "Installation of gem $GemName $GemVersion failed! Must resolve manually."
2263-
$logs = Get-ChildItem "/var/lib/gems/*/extensions/x86_64-linux/*/$GemName-*/gem_make.out" | Select-Object -ExpandProperty FullName
2264-
foreach ($log in $logs) {
2265-
Write-Verbose "Contents of: $log" -Verbose
2266-
Get-Content -Raw -Path $log -ErrorAction Ignore | ForEach-Object { Write-Verbose $_ -Verbose }
2267-
Write-Verbose "END Contents of: $log" -Verbose
2268-
}
2269-
2270-
throw
2271-
}
2272-
}
2273-
22742237
function Start-PSBootstrap {
22752238
[CmdletBinding()]
22762239
param(
@@ -2282,7 +2245,7 @@ function Start-PSBootstrap {
22822245
[switch]$BuildLinuxArm,
22832246
[switch]$Force,
22842247
[Parameter(Mandatory = $true)]
2285-
# Package: Install dependencies for packaging tools (fpm, rpmbuild, WiX)
2248+
# Package: Install dependencies for packaging tools (rpmbuild, dpkg-deb, pkgbuild, WiX)
22862249
# DotNet: Install the .NET SDK
22872250
# Both: Package and DotNet scenarios
22882251
# Tools: Install .NET global tools (e.g., dotnet-format)
@@ -2321,7 +2284,9 @@ function Start-PSBootstrap {
23212284
elseif ($environment.IsUbuntu18) { $Deps += "libicu60"}
23222285

23232286
# Packaging tools
2324-
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "ruby-dev", "groff", "libffi-dev", "rpm", "g++", "make" }
2287+
# Note: ruby-dev, libffi-dev, g++, and make are no longer needed for DEB packaging
2288+
# DEB packages now use native dpkg-deb (pre-installed)
2289+
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "groff", "rpm" }
23252290

23262291
# Install dependencies
23272292
# change the fontend from apt-get to noninteractive
@@ -2345,7 +2310,9 @@ function Start-PSBootstrap {
23452310
$Deps += "libicu", "openssl-libs"
23462311

23472312
# Packaging tools
2348-
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "ruby-devel", "rpm-build", "groff", 'libffi-devel', "gcc-c++" }
2313+
# Note: ruby-devel and libffi-devel are no longer needed
2314+
# RPM packages use rpmbuild, DEB packages use dpkg-deb
2315+
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "rpm-build", "groff" }
23492316

23502317
$PackageManager = Get-RedHatPackageManager
23512318

@@ -2366,7 +2333,8 @@ function Start-PSBootstrap {
23662333
$Deps += "wget"
23672334

23682335
# Packaging tools
2369-
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "ruby-devel", "rpmbuild", "groff", 'libffi-devel', "gcc" }
2336+
# Note: ruby-devel and libffi-devel are no longer needed for packaging
2337+
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "rpmbuild", "groff" }
23702338

23712339
$PackageManager = "zypper --non-interactive install"
23722340
$baseCommand = "$sudo $PackageManager"
@@ -2405,17 +2373,7 @@ function Start-PSBootstrap {
24052373
}
24062374
}
24072375

2408-
# Install [fpm](https://github.com/jordansissel/fpm)
2409-
# Note: fpm is now only needed for DEB and macOS packages; RPM packages use rpmbuild directly
24102376
if ($Scenario -in 'All', 'Both', 'Package') {
2411-
# Install fpm on Debian-based systems, macOS, and Mariner (where DEB packages are built)
2412-
if (($environment.IsLinux -and ($environment.IsDebianFamily -or $environment.IsMariner)) -or $environment.IsMacOS) {
2413-
Install-GlobalGem -Sudo $sudo -GemName "dotenv" -GemVersion "2.8.1"
2414-
Install-GlobalGem -Sudo $sudo -GemName "ffi" -GemVersion "1.16.3"
2415-
Install-GlobalGem -Sudo $sudo -GemName "fpm" -GemVersion "1.15.1"
2416-
Install-GlobalGem -Sudo $sudo -GemName "rexml" -GemVersion "3.2.5"
2417-
}
2418-
24192377
# For RPM-based systems, ensure rpmbuild is available
24202378
if ($environment.IsLinux -and ($environment.IsRedHatFamily -or $environment.IsSUSEFamily -or $environment.IsMariner)) {
24212379
Write-Verbose -Verbose "Checking for rpmbuild..."
@@ -2424,6 +2382,22 @@ function Start-PSBootstrap {
24242382
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager install -y rpm-build")) -IgnoreExitcode
24252383
}
24262384
}
2385+
2386+
# For Debian-based systems and Mariner, ensure dpkg-deb is available
2387+
if ($environment.IsLinux -and ($environment.IsDebianFamily -or $environment.IsMariner)) {
2388+
Write-Verbose -Verbose "Checking for dpkg-deb..."
2389+
if (!(Get-Command dpkg-deb -ErrorAction SilentlyContinue)) {
2390+
Write-Warning "dpkg-deb not found. Installing dpkg package..."
2391+
if ($environment.IsMariner) {
2392+
# For Mariner (Azure Linux), install the extended repo first to access dpkg.
2393+
Write-Verbose -Verbose "Installing azurelinux-repos-extended for Mariner..."
2394+
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager install -y azurelinux-repos-extended")) -IgnoreExitcode
2395+
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager install -y dpkg")) -IgnoreExitcode
2396+
} else {
2397+
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo apt-get install -y dpkg")) -IgnoreExitcode
2398+
}
2399+
}
2400+
}
24272401
}
24282402
}
24292403

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

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ Describe "Linux Package Name Validation" {
2121
It "Should have valid RPM package names" {
2222
$rpmPackages = Get-ChildItem -Path $artifactsDir -Recurse -Filter *.rpm -ErrorAction SilentlyContinue
2323

24-
if ($rpmPackages.Count -eq 0) {
25-
Set-ItResult -Skipped -Because "No RPM packages found in artifacts directory"
26-
return
27-
}
24+
$rpmPackages.Count | Should -BeGreaterThan 0 -Because "At least one RPM package should exist in the artifacts directory"
2825

2926
$invalidPackages = @()
3027
# Regex pattern for valid RPM package names.
@@ -49,19 +46,50 @@ Describe "Linux Package Name Validation" {
4946
if ($invalidPackages.Count -gt 0) {
5047
throw ($invalidPackages | Out-String)
5148
}
49+
}
50+
}
51+
52+
Context "DEB Package Names" {
53+
It "Should have valid DEB package names" {
54+
$debPackages = Get-ChildItem -Path $artifactsDir -Recurse -Filter *.deb -ErrorAction SilentlyContinue
55+
56+
$debPackages.Count | Should -BeGreaterThan 0 -Because "At least one DEB package should exist in the artifacts directory"
57+
58+
$invalidPackages = @()
59+
# Regex pattern for valid DEB package names.
60+
# Valid examples:
61+
# - powershell-preview_7.6.0-preview.6-1.deb_amd64.deb
62+
# - powershell-lts_7.4.13-1.deb_amd64.deb
63+
# - powershell_7.4.13-1.deb_amd64.deb
64+
# Breakdown:
65+
# ^powershell : Starts with 'powershell'
66+
# (-preview|-lts)? : Optionally '-preview' or '-lts'
67+
# _\d+\.\d+\.\d+ : Underscore followed by version number (e.g., _7.6.0)
68+
# (-[a-z]+\.\d+)? : Optional dash, letters, dot, and digits (e.g., -preview.6)
69+
# -1 : Literal '-1'
70+
# \.deb_ : Literal '.deb_'
71+
# (amd64|arm64) : Architecture
72+
# \.deb$ : File extension
73+
$debPackageNamePattern = '^powershell(-preview|-lts)?_\d+\.\d+\.\d+(-[a-z]+\.\d+)?-1\.deb_(amd64|arm64)\.deb$'
74+
75+
foreach ($package in $debPackages) {
76+
if ($package.Name -notmatch $debPackageNamePattern) {
77+
$invalidPackages += "$($package.Name) is not a valid DEB package name"
78+
Write-Warning "$($package.Name) is not a valid DEB package name"
79+
}
80+
}
5281

53-
$rpmPackages.Count | Should -BeGreaterThan 0
82+
if ($invalidPackages.Count -gt 0) {
83+
throw ($invalidPackages | Out-String)
84+
}
5485
}
5586
}
5687

5788
Context "Tar.Gz Package Names" {
5889
It "Should have valid tar.gz package names" {
5990
$tarPackages = Get-ChildItem -Path $artifactsDir -Recurse -Filter *.tar.gz -ErrorAction SilentlyContinue
6091

61-
if ($tarPackages.Count -eq 0) {
62-
Set-ItResult -Skipped -Because "No tar.gz packages found in artifacts directory"
63-
return
64-
}
92+
$tarPackages.Count | Should -BeGreaterThan 0 -Because "At least one tar.gz package should exist in the artifacts directory"
6593

6694
$invalidPackages = @()
6795
foreach ($package in $tarPackages) {
@@ -76,8 +104,6 @@ Describe "Linux Package Name Validation" {
76104
if ($invalidPackages.Count -gt 0) {
77105
throw ($invalidPackages | Out-String)
78106
}
79-
80-
$tarPackages.Count | Should -BeGreaterThan 0
81107
}
82108
}
83109

0 commit comments

Comments
 (0)