From 273a32c4cb8b03d45bb2fb024483769ce85737fc Mon Sep 17 00:00:00 2001 From: AlisherAmonulloev Date: Sun, 22 Dec 2024 15:09:34 +0200 Subject: [PATCH] Update test-example.ps1 --- test-example.ps1 | 193 +++++++++++++++++++++++++++++++---------------- 1 file changed, 126 insertions(+), 67 deletions(-) diff --git a/test-example.ps1 b/test-example.ps1 index 4b95a71..5104151 100644 --- a/test-example.ps1 +++ b/test-example.ps1 @@ -1,7 +1,21 @@ -$global:inputVersion = $env:branchName -$global:errorCode = 0 +# For local testing, you can pass branchName and/or buildVersion. +# If both parameters are specified, only buildVersion will be used. +# Example usage: +# ./test-example.ps1 -branchName 23.1.3+ +# ./test-example.ps1 -buildVersion 23.1.13 +param ( + [string]$branchName = [Environment]::GetEnvironmentVariable("BRANCH_NAME", [EnvironmentVariableTarget]::Machine), + [string]$buildVersion = [Environment]::GetEnvironmentVariable("BUILD_VERSION", [EnvironmentVariableTarget]::Machine) +) + +# Repository's branch name, e.g. 24.1.3+ +$global:BRANCH_NAME = $branchName +# Masstest-specific parameter. Specifies the minor version (example: '21.1.5') !or daily build (example: '21.2.2005') +$global:BUILD_VERSION = $buildVersion + +$global:ERROR_CODE = 0 -$global:allVersions = @( +$global:ALL_VERSIONS = @( "14.1", "14.2", "15.1", "15.2", "16.1", "16.2", @@ -16,22 +30,53 @@ $global:allVersions = @( "25.1", "25.2" ) +function Install-Packages { + param ( + [string]$folderName, + [string[]]$packages, + [string]$buildVersion + ) + Write-Output "`nInstalling packages in folder: $folderName" + + $packageList = $packages | ForEach-Object { "$_@$buildVersion" } + Write-Output "`nPackages to install: $($packageList -join ", ")" + # TODO: Uninstall DevExtreme packages to avoid potential peer-dependency issues + npm install @($packageList) --save --save-exact --no-fund + if (-not $?) { + Write-Error "`nERROR: Failed to install DevExtreme packages in $folderName" + throw "Installation failed in $folderName" + } +} + +function Build-Project { + param ( + [string]$folderName + ) + Write-Output "`nBuilding the project in folder: $folderName" + + npm run build + if (-not $?) { + Write-Error "`nERROR: Failed to build the project in $folderName" + throw "Build failed in $folderName" + } +} + function Process-JavaScriptProjects { param ( [string]$buildVersion ) - Write-Output "`n--== Processing JavaScript Projects ==--" + Write-Output "`n--== Starting JavaScript Projects Processing ==--" [hashtable[]]$folders = @( - @{ Name = "Angular"; Packages = @("devextreme-angular", "devextreme") }, - @{ Name = "React"; Packages = @("devextreme-react", "devextreme") }, - @{ Name = "Vue"; Packages = @("devextreme-vue", "devextreme") } + @{ Name = "Angular"; Packages = @("devextreme", "devextreme-angular") }, + @{ Name = "React"; Packages = @("devextreme", "devextreme-react") }, + @{ Name = "Vue"; Packages = @("devextreme", "devextreme-vue") } ) $jQueryEntry = @{ Name = "jQuery"; - Packages = if ([double]$buildVersion -ge 23.1) { # `devextreme-dist` appeared in 23.1 - @("devextreme-dist", "devextreme") + Packages = if ([version]$buildVersion -ge [version]23.1) { # `devextreme-dist` appeared in 23.1 + @("devextreme", "devextreme-dist") } else { @("devextreme") } @@ -40,118 +85,132 @@ function Process-JavaScriptProjects { $folders = @($jQueryEntry) + $folders foreach ($folder in $folders) { - if (-not (Test-Path $($folder.Name))) { - Write-Output "`nDirectory $($folder.Name) does not exist. Skipping..." - continue - } + $folderName = $folder.Name + $packages = $folder.Packages - Write-Output "`n<-- Processing folder: $($folder.Name) -->" - - Set-Location $($folder.Name) - - $packages = $folder.Packages | ForEach-Object { "$_@$buildVersion" } - - $packageList = $packages -join " " - - Write-Output "`nInstalling DevExtreme packages" - npm install $packageList --save --save-exact --no-fund - if (-not $?) { - Write-Error "`nERROR: Failed to install DevExtreme packages: $($folder.Name)" - $global:LASTEXITCODE = 1 - $global:errorCode = 1 - } - - Write-Output "`nInstalling the rest of the packages $($folder.Name)" - npm install --save --save-exact --no-fund --loglevel=error - if (-not $?) { - Write-Error "`nERROR: Failed to install packages: $($folder.Name)" - $global:LASTEXITCODE = 1 - $global:errorCode = 1 + if (-not (Test-Path $folderName)) { + Write-Output "`nDirectory $folderName does not exist. Skipping..." + continue } - Write-Output "`nBuilding the project with 'npm run build' $($folder.Name)" - npm run build - if (-not $?) { - Write-Error "`nERROR: Failed to build the project: $($folder.Name)" + Write-Output "`nProcessing folder: $folderName" + Push-Location $folderName + + try { + Install-Packages -folderName $folderName -packages $packages -buildVersion $buildVersion + Write-Output "`nInstalling remaining packages in $folderName" + npm install --save --save-exact --no-fund --loglevel=error + if (-not $?) { + throw "ERROR: Failed to install remaining packages in $folderName" + } + Build-Project -folderName $folderName + } catch { + Write-Error "`nAn error occurred: $_" $global:LASTEXITCODE = 1 - $global:errorCode = 1 + $global:ERROR_CODE = 1 + } finally { + Pop-Location } - - Set-Location .. } + + Write-Output "`n--== JavaScript Projects Processing Completed ==--" } function Process-DotNetProjects { param ( [string]$RootDirectory = "." ) - Write-Output "`nProcessing .NET projects" + + Write-Output "`n--== Starting .NET project processing in directory: $RootDirectory ==--" $slnFiles = Get-ChildItem -Path $RootDirectory -Filter *.sln -Recurse -Depth 1 if ($slnFiles.Count -eq 0) { - Write-Output "`nNo solution files (.sln) found in the specified directory at level 1." + Write-Output "`nNo solution files (.sln) found in the specified directory at level 1." return } foreach ($slnFile in $slnFiles) { Write-Output "`nFound solution file: $($slnFile.FullName)" - dotnet build $slnFile.FullName -c Release - - if ($?) { - Write-Output "`nBuild succeeded for $($slnFile.FullName)." - } else { - Write-Error "`nBuild failed for $($slnFile.FullName)." + try { + Write-Output "`nBuilding solution: $($slnFile.FullName)" + dotnet build $slnFile.FullName -c Release + + if ($?) { + Write-Output "`nBuild succeeded for $($slnFile.FullName)." + } else { + throw "Build failed for $($slnFile.FullName)." + } + } catch { + Write-Error "`nERROR: $_" $global:LASTEXITCODE = 1 - $global:errorCode = 1 + $global:ERROR_CODE = 1 } } -} + + Write-Output "`nCompleted .NET project processing." +} function Set-BuildVersion { + Write-Output "`n--== Starting Set-BuildVersion process. ==--" + + $BUILD_VERSION = $global:BUILD_VERSION + if ($BUILD_VERSION) { + Write-Output "BUILD_VERSION is already set: $BUILD_VERSION" + return + } + $BUILD_VERSIONS_LIST = "BUILD_VERSIONS_LIST" - $inputMajorMinor = $global:inputVersion -replace "\.\d+\+$", "" + $inputMajorMinor = $global:BRANCH_NAME -replace "\.\d+\+$", "" + Write-Output "Extracted major.minor version from branch name: $inputMajorMinor" - $filteredList = $global:allVersions | Where-Object { + $filteredList = $global:ALL_VERSIONS | Where-Object { ($_ -replace "\." -as [double]) -ge ($inputMajorMinor -replace "\." -as [double]) } + Write-Output "Filtered versions list: $filteredList" $currentValue = [Environment]::GetEnvironmentVariable($BUILD_VERSIONS_LIST, [EnvironmentVariableTarget]::Machine) - $currentList = if ($currentValue) { $currentValue -split ";" } else { $filteredList } + Write-Output "Current versions list: $currentList" if ($currentList.Count -gt 1) { $inputMajorMinor = $currentList[0] $updatedList = $currentList[1..($currentList.Count - 1)] } else { - Write-Output "`nThe list in the environment variable has only one item." - $inputMajorMinor = $currentList - $updatedList = "" + Write-Output "The list in the environment variable has only one item." + $inputMajorMinor = $currentList[0] + $updatedList = @() } - $global:buildVersion = $inputMajorMinor - Write-Output "Input version: '$inputMajorMinor'" + $global:BUILD_VERSION = $inputMajorMinor + Write-Output "BUILD_VERSION set to: $global:BUILD_VERSION" $newValue = $updatedList -join ";" - [Environment]::SetEnvironmentVariable($BUILD_VERSIONS_LIST, $newValue, [EnvironmentVariableTarget]::Machine) - Write-Output "`nEnvironment variable '$BUILD_VERSIONS_LIST' has been updated." - Write-Output "New List: $updatedList" + Write-Output "Environment variable '$BUILD_VERSIONS_LIST' updated." + Write-Output "New list: $updatedList" } -Write-Output "`nBranch Name: $env:branchName" +function Write-BuildInfo { + $BRANCH_NAME = if ($global:BRANCH_NAME -ne $null) { $global:BRANCH_NAME } else { "(empty)" } + $BUILD_VERSION = if ($global:BUILD_VERSION -ne $null) { $global:BUILD_VERSION } else { "(empty)" } + + Write-Output "`nBranch Name: $BRANCH_NAME" + Write-Output "Build Version: $BUILD_VERSION" +} +Write-BuildInfo Set-BuildVersion -Process-JavaScriptProjects -buildVersion $global:buildVersion +Process-JavaScriptProjects -buildVersion $global:BUILD_VERSION Process-DotNetProjects -Write-Output "`nFinished testing. Error code: $global:errorCode" +Write-Output "`nFinished testing. Error code: $global:ERROR_CODE" -[System.Environment]::Exit($global:errorCode) +[System.Environment]::Exit($global:ERROR_CODE)