diff --git a/build/gdrive_retention.ps1 b/build/gdrive_retention.ps1 index 3e499ad..1f6234d 100644 --- a/build/gdrive_retention.ps1 +++ b/build/gdrive_retention.ps1 @@ -1,4 +1,4 @@ - # Configuration +# Configuration $rcloneRemote = "AzaionGoogleDrive:AzaionSuiteBuilds" $rclone = "rclone" # Assuming rclone is available in the PATH. @@ -18,11 +18,19 @@ function Write-ErrorMsg($text) { Write-Host "[ERROR] $text" -ForegroundColor Red } -function Get-BuildNumber($filename) { - if ($filename -match "\.(\d+)\.(zip|exe)$") { - return [int]$matches[1] +function Get-SortableBuildKey($filename) { + # This regex is specifically for the AzaionSuite filenames + # It captures the four-part build number (year.month.day.build) + if ($filename -match 'AzaionSuite\.(?:Full|Iterative)\.Stage\.(\d{4})\.(\d+)\.(\d+)\.(\d+)\.(zip|exe)$') { + # Create a combined key that can be sorted chronologically + # Example: '202507030634' + $year = [int]$matches[1] + $month = [int]$matches[2] + $day = [int]$matches[3] + $buildNumber = [int]$matches[4] + return "$year-$month-$day-$buildNumber" } - return 0 + return "0000-00-00-0000" } Write-Header "Starting cleanup of older Full and Iterative installers on Google Drive" @@ -48,16 +56,16 @@ $allFiles | ForEach-Object { Write-Host " $_" } # --- Full Installers --- Write-Header 'Checking for old Full installers (AzaionSuite.Full.*.zip)' $fullFiles = $allFiles | Where-Object { $_ -like "AzaionSuite.Full.*.zip" } | - Sort-Object { Get-BuildNumber $_ } -Descending + Sort-Object { Get-SortableBuildKey $_ } -Descending if ($fullFiles.Count -eq 0) { Write-WarningMsg "No Full installer files found." } else { - Write-Info "Matching Full installer files:" + Write-Info "Matching Full installer files (sorted by date/build):" $fullFiles | ForEach-Object { Write-Host " $_" } if ($fullFiles.Count -le 5) { - Write-Info "5 or fewer Full installers found — nothing to delete." + Write-Info "5 or fewer Full installers found — nothing to delete." } else { $fullToDelete = $fullFiles | Select-Object -Skip 5 Write-WarningMsg "Full installers to delete:" @@ -77,16 +85,16 @@ if ($fullFiles.Count -eq 0) { # --- Iterative Installers --- Write-Header 'Checking for old Iterative installers (AzaionSuite.Iterative.*.exe)' $iterativeFiles = $allFiles | Where-Object { $_ -like "AzaionSuite.Iterative.*.exe" } | - Sort-Object { Get-BuildNumber $_ } -Descending + Sort-Object { Get-SortableBuildKey $_ } -Descending if ($iterativeFiles.Count -eq 0) { Write-WarningMsg "No Iterative installer files found." } else { - Write-Info "Matching Iterative installer files:" + Write-Info "Matching Iterative installer files (sorted by date/build):" $iterativeFiles | ForEach-Object { Write-Host " $_" } if ($iterativeFiles.Count -le 5) { - Write-Info "5 or fewer Iterative installers found — nothing to delete." + Write-Info "5 or fewer Iterative installers found — nothing to delete." } else { $iterativeToDelete = $iterativeFiles | Select-Object -Skip 5 Write-WarningMsg "Iterative installers to delete:" @@ -103,5 +111,4 @@ if ($iterativeFiles.Count -eq 0) { } } -Write-Header "Cleanup script completed" - +Write-Header "Cleanup script completed" \ No newline at end of file