From eac64606454b7a36b7e90a6d45963021897d7965 Mon Sep 17 00:00:00 2001 From: Denys Zaitsev Date: Thu, 3 Jul 2025 12:49:24 +0300 Subject: [PATCH] added env vars for stage/prod and updated gdrive upload for production (separate folder). --- build/gdrive_upload_full.ps1 | 65 +++++++++++++++++++++++++++---- build/gdrive_upload_iterative.ps1 | 31 --------------- build/installer.full.iss | 12 +++++- build/installer.iterative.iss | 16 +++++++- 4 files changed, 84 insertions(+), 40 deletions(-) delete mode 100644 build/gdrive_upload_iterative.ps1 diff --git a/build/gdrive_upload_full.ps1 b/build/gdrive_upload_full.ps1 index d6f5164..75dc4ed 100644 --- a/build/gdrive_upload_full.ps1 +++ b/build/gdrive_upload_full.ps1 @@ -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." } diff --git a/build/gdrive_upload_iterative.ps1 b/build/gdrive_upload_iterative.ps1 deleted file mode 100644 index 221e4f9..0000000 --- a/build/gdrive_upload_iterative.ps1 +++ /dev/null @@ -1,31 +0,0 @@ -param ( - [string]$Path = "." -) - -Write-Output "`n=== Starting Upload: Iterative Installer ===" - -$uploadFolder = "AzaionSuiteBuilds" -Write-Output "[INFO] Target Google Drive folder: $uploadFolder" -Write-Output "[INFO] Looking for latest .exe matching 'AzaionSuite.Iterative.*.exe' in folder: $Path..." - -$iterativeFile = Get-ChildItem -Path $Path -Filter "AzaionSuite.Iterative.*.exe" | - Sort-Object LastWriteTime -Descending | - Select-Object -First 1 - -if ($iterativeFile) { - Write-Output "[FOUND] Iterative installer: $($iterativeFile.Name)" - Write-Output "[INFO] Full path: $($iterativeFile.FullName)" - Write-Output "[ACTION] Uploading file to Google Drive using rclone..." - - rclone copy "$($iterativeFile.FullName)" "AzaionGoogleDrive:$uploadFolder" --progress - - if ($LASTEXITCODE -eq 0) { - Write-Output "[SUCCESS] Iterative installer uploaded successfully." - } else { - Write-Output "[ERROR] Upload failed with exit code $LASTEXITCODE." - } -} else { - Write-Output "[WARNING] No matching Iterative installer found in folder: $Path." -} - -Write-Output "=== Upload Complete: Iterative Installer ===`n" diff --git a/build/installer.full.iss b/build/installer.full.iss index fd1bab4..9b327c0 100644 --- a/build/installer.full.iss +++ b/build/installer.full.iss @@ -1,5 +1,9 @@ #define MyAppVersion GetFileVersion("..\dist-azaion\Azaion.Suite.exe") +#ifndef MY_BUILD_ENV +#define MY_BUILD_ENV "Stage" ; За замовчуванням Stage, якщо не вказано +#endif + [Setup] AppId={{CCFEC8E2-0FCC-4B03-8EEA-00AF20D265E5}} AppName=Azaion Suite @@ -9,7 +13,13 @@ AppPublisher=Azaion LLC DefaultDirName={localappdata}\Azaion\Azaion Suite DefaultGroupName=Azaion Suite OutputDir=..\ -OutputBaseFilename=AzaionSuite.Full.{#MyAppVersion} + +#if MY_BUILD_ENV == "Prod" +OutputBaseFilename=AzaionSuite.Full.Prod.{#MyAppVersion} +#else +OutputBaseFilename=AzaionSuite.Full.Stage.{#MyAppVersion} ; За замовчуванням Stage +#endif + SetupIconFile=..\dist-azaion\logo.ico UninstallDisplayName=Azaion Suite UninstallDisplayIcon={app}\Azaion.Suite.exe diff --git a/build/installer.iterative.iss b/build/installer.iterative.iss index 1ac7d13..4ca904b 100644 --- a/build/installer.iterative.iss +++ b/build/installer.iterative.iss @@ -1,5 +1,12 @@ #define MyAppVersion GetFileVersion("..\dist-azaion\Azaion.Suite.exe") +; Define a variable for the build environment, e.g., "Stage" or "Prod" +; This will be set by your Jenkins pipeline using the /D switch. +; If not defined via /D, it defaults to "Stage". +#ifndef MY_BUILD_ENV +#define MY_BUILD_ENV "Stage" ; Default to Stage if not specified (e.g., when compiling manually without /D) +#endif + [Setup] AppId={{CCFEC8E2-0FCC-4B03-8EEA-00AF20D265E5}} AppName=Azaion Suite @@ -9,7 +16,14 @@ AppPublisher=Azaion LLC DefaultDirName={localappdata}\Azaion\Azaion Suite DefaultGroupName=Azaion Suite OutputDir=..\ -OutputBaseFilename=AzaionSuite.Iterative.{#MyAppVersion} + +; Conditional OutputBaseFilename based on MY_BUILD_ENV +#if MY_BUILD_ENV == "Prod" +OutputBaseFilename=AzaionSuite.Iterative.Prod.{#MyAppVersion} +#else +OutputBaseFilename=AzaionSuite.Iterative.Stage.{#MyAppVersion} ; Defaults to Stage if MY_BUILD_ENV is not "Prod" +#endif + SetupIconFile=..\dist-azaion\logo.ico UninstallDisplayName=Azaion Suite UninstallDisplayIcon={app}\Azaion.Suite.exe