Skip to content

Commit 391284f

Browse files
TravisEz13Copilot
andauthored
[release/v7.6] Remove usage of fpm for DEB package generation (#26504)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent 61682d4 commit 391284f

3 files changed

Lines changed: 321 additions & 272 deletions

File tree

build.psm1

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,43 +2249,6 @@ function Get-RedHatPackageManager {
22492249
}
22502250
}
22512251

2252-
function Install-GlobalGem {
2253-
param(
2254-
[Parameter()]
2255-
[string]
2256-
$Sudo = "",
2257-
2258-
[Parameter(Mandatory)]
2259-
[string]
2260-
$GemName,
2261-
2262-
[Parameter(Mandatory)]
2263-
[string]
2264-
$GemVersion
2265-
)
2266-
try {
2267-
# We cannot guess if the user wants to run gem install as root on linux and windows,
2268-
# but macOs usually requires sudo
2269-
$gemsudo = ''
2270-
if($environment.IsMacOS -or $env:TF_BUILD -or $env:GITHUB_ACTIONS) {
2271-
$gemsudo = $sudo
2272-
}
2273-
2274-
Start-NativeExecution ([ScriptBlock]::Create("$gemsudo gem install $GemName -v $GemVersion --no-document"))
2275-
2276-
} catch {
2277-
Write-Warning "Installation of gem $GemName $GemVersion failed! Must resolve manually."
2278-
$logs = Get-ChildItem "/var/lib/gems/*/extensions/x86_64-linux/*/$GemName-*/gem_make.out" | Select-Object -ExpandProperty FullName
2279-
foreach ($log in $logs) {
2280-
Write-Verbose "Contents of: $log" -Verbose
2281-
Get-Content -Raw -Path $log -ErrorAction Ignore | ForEach-Object { Write-Verbose $_ -Verbose }
2282-
Write-Verbose "END Contents of: $log" -Verbose
2283-
}
2284-
2285-
throw
2286-
}
2287-
}
2288-
22892252
function Start-PSBootstrap {
22902253
[CmdletBinding()]
22912254
param(
@@ -2297,7 +2260,12 @@ function Start-PSBootstrap {
22972260
[switch]$BuildLinuxArm,
22982261
[switch]$Force,
22992262
[Parameter(Mandatory = $true)]
2300-
[ValidateSet("Package", "DotNet", "Both")]
2263+
# Package: Install dependencies for packaging tools (rpmbuild, dpkg-deb, pkgbuild, WiX)
2264+
# DotNet: Install the .NET SDK
2265+
# Both: Package and DotNet scenarios
2266+
# Tools: Install .NET global tools (e.g., dotnet-format)
2267+
# All: Install all dependencies (packaging, .NET SDK, and tools)
2268+
[ValidateSet("Package", "DotNet", "Both", "Tools", "All")]
23012269
[string]$Scenario = "Package"
23022270
)
23032271

@@ -2333,7 +2301,9 @@ function Start-PSBootstrap {
23332301
elseif ($environment.IsUbuntu18) { $Deps += "libicu60"}
23342302

23352303
# Packaging tools
2336-
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "ruby-dev", "groff", "libffi-dev", "rpm", "g++", "make" }
2304+
# Note: ruby-dev, libffi-dev, g++, and make are no longer needed for DEB packaging
2305+
# DEB packages now use native dpkg-deb (pre-installed)
2306+
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "groff", "rpm" }
23372307

23382308
# Install dependencies
23392309
# change the fontend from apt-get to noninteractive
@@ -2357,7 +2327,9 @@ function Start-PSBootstrap {
23572327
$Deps += "libicu", "openssl-libs"
23582328

23592329
# Packaging tools
2360-
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "ruby-devel", "rpm-build", "groff", 'libffi-devel', "gcc-c++" }
2330+
# Note: ruby-devel and libffi-devel are no longer needed
2331+
# RPM packages use rpmbuild, DEB packages use dpkg-deb
2332+
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "rpm-build", "groff" }
23612333

23622334
$PackageManager = Get-RedHatPackageManager
23632335

@@ -2378,7 +2350,8 @@ function Start-PSBootstrap {
23782350
$Deps += "wget"
23792351

23802352
# Packaging tools
2381-
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "ruby-devel", "rpmbuild", "groff", 'libffi-devel', "gcc" }
2353+
# Note: ruby-devel and libffi-devel are no longer needed for packaging
2354+
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { $Deps += "rpmbuild", "groff" }
23822355

23832356
$PackageManager = "zypper --non-interactive install"
23842357
$baseCommand = "$sudo $PackageManager"
@@ -2417,17 +2390,7 @@ function Start-PSBootstrap {
24172390
}
24182391
}
24192392

2420-
# Install [fpm](https://github.com/jordansissel/fpm)
2421-
# Note: fpm is now only needed for DEB and macOS packages; RPM packages use rpmbuild directly
2422-
if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') {
2423-
# Install fpm on Debian-based systems, macOS, and Mariner (where DEB packages are built)
2424-
if (($environment.IsLinux -and ($environment.IsDebianFamily -or $environment.IsMariner)) -or $environment.IsMacOS) {
2425-
Install-GlobalGem -Sudo $sudo -GemName "dotenv" -GemVersion "2.8.1"
2426-
Install-GlobalGem -Sudo $sudo -GemName "ffi" -GemVersion "1.16.3"
2427-
Install-GlobalGem -Sudo $sudo -GemName "fpm" -GemVersion "1.15.1"
2428-
Install-GlobalGem -Sudo $sudo -GemName "rexml" -GemVersion "3.2.5"
2429-
}
2430-
2393+
if ($Scenario -in 'All', 'Both', 'Package') {
24312394
# For RPM-based systems, ensure rpmbuild is available
24322395
if ($environment.IsLinux -and ($environment.IsRedHatFamily -or $environment.IsSUSEFamily -or $environment.IsMariner)) {
24332396
Write-Verbose -Verbose "Checking for rpmbuild..."
@@ -2436,6 +2399,22 @@ function Start-PSBootstrap {
24362399
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager install -y rpm-build")) -IgnoreExitcode
24372400
}
24382401
}
2402+
2403+
# For Debian-based systems and Mariner, ensure dpkg-deb is available
2404+
if ($environment.IsLinux -and ($environment.IsDebianFamily -or $environment.IsMariner)) {
2405+
Write-Verbose -Verbose "Checking for dpkg-deb..."
2406+
if (!(Get-Command dpkg-deb -ErrorAction SilentlyContinue)) {
2407+
Write-Warning "dpkg-deb not found. Installing dpkg package..."
2408+
if ($environment.IsMariner) {
2409+
# For Mariner (Azure Linux), install the extended repo first to access dpkg.
2410+
Write-Verbose -Verbose "Installing azurelinux-repos-extended for Mariner..."
2411+
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager azurelinux-repos-extended")) -IgnoreExitcode
2412+
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo $PackageManager dpkg")) -IgnoreExitcode
2413+
} else {
2414+
Start-NativeExecution -sb ([ScriptBlock]::Create("$sudo apt-get install -y dpkg")) -IgnoreExitcode
2415+
}
2416+
}
2417+
}
24392418
}
24402419
Write-LogGroupEnd -Title "Install Native Dependencies"
24412420
}

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)