added env vars for stage/prod and updated gdrive upload for production (separate folder).

This commit is contained in:
Denys Zaitsev
2025-07-03 12:49:24 +03:00
parent bb6413c4f0
commit eac6460645
4 changed files with 84 additions and 40 deletions
+58 -7
View File
@@ -1,14 +1,39 @@
param (
[string]$Path = "."
param (
[string]$Path = ".",
[string]$BuildEnv = "Stage" # Added parameter for build environment, defaults to "Stage"
)
Write-Output "`n=== Starting Upload: Full Installer ZIP ==="
$uploadFolder = "AzaionSuiteBuilds"
Write-Output "[INFO] Target Google Drive folder: $uploadFolder"
Write-Output "[INFO] Looking for latest .zip matching 'AzaionSuite.Full.*.zip' in folder: $Path..."
# Define target Google Drive folders
$stageUploadFolder = "AzaionGoogleDrive:AzaionSuiteBuilds"
$prodUploadFolder = "AzaionGoogleDrive:AzaionSuiteLatestProduction" # Make sure this matches your actual rclone remote name and path
$fullZip = Get-ChildItem -Path $Path -Filter "AzaionSuite.Full.*.zip" |
$targetUploadPath = ""
if ($BuildEnv -eq "Prod") {
Write-Output "[INFO] Build environment is Production. Preparing to upload to: $prodUploadFolder"
# 1. Ensure the Production folder exists
Write-Output "[ACTION] Ensuring production folder '$prodUploadFolder' exists..."
rclone mkdir "$prodUploadFolder"
if ($LASTEXITCODE -ne 0) {
Write-Output "[ERROR] Failed to create or confirm existence of production folder with exit code $LASTEXITCODE. Aborting upload."
exit 1
} else {
Write-Output "[SUCCESS] Production folder confirmed/created."
}
$targetUploadPath = $prodUploadFolder
} else {
Write-Output "[INFO] Build environment is Stage. Uploading to: $stageUploadFolder"
$targetUploadPath = $stageUploadFolder
}
# Updated filter for finding the ZIP file
$filter = "AzaionSuite.Full.$BuildEnv.*.zip"
Write-Output "[INFO] Looking for latest .zip matching '$filter' in folder: $Path..."
$fullZip = Get-ChildItem -Path $Path -Filter $filter |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
@@ -17,10 +42,36 @@ if ($fullZip) {
Write-Output "[INFO] Full path: $($fullZip.FullName)"
Write-Output "[ACTION] Uploading file to Google Drive using rclone..."
rclone copy "$($fullZip.FullName)" "AzaionGoogleDrive:$uploadFolder" --progress
# 2. Upload the new build
rclone copy "$($fullZip.FullName)" "$targetUploadPath" --progress
if ($LASTEXITCODE -eq 0) {
Write-Output "[SUCCESS] Full installer ZIP uploaded successfully."
# 3. Delete all other builds except the newly uploaded one (only for Prod)
if ($BuildEnv -eq "Prod") {
Write-Output "[ACTION] Deleting old production builds, keeping only the newly uploaded file..."
$uploadedFileName = $fullZip.Name
# Get list of files in the target folder
$existingFiles = (rclone ls "$prodUploadFolder" --files-only) | ForEach-Object { $_.Trim() }
if ($LASTEXITCODE -eq 0) {
foreach ($fileName in $existingFiles) {
if ($fileName -ne $uploadedFileName) {
Write-Output "[INFO] Deleting old file: $fileName"
rclone delete "$prodUploadFolder/$fileName"
if ($LASTEXITCODE -ne 0) {
Write-Output "[WARNING] Failed to delete '$fileName' with exit code $LASTEXITCODE."
}
}
}
Write-Output "[SUCCESS] Old production builds cleanup complete."
} else {
Write-Output "[ERROR] Failed to list files in '$prodUploadFolder' for cleanup with exit code $LASTEXITCODE."
}
}
} else {
Write-Output "[ERROR] Upload failed with exit code $LASTEXITCODE."
}