From fcd85a609ddebdb8bc0c75d474137c7a319c9e24 Mon Sep 17 00:00:00 2001 From: foefl Date: Thu, 15 May 2025 11:52:44 +0200 Subject: [PATCH] add new build script for improved automation --- scripts/build.ps1 | 81 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index edb0a24..c736f3e 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -1 +1,80 @@ -pdm build -d build/ \ No newline at end of file +# 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(?\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