From b491078dc87ce9f9bfa196b4c125849436fd1cb3 Mon Sep 17 00:00:00 2001 From: Gamosoft Date: Sun, 23 Nov 2025 16:55:05 +0100 Subject: [PATCH] added some checks to release script --- release.ps1 | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/release.ps1 b/release.ps1 index 881963d..a9ccf2e 100644 --- a/release.ps1 +++ b/release.ps1 @@ -12,7 +12,69 @@ if ($Version -notmatch '^\d+\.\d+\.\d+$') { exit 1 } -Write-Host "Releasing version $Version..." -ForegroundColor Green +# Check if we're on the main branch +$currentBranch = git rev-parse --abbrev-ref HEAD +if ($currentBranch -ne "main" -and $currentBranch -ne "master") { + Write-Host "Error: Releases can only be created from the main branch." -ForegroundColor Red + Write-Host "Current branch: $currentBranch" -ForegroundColor Yellow + Write-Host "Please switch to main branch first: git checkout main" -ForegroundColor Yellow + exit 1 +} + +Write-Host "Releasing version $Version from branch: $currentBranch" -ForegroundColor Green + +# Read current version and validate it's higher +if (Test-Path "VERSION") { + $currentVersion = (Get-Content "VERSION" -Raw).Trim() + + if ($currentVersion -match '^\d+\.\d+\.\d+$') { + # Parse versions into components + $currentParts = $currentVersion -split '\.' + $newParts = $Version -split '\.' + + $currentMajor = [int]$currentParts[0] + $currentMinor = [int]$currentParts[1] + $currentPatch = [int]$currentParts[2] + + $newMajor = [int]$newParts[0] + $newMinor = [int]$newParts[1] + $newPatch = [int]$newParts[2] + + # Compare versions + $isHigher = $false + if ($newMajor -gt $currentMajor) { + $isHigher = $true + } elseif ($newMajor -eq $currentMajor) { + if ($newMinor -gt $currentMinor) { + $isHigher = $true + } elseif ($newMinor -eq $currentMinor) { + if ($newPatch -gt $currentPatch) { + $isHigher = $true + } + } + } + + if (-not $isHigher) { + Write-Host "Error: New version must be higher than current version." -ForegroundColor Red + Write-Host "Current version: $currentVersion" -ForegroundColor Yellow + Write-Host "New version: $Version" -ForegroundColor Yellow + Write-Host "`nVersion comparison:" -ForegroundColor Yellow + Write-Host " Major: $newMajor vs $currentMajor" -ForegroundColor Yellow + Write-Host " Minor: $newMinor vs $currentMinor" -ForegroundColor Yellow + Write-Host " Patch: $newPatch vs $currentPatch" -ForegroundColor Yellow + exit 1 + } + + Write-Host "Version check passed: $currentVersion -> $Version" -ForegroundColor Green + } else { + Write-Host "Error: Current VERSION file has invalid format. Must be in X.Y.Z format (e.g., 0.4.0)" -ForegroundColor Red + Write-Host "Current VERSION file contains: '$currentVersion'" -ForegroundColor Yellow + Write-Host "Please fix the VERSION file before creating a release." -ForegroundColor Yellow + exit 1 + } +} else { + Write-Host "No existing VERSION file found. Creating new one..." -ForegroundColor Yellow +} # Check if working directory is clean (unless skipping commit) if (-not $SkipCommit) {