add new build script for improved automation
This commit is contained in:
parent
3e14a8660e
commit
fcd85a609d
@ -1 +1,80 @@
|
|||||||
pdm build -d build/
|
# pdm build --no-sdist -d build/
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
$sourceDir = ".\build"
|
||||||
|
$destDir = "..\01_releases\runtime"
|
||||||
|
$packagePrefix = "delta_barth-"
|
||||||
|
$packageSuffix = ".whl" # <- You can change this to any suffix pattern like "-py3-none-any.whl"
|
||||||
|
|
||||||
|
|
||||||
|
# === Configuration ===
|
||||||
|
# $sourceDir = "C:\Path\To\Packages"
|
||||||
|
# $destDir = "C:\Path\To\Destination"
|
||||||
|
# $packagePrefix = "my-package-"
|
||||||
|
# $packageSuffix = "-py.whl" # Customize as needed
|
||||||
|
|
||||||
|
# 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(?<version>\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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user