|
| 1 | +# For local testing, you can pass branchName and/or buildVersion. |
| 2 | +# If both parameters are specified, only buildVersion will be used. |
| 3 | +# Example usage: |
| 4 | +# ./test-example.ps1 -branchName 23.1.3+ |
| 5 | +# ./test-example.ps1 -buildVersion 23.1.13 |
| 6 | +param ( |
| 7 | + [string]$branchName = [Environment]::GetEnvironmentVariable("BRANCH_NAME", [EnvironmentVariableTarget]::Machine), |
| 8 | + [string]$buildVersion = [Environment]::GetEnvironmentVariable("BUILD_VERSION", [EnvironmentVariableTarget]::Machine) |
| 9 | +) |
| 10 | + |
| 11 | +# Repository's branch name, e.g. 24.1.3+ |
| 12 | +$global:BRANCH_NAME = $branchName |
| 13 | +# Masstest-specific parameter. Specifies the minor version (example: '21.1.5') !or daily build (example: '21.2.2005') |
| 14 | +$global:BUILD_VERSION = $buildVersion |
| 15 | + |
| 16 | +$global:ERROR_CODE = 0 |
| 17 | +$global:FAILED_PROJECTS = @() |
| 18 | + |
| 19 | +$global:ALL_VERSIONS = @( |
| 20 | + "14.1", "14.2", |
| 21 | + "15.1", "15.2", |
| 22 | + "16.1", "16.2", |
| 23 | + "17.1", "17.2", |
| 24 | + "18.1", "18.2", |
| 25 | + "19.1", "19.2", |
| 26 | + "20.1", "20.2", |
| 27 | + "21.1", "21.2", |
| 28 | + "22.1", "22.2", |
| 29 | + "23.1", "23.2", |
| 30 | + "24.1", "24.2", |
| 31 | + "25.1", "25.2" |
| 32 | +) |
| 33 | + |
| 34 | +function Install-Packages { |
| 35 | + param ( |
| 36 | + [string]$folderName, |
| 37 | + [string[]]$packages, |
| 38 | + [string]$buildVersion |
| 39 | + ) |
| 40 | + Write-Output "`nInstalling packages in folder: $folderName" |
| 41 | + |
| 42 | + $packageList = $packages | ForEach-Object { "$_@$buildVersion" } |
| 43 | + Write-Output "`nPackages to install: $($packageList -join ", ")" |
| 44 | + # TODO: Uninstall DevExtreme packages to avoid potential peer-dependency issues |
| 45 | + npm install @($packageList) --save --save-exact --no-fund |
| 46 | + if (-not $?) { |
| 47 | + Write-Error "`nERROR: Failed to install DevExtreme packages in $folderName" |
| 48 | + throw "Installation failed in $folderName" |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +function Build-Project { |
| 53 | + param ( |
| 54 | + [string]$folderName |
| 55 | + ) |
| 56 | + Write-Output "`nBuilding the project in folder: $folderName" |
| 57 | + |
| 58 | + npm run build |
| 59 | + if (-not $?) { |
| 60 | + Write-Error "`nERROR: Failed to build the project in $folderName" |
| 61 | + throw "Build failed in $folderName" |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +function Process-JavaScriptProjects { |
| 66 | + param ( |
| 67 | + [string]$buildVersion |
| 68 | + ) |
| 69 | + Write-Output "`n--== Starting JavaScript Projects Processing ==--" |
| 70 | + |
| 71 | + [hashtable[]]$folders = @( |
| 72 | + @{ Name = "Angular"; Packages = @("devextreme", "devextreme-angular") }, |
| 73 | + @{ Name = "React"; Packages = @("devextreme", "devextreme-react") }, |
| 74 | + @{ Name = "Vue"; Packages = @("devextreme", "devextreme-vue") } |
| 75 | + ) |
| 76 | + |
| 77 | + $jQueryEntry = @{ |
| 78 | + Name = "jQuery"; |
| 79 | + Packages = if ([version]$buildVersion -ge [version]23.1) { # `devextreme-dist` appeared in 23.1 |
| 80 | + @("devextreme", "devextreme-dist") |
| 81 | + } else { |
| 82 | + @("devextreme") |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + $folders = @($jQueryEntry) + $folders |
| 87 | + |
| 88 | + foreach ($folder in $folders) { |
| 89 | + $folderName = $folder.Name |
| 90 | + $packages = $folder.Packages |
| 91 | + |
| 92 | + if (-not (Test-Path $folderName)) { |
| 93 | + Write-Output "`nDirectory $folderName does not exist. Skipping..." |
| 94 | + continue |
| 95 | + } |
| 96 | + |
| 97 | + Write-Output "`nProcessing folder: $folderName" |
| 98 | + Push-Location $folderName |
| 99 | + |
| 100 | + try { |
| 101 | + Install-Packages -folderName $folderName -packages $packages -buildVersion $buildVersion |
| 102 | + Write-Output "`nInstalling remaining packages in $folderName" |
| 103 | + npm install --save --save-exact --no-fund --loglevel=error |
| 104 | + if (-not $?) { |
| 105 | + throw "ERROR: Failed to install remaining packages in $folderName" |
| 106 | + } |
| 107 | + Build-Project -folderName $folderName |
| 108 | + } catch { |
| 109 | + Write-Error "`nAn error occurred: $_" |
| 110 | + $global:LASTEXITCODE = 1 |
| 111 | + $global:ERROR_CODE = 1 |
| 112 | + $global:FAILED_PROJECTS += $folderName |
| 113 | + } finally { |
| 114 | + Pop-Location |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + Write-Output "`n--== JavaScript Projects Processing Completed ==--" |
| 119 | +} |
| 120 | + |
| 121 | +function Process-DotNetProjects { |
| 122 | + param ( |
| 123 | + [string]$RootDirectory = "." |
| 124 | + ) |
| 125 | + |
| 126 | + Write-Output "`n--== Starting .NET project processing in directory: $RootDirectory ==--" |
| 127 | + |
| 128 | + $slnFiles = Get-ChildItem -Path $RootDirectory -Filter *.sln -Recurse -Depth 1 |
| 129 | + |
| 130 | + if ($slnFiles.Count -eq 0) { |
| 131 | + Write-Output "`nNo solution files (.sln) found in the specified directory at level 1." |
| 132 | + return |
| 133 | + } |
| 134 | + |
| 135 | + foreach ($slnFile in $slnFiles) { |
| 136 | + Write-Output "`nFound solution file: $($slnFile.FullName)" |
| 137 | + |
| 138 | + try { |
| 139 | + Write-Output "`nBuilding solution: $($slnFile.FullName)" |
| 140 | + dotnet build $slnFile.FullName -c Release |
| 141 | + |
| 142 | + if ($?) { |
| 143 | + Write-Output "`nBuild succeeded for $($slnFile.FullName)." |
| 144 | + } else { |
| 145 | + throw "Build failed for $($slnFile.FullName)." |
| 146 | + } |
| 147 | + } catch { |
| 148 | + Write-Error "`nERROR: $_" |
| 149 | + $global:LASTEXITCODE = 1 |
| 150 | + $global:ERROR_CODE = 1 |
| 151 | + $global:FAILED_PROJECTS += "ASP.NET" |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + Write-Output "`nCompleted .NET project processing." |
| 156 | +} |
| 157 | + |
| 158 | +function Set-BuildVersion { |
| 159 | + Write-Output "`n--== Starting Set-BuildVersion process. ==--" |
| 160 | + |
| 161 | + $BUILD_VERSION = $global:BUILD_VERSION |
| 162 | + if ($BUILD_VERSION) { |
| 163 | + Write-Output "BUILD_VERSION is already set: $BUILD_VERSION" |
| 164 | + return |
| 165 | + } |
| 166 | + |
| 167 | + $BUILD_VERSIONS_LIST = "BUILD_VERSIONS_LIST" |
| 168 | + |
| 169 | + $inputMajorMinor = $global:BRANCH_NAME -replace "\.\d+\+$", "" |
| 170 | + Write-Output "Extracted major.minor version from branch name: $inputMajorMinor" |
| 171 | + |
| 172 | + $filteredList = $global:ALL_VERSIONS | Where-Object { |
| 173 | + ($_ -replace "\." -as [double]) -ge ($inputMajorMinor -replace "\." -as [double]) |
| 174 | + } |
| 175 | + Write-Output "Filtered versions list: $filteredList" |
| 176 | + |
| 177 | + $currentValue = [Environment]::GetEnvironmentVariable($BUILD_VERSIONS_LIST, [EnvironmentVariableTarget]::Machine) |
| 178 | + $currentList = if ($currentValue) { |
| 179 | + $currentValue -split ";" |
| 180 | + } else { |
| 181 | + $filteredList |
| 182 | + } |
| 183 | + Write-Output "Current versions list: $currentList" |
| 184 | + |
| 185 | + if ($currentList.Count -gt 1) { |
| 186 | + $inputMajorMinor = $currentList[0] |
| 187 | + $updatedList = $currentList[1..($currentList.Count - 1)] |
| 188 | + } else { |
| 189 | + Write-Output "The list in the environment variable has only one item." |
| 190 | + $inputMajorMinor = $currentList[0] |
| 191 | + $updatedList = @() |
| 192 | + } |
| 193 | + |
| 194 | + $global:BUILD_VERSION = $inputMajorMinor |
| 195 | + Write-Output "BUILD_VERSION set to: $global:BUILD_VERSION" |
| 196 | + |
| 197 | + $newValue = $updatedList -join ";" |
| 198 | + [Environment]::SetEnvironmentVariable($BUILD_VERSIONS_LIST, $newValue, [EnvironmentVariableTarget]::Machine) |
| 199 | + |
| 200 | + Write-Output "Environment variable '$BUILD_VERSIONS_LIST' updated." |
| 201 | + Write-Output "New list: $updatedList" |
| 202 | +} |
| 203 | + |
| 204 | +function Write-BuildInfo { |
| 205 | + $BRANCH_NAME = if ($global:BRANCH_NAME -ne $null -and $global:BRANCH_NAME -ne "") { |
| 206 | + $global:BRANCH_NAME |
| 207 | + } else { |
| 208 | + "(empty)" |
| 209 | + } |
| 210 | + |
| 211 | + $BUILD_VERSION = if ($global:BUILD_VERSION -ne $null -and $global:BUILD_VERSION -ne "") { |
| 212 | + $global:BUILD_VERSION |
| 213 | + } else { |
| 214 | + "(empty)" |
| 215 | + } |
| 216 | + |
| 217 | + Write-Output "`nBranch Name: $BRANCH_NAME" |
| 218 | + Write-Output "Build Version: $BUILD_VERSION" |
| 219 | +} |
| 220 | + |
| 221 | +Write-BuildInfo |
| 222 | +Set-BuildVersion |
| 223 | +Process-JavaScriptProjects -buildVersion $global:BUILD_VERSION |
| 224 | +Process-DotNetProjects |
| 225 | + |
| 226 | +Write-Output "`nFinished testing version: $global:BUILD_VERSION. Error code: $global:ERROR_CODE" |
| 227 | +if ($global:ERROR_CODE -ne 0 -and $global:FAILED_PROJECTS.Count -gt 0) { |
| 228 | + Write-Output "`FAILED PROJECTS: $(($global:FAILED_PROJECTS -join ", "))" |
| 229 | +} |
| 230 | + |
| 231 | +exit $global:ERROR_CODE |
0 commit comments