Skip to content

Replace fpm with native rpmbuild for RPM package generation#26233

Merged
TravisEz13 merged 27 commits intomasterfrom
copilot/update-code-to-generate-rpm
Oct 20, 2025
Merged

Replace fpm with native rpmbuild for RPM package generation#26233
TravisEz13 merged 27 commits intomasterfrom
copilot/update-code-to-generate-rpm

Conversation

Copy link
Contributor

Copilot AI commented Oct 17, 2025

Summary

Successfully replaced the Ruby gem fpm with native rpmbuild for generating RPM packages, eliminating the need for Ruby and associated gems when building RPM packages on RHEL, CentOS, Fedora, SUSE, and Azure Linux systems.

Changes Made

Modified Files

  • build.psm1 - Updated bootstrap logic to install fpm on Debian/macOS/Mariner, added Azure Linux support
  • tools/packaging/packaging.psm1 - Implemented native rpmbuild support with well-documented cross-architecture build fixes
  • tools/ci.psm1 - Fixed package artifacts handling for GitHub Actions
  • .github/actions/test/linux-packaging/action.yml - Updated to explicitly import packaging modules and run validation tests
  • .github/workflows/linux-ci.yml - Updated to trigger packaging job for packaging changes

Created Files

  • test/packaging/linux/package-validation.tests.ps1 - Added Pester tests for package name validation

Key Features

1. New-RpmSpec Function

  • Generates complete RPM spec files from package metadata
  • Includes all required sections: description, prep, build, install, post, postun, files, changelog
  • Handles dependencies, symlinks, and install/remove scripts
  • Produces properly formatted spec files compatible with rpmbuild
  • Properly handles pre-release versions by converting hyphens to underscores (e.g., 7.6.0-preview.5 → 7.6.0_preview.5)
  • Builds release field with distribution suffix in PowerShell (e.g., "1.cm" or "1.rh")
  • Supports cross-architecture builds with well-documented binary stripping disabled
  • Disables debug package generation for cross-arch builds with detailed explanations

2. Updated New-UnixPackage Function

  • Detects RPM package type and routes to rpmbuild instead of fpm
  • Creates proper rpmbuild directory structure (SPECS, RPMS, BUILDROOT)
  • Generates spec files and builds packages using native tools
  • Logs spec file content with collapsible GitHub Actions groups for debugging
  • Cleans up temporary directories after build
  • Maintains backward compatibility for DEB and macOS packages (still use fpm)
  • Fixed output path handling to avoid path duplication
  • Supports cross-architecture builds with --target option for arm64 packages

3. Updated Test-Dependencies Function

  • Only checks for fpm on Debian-based systems and Mariner
  • RPM-based systems skip fpm dependency check

4. Updated Start-PSBootstrap Function

  • Installs fpm on Debian-based systems, macOS, and Mariner (where DEB packages are built)
  • Ensures rpm-build package is available on RPM-based systems (RHEL, SUSE, Azure Linux)
  • Fixed environment property checks for cross-platform compatibility
  • Added support for Azure Linux (CBL-Mariner) for both DEB and RPM builds

5. Updated Linux Packaging Workflow

  • Explicitly imports build.psm1 and packaging.psm1 modules
  • Ensures RPM packaging changes are properly loaded during CI builds
  • Follows pattern similar to Windows packaging workflow
  • Runs Pester tests to validate package names before artifact upload

6. Updated Linux CI Workflow

  • Added packagingChanged output to changes detection job
  • Updated linux_packaging job to trigger on packaging-related changes
  • Maintains ci_build dependency to ensure build artifacts are available
  • Uses packaging change detection for efficient CI runs

7. Updated New-LinuxPackage Function

  • Detects GitHub Actions vs Azure DevOps environment
  • Uses appropriate artifacts directory path for each CI system
  • Ensures packages are preserved in artifacts directory through build cleanup
  • Maintains clean build requirement for Raspbian packages

8. Added Package Validation Tests

  • Pester tests validate RPM package naming conventions using original regex pattern
  • Pester tests validate tar.gz package naming conventions
  • Tests automatically detect GitHub Actions vs Azure DevOps artifact directories
  • Tests run in CI pipeline after package creation and before upload
  • Catches naming issues early to prevent invalid packages

Benefits

Eliminates Ruby dependency - No need for Ruby or gems on RPM-based systems (except Mariner which also builds DEBs)
Native tooling - Uses standard Linux packaging tools (rpmbuild)
Reduced complexity - Simpler build requirements on RHEL/CentOS/Fedora/SUSE
Faster builds - No Ruby environment setup needed for pure RPM systems
Backward compatible - DEB and macOS packaging unchanged
Well tested - Comprehensive tests validate spec generation and RPM building
CI/CD ready - Workflows updated to properly detect and run packaging jobs
RPM compliant - Follows RPM spec file conventions for version formatting
Cross-architecture support - Supports building arm64 RPMs on x86_64 systems without strip errors
Multi-CI support - Works with both GitHub Actions and Azure DevOps
Package validation - Automated Pester tests ensure package names meet requirements
Better debugging - Spec file logging with collapsible GitHub Actions groups
Accurate release field - Distribution appears in both release field and filename
Azure Linux ready - Full support for CBL-Mariner systems for both DEB and RPM builds
Well documented - Clear comments with links to RPM documentation

Testing

Created and executed comprehensive tests:

  • ✅ Spec file generation with all required sections
  • ✅ Built actual RPM packages using rpmbuild
  • ✅ Validated packages with rpm -qip and rpm -qlp
  • ✅ Module loading and function availability checks
  • ✅ YAML workflow validation
  • ✅ Version parsing for stable and pre-release versions
  • ✅ Path handling for package output
  • ✅ Cross-architecture build support with binary stripping disabled
  • ✅ Package artifacts preservation in CI workflows
  • ✅ Pester tests for RPM and tar.gz package name validation
  • ✅ Regex validation matches original pattern
  • ✅ Spec file logging with GitHub Actions groups
  • ✅ Distribution suffix in release field matches filename

Code Statistics

  • 6 files changed (5 modified, 1 created)
  • 445+ insertions, 37 deletions
  • All changes in PowerShell modules (.psm1), GitHub Actions workflows, and test files

Security Summary

No security vulnerabilities introduced:

  • CodeQL analysis: No issues (PowerShell not analyzed by CodeQL)
  • All changes reviewed for secure coding practices
  • No credentials or sensitive data handling
  • Uses standard Linux packaging tools with proper error handling

Ready for Review

Original prompt

this uses a ruby gem called fpm to generate the RPM package currently.

Update the code to generate an RPMSPEC and generate the RPM directly without using any ruby


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.4.x-Migrated Backport-7.5.x-Migrated Backport-7.6.x-Migrated CL-BuildPackaging Indicates that a PR should be marked as a build or packaging change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants