pdm build --no-sdist -d build/ # Configuration $sourceDir = ".\build" $destDir = "..\01_releases\runtime" $packagePrefix = "delta_barth-" $packageSuffix = ".whl" # change this to any suffix pattern like "-py3-none-any.whl" # Ensure destination exists if (-not (Test-Path $destDir)) { New-Item -ItemType Directory -Path $destDir | Out-Null } # === Build Regex Pattern === $escapedSuffix = [regex]::Escape($packageSuffix) # Match versions like 1.2.3 or 1.2.3.beta or 1.2.3.beta1 # Capture the full version as one string, including the optional pre-release after a dot $pattern = "^$packagePrefix(?\d+\.\d+\.\d+(?:\.[a-zA-Z0-9\-]+)?)$escapedSuffix$" Write-Host "Using pattern: $pattern" # === Get and Filter Files === $allFiles = Get-ChildItem -Path $sourceDir -File $matchingFiles = @() foreach ($file in $allFiles) { if ($file.Name -match $pattern) { $version = $Matches['version'] $matchingFiles += [PSCustomObject]@{ File = $file Version = $version } Write-Host "Matched: $($file.Name) -> Version: $version" } else { Write-Host "No match: $($file.Name)" } } if ($matchingFiles.Count -eq 0) { Write-Host "No matching package files found." return } # === Convert version strings to sortable format === function Convert-VersionForSort($v) { # Split by dot: e.g., 1.2.3.beta -> [1, 2, 3, "beta"] $parts = $v -split '\.' $major = [int]$parts[0] $minor = [int]$parts[1] $patch = [int]$parts[2] $pre = if ($parts.Count -gt 3) { $parts[3] } else { "~" } # "~" to ensure stable > prerelease return [PSCustomObject]@{ Major = $major Minor = $minor Patch = $patch Pre = $pre } } # === Sort by semantic version + pre-release === $latest = $matchingFiles | Sort-Object { Convert-VersionForSort $_.Version } -Descending | Select-Object -First 1 # === Copy and rename to .zip === $baseName = [System.IO.Path]::GetFileNameWithoutExtension($latest.File.Name) $newFileName = "$baseName.zip" $destPath = Join-Path $destDir $newFileName Copy-Item -Path $latest.File.FullName -Destination $destPath