Skip to content

Commit 40fd829

Browse files
Update test-example.ps1
1 parent c58aca1 commit 40fd829

File tree

1 file changed

+194
-71
lines changed

1 file changed

+194
-71
lines changed

test-example.ps1

Lines changed: 194 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,231 @@
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
16
param (
2-
[string]$version = "latest"
7+
[string]$branchName = [Environment]::GetEnvironmentVariable("BRANCH_NAME", [EnvironmentVariableTarget]::Machine),
8+
[string]$buildVersion = [Environment]::GetEnvironmentVariable("BUILD_VERSION", [EnvironmentVariableTarget]::Machine)
39
)
4-
if (-not $env:buildVersion) {
5-
$global:buildVersion = "latest"
6-
} else {
7-
$global:buildVersion = $env:buildVersion
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+
}
863
}
9-
Write-Host "Build: $buildVersion"
10-
$global:errorCode = 0
1164

1265
function Process-JavaScriptProjects {
1366
param (
14-
[string]$Path = ".",
15-
[hashtable[]]$Folders = @(
16-
@{ Name = "jQuery"; Packages = @("devextreme-dist", "devextreme") },
17-
@{ Name = "Angular"; Packages = @("devextreme-angular", "devextreme") },
18-
@{ Name = "Vue"; Packages = @("devextreme-vue", "devextreme") },
19-
@{ Name = "React"; Packages = @("devextreme-react", "devextreme") }
20-
)
67+
[string]$buildVersion
2168
)
22-
Write-Host "Processing JavaScript Projects"
69+
Write-Output "`n--== Starting JavaScript Projects Processing ==--"
2370

24-
foreach ($folder in $Folders) {
25-
if (-not (Test-Path $($folder.Name))) {
26-
Write-Host "Directory $($folder.Name) does not exist. Skipping..."
27-
continue
28-
}
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+
)
2976

30-
Write-Host "`nProcessing folder: $($folder.Name)"
31-
32-
Set-Location $($folder.Name)
33-
34-
# Prepare the list of packages with their versions
35-
$packages = $folder.Packages | ForEach-Object { "$_@$global:buildVersion" }
36-
37-
# Join the package list into a single string
38-
$packageList = $packages -join " "
39-
40-
# Construct the npm install command
41-
$command = "npm install $packageList --force --save --no-fund"
42-
43-
# Output and execute the command
44-
Write-Output "Running: $command"
45-
Invoke-Expression $command
46-
47-
Write-Host "Running 'npm install' in $($folder.Name)"
48-
$installResult = & npm install --force --no-fund --loglevel=error -PassThru
49-
if ($LASTEXITCODE -ne 0) {
50-
Write-Error "npm install failed in $($folder.Name)"
51-
$global:errorCode = 1
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")
5283
}
84+
}
5385

54-
Write-Host "`nUpdating packages..."
55-
#foreach ($package in $($folder.Packages)) {
56-
# $command = "npm install $package@$global:buildVersion --save"
57-
# Write-Output "Running: $command"
58-
# Invoke-Expression $command
59-
#}
60-
86+
$folders = @($jQueryEntry) + $folders
6187

88+
foreach ($folder in $folders) {
89+
$folderName = $folder.Name
90+
$packages = $folder.Packages
6291

63-
Write-Host "Running 'npm run build' in $($folder.Name)"
64-
$buildResult = & npm run build
65-
if ($LASTEXITCODE -ne 0) {
66-
Write-Error "npm run build failed in $($folder.Name)"
67-
$global:errorCode = 1
92+
if (-not (Test-Path $folderName)) {
93+
Write-Output "`nDirectory $folderName does not exist. Skipping..."
94+
continue
6895
}
6996

70-
Set-Location ..
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+
}
71116
}
117+
118+
Write-Output "`n--== JavaScript Projects Processing Completed ==--"
72119
}
73120

74121
function Process-DotNetProjects {
75122
param (
76123
[string]$RootDirectory = "."
77124
)
78-
Write-Host "`nProcessing .NET Projects"
125+
126+
Write-Output "`n--== Starting .NET project processing in directory: $RootDirectory ==--"
79127

80128
$slnFiles = Get-ChildItem -Path $RootDirectory -Filter *.sln -Recurse -Depth 1
81129

82130
if ($slnFiles.Count -eq 0) {
83-
Write-Host "No solution files (.sln) found in the specified directory at level 1."
84-
$global:errorCode = 1
131+
Write-Output "`nNo solution files (.sln) found in the specified directory at level 1."
85132
return
86133
}
87134

88135
foreach ($slnFile in $slnFiles) {
89-
Write-Host "Found solution file: $($slnFile.FullName)"
136+
Write-Output "`nFound solution file: $($slnFile.FullName)"
90137

91-
dotnet build $slnFile.FullName -c Release
92-
93-
if ($LASTEXITCODE -eq 0) {
94-
Write-Host "Build succeeded for $($slnFile.FullName)."
95-
} else {
96-
Write-Error "Build failed for $($slnFile.FullName)."
97-
$global:errorCode = 1
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"
98152
}
99153
}
100-
}
101154

102-
Write-Host "Version: $global:buildVersion"
103-
Process-JavaScriptProjects
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
104224
Process-DotNetProjects
105225

106-
Write-Host "Error code: $global:errorCode"
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+
}
107230

108-
exit $global:errorCode
231+
[System.Environment]::Exit($global:ERROR_CODE)

0 commit comments

Comments
 (0)