Refactor package name validation to use centralized functions

Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-18 18:51:40 +00:00
co-authored by TravisEz13
parent 3241b9802f
commit 00883eb569
3 changed files with 20 additions and 48 deletions
@@ -54,9 +54,10 @@ jobs:
displayName: Capture Artifact Listing
- pwsh: |
Import-Module ./tools/packaging/packaging.psm1 -Force
$message = @()
Get-ChildItem $(System.ArtifactsDirectory)\* -recurse -filter *.rpm | ForEach-Object {
if($_.Name -notmatch 'powershell\-(preview-|lts-)?\d+\.\d+\.\d+(_[a-z]*\.\d+)?-1.(rh|cm).(x86_64|aarch64)\.rpm')
if(-not (Test-PackageNameRpm -PackageName $_.Name))
{
$messageInstance = "$($_.Name) is not a valid package name"
$message += $messageInstance
@@ -67,9 +68,10 @@ jobs:
displayName: Validate RPM package names
- pwsh: |
Import-Module ./tools/packaging/packaging.psm1 -Force
$message = @()
Get-ChildItem $(System.ArtifactsDirectory)\* -recurse -filter *.tar.gz | ForEach-Object {
if($_.Name -notmatch '^powershell-(lts-)?\d+\.\d+\.\d+\-([a-z]*\.\d+\-)?(linux|osx|linux-musl)\-(x64\-fxdependent|x64|arm32|arm64|x64\-musl-noopt\-fxdependent)\.tar\.gz$')
if(-not (Test-PackageNameTarGz -PackageName $_.Name))
{
$messageInstance = "$($_.Name) is not a valid package name"
$message += $messageInstance
@@ -80,9 +82,10 @@ jobs:
displayName: Validate Tar.Gz Package Names
- pwsh: |
Import-Module ./tools/packaging/packaging.psm1 -Force
$message = @()
Get-ChildItem $(System.ArtifactsDirectory)\* -recurse -filter *.pkg | ForEach-Object {
if($_.Name -notmatch '^powershell-(lts-)?\d+\.\d+\.\d+\-([a-z]+\.\d+\-)?osx\-(x64|arm64)\.pkg$')
if(-not (Test-PackageNamePkg -PackageName $_.Name))
{
$messageInstance = "$($_.Name) is not a valid package name"
$message += $messageInstance
@@ -93,9 +96,10 @@ jobs:
displayName: Validate PKG Package Names
- pwsh: |
Import-Module ./tools/packaging/packaging.psm1 -Force
$message = @()
Get-ChildItem $(System.ArtifactsDirectory)\* -recurse -include *.zip, *.msi | ForEach-Object {
if($_.Name -notmatch '^PowerShell-\d+\.\d+\.\d+\-([a-z]+\.\d+\-)?win\-(fxdependent|x64|arm64|x86|fxdependentWinDesktop)\.(msi|zip){1}$')
if(-not (Test-PackageNameWindowsMsiZip -PackageName $_.Name))
{
$messageInstance = "$($_.Name) is not a valid package name"
$message += $messageInstance
@@ -107,9 +111,10 @@ jobs:
displayName: Validate Zip and MSI Package Names
- pwsh: |
Import-Module ./tools/packaging/packaging.psm1 -Force
$message = @()
Get-ChildItem $(System.ArtifactsDirectory)\* -recurse -filter *.deb | ForEach-Object {
if($_.Name -notmatch '^powershell(-preview|-lts)?_\d+\.\d+\.\d+([\-~][a-z]+\.\d+)?-\d\.deb_amd64\.deb$')
if(-not (Test-PackageNameDeb -PackageName $_.Name))
{
$messageInstance = "$($_.Name) is not a valid package name"
$message += $messageInstance
@@ -3,6 +3,8 @@
Describe "Linux Package Name Validation" {
BeforeAll {
Import-Module $PSScriptRoot/../../tools/packaging/packaging.psm1 -Force
# Determine artifacts directory (GitHub Actions or Azure DevOps)
$artifactsDir = if ($env:GITHUB_ACTIONS -eq 'true') {
"$env:GITHUB_WORKSPACE/../packages"
@@ -24,20 +26,9 @@ Describe "Linux Package Name Validation" {
$rpmPackages.Count | Should -BeGreaterThan 0 -Because "At least one RPM package should exist in the artifacts directory"
$invalidPackages = @()
# Regex pattern for valid RPM package names.
# Breakdown:
# ^powershell\- : Starts with 'powershell-'
# (preview-|lts-)? : Optionally 'preview-' or 'lts-'
# \d+\.\d+\.\d+ : Version number (e.g., 7.6.0)
# (_[a-z]*\.\d+)? : Optional underscore, letters, dot, and digits (e.g., _alpha.1)
# -1\. : Literal '-1.'
# (preview\.\d+\.)? : Optional 'preview.' and digits, followed by a dot
# (rh|cm)\. : Either 'rh.' or 'cm.'
# (x86_64|aarch64)\.rpm$ : Architecture and file extension
$rpmPackageNamePattern = 'powershell\-(preview-|lts-)?\d+\.\d+\.\d+(_[a-z]*\.\d+)?-1\.(preview\.\d+\.)?(rh|cm)\.(x86_64|aarch64)\.rpm'
foreach ($package in $rpmPackages) {
if ($package.Name -notmatch $rpmPackageNamePattern) {
if (-not (Test-PackageNameRpm -PackageName $package.Name)) {
$invalidPackages += "$($package.Name) is not a valid RPM package name"
Write-Warning "$($package.Name) is not a valid RPM package name"
}
@@ -56,24 +47,9 @@ Describe "Linux Package Name Validation" {
$debPackages.Count | Should -BeGreaterThan 0 -Because "At least one DEB package should exist in the artifacts directory"
$invalidPackages = @()
# Regex pattern for valid DEB package names.
# Valid examples:
# - powershell-preview_7.6.0-preview.6-1.deb_amd64.deb
# - powershell-lts_7.4.13-1.deb_amd64.deb
# - powershell_7.4.13-1.deb_amd64.deb
# Breakdown:
# ^powershell : Starts with 'powershell'
# (-preview|-lts)? : Optionally '-preview' or '-lts'
# _\d+\.\d+\.\d+ : Underscore followed by version number (e.g., _7.6.0)
# (-[a-z]+\.\d+)? : Optional dash, letters, dot, and digits (e.g., -preview.6)
# -1 : Literal '-1'
# \.deb_ : Literal '.deb_'
# (amd64|arm64) : Architecture
# \.deb$ : File extension
$debPackageNamePattern = '^powershell(-preview|-lts)?_\d+\.\d+\.\d+(-[a-z]+\.\d+)?-1\.deb_(amd64|arm64)\.deb$'
foreach ($package in $debPackages) {
if ($package.Name -notmatch $debPackageNamePattern) {
if (-not (Test-PackageNameDeb -PackageName $package.Name)) {
$invalidPackages += "$($package.Name) is not a valid DEB package name"
Write-Warning "$($package.Name) is not a valid DEB package name"
}
@@ -93,9 +69,7 @@ Describe "Linux Package Name Validation" {
$invalidPackages = @()
foreach ($package in $tarPackages) {
# Pattern matches: powershell-7.6.0-preview.6-linux-x64.tar.gz or powershell-7.6.0-linux-x64.tar.gz
# Also matches various runtime configurations
if ($package.Name -notmatch '^powershell-(lts-)?\d+\.\d+\.\d+\-([a-z]*\.\d+\-)?(linux|osx|linux-musl)\-(x64\-fxdependent|x64|arm32|arm64|x64\-musl-noopt\-fxdependent)\.tar\.gz$') {
if (-not (Test-PackageNameTarGz -PackageName $package.Name)) {
$invalidPackages += "$($package.Name) is not a valid tar.gz package name"
Write-Warning "$($package.Name) is not a valid tar.gz package name"
}
@@ -5,6 +5,7 @@ Describe "Verify macOS Package" {
BeforeAll {
Write-Verbose "In Describe BeforeAll" -Verbose
Import-Module $PSScriptRoot/../../../build.psm1
Import-Module $PSScriptRoot/../../../tools/packaging/packaging.psm1
# Find the macOS package
$packagePath = $env:PACKAGE_FOLDER
@@ -81,16 +82,8 @@ Describe "Verify macOS Package" {
It "Package name should follow correct naming convention" {
$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$'
$script:package.Name | Should -Match $pkgPackageNamePattern -Because "Package name should follow the standard naming convention"
# Use the centralized validation function from packaging module
Test-PackageNamePkg -PackageName $script:package.Name | Should -Be $true -Because "Package name should follow the standard naming convention"
}
It "Package name should NOT use x86_64 with underscores" {