Skip to content

Commit 2bf4e1d

Browse files
Update test-example.ps1
1 parent 7a1748b commit 2bf4e1d

File tree

1 file changed

+21
-86
lines changed

1 file changed

+21
-86
lines changed

test-example.ps1

Lines changed: 21 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,38 @@
1-
# For local testing, you can pass branchName and/or buildVersion.
2-
# If both parameters are specified, only buildVersion will be used.
1+
# For local testing, you can pass buildVersion.
32
# Example usage:
4-
# ./test-example.ps1 -branchName 23.1.3+
53
# ./test-example.ps1 -buildVersion 23.1.13
64
param (
7-
[string]$branchName = [Environment]::GetEnvironmentVariable("BRANCH_NAME", [EnvironmentVariableTarget]::Machine),
8-
[string]$buildVersion = [Environment]::GetEnvironmentVariable("BUILD_VERSION", [EnvironmentVariableTarget]::Machine)
5+
[string]$buildVersion = $Env:CodeCentralBuildVersion
96
)
107

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')
8+
# Masstest-specific parameter. Specifies the minor version (example: '21.1.5')
149
$global:BUILD_VERSION = $buildVersion
1510

1611
$global:ERROR_CODE = 0
1712
$global:FAILED_PROJECTS = @()
1813

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-
3414
function Install-Packages {
3515
param (
3616
[string]$folderName,
3717
[string[]]$packages,
3818
[string]$buildVersion
3919
)
20+
4021
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"
22+
23+
# Loop through each package and install it individually
24+
foreach ($package in $packages) {
25+
$packageWithVersion = "$package@$buildVersion"
26+
Write-Output "Installing $packageWithVersion..."
27+
28+
npm install --save --save-exact --no-fund --loglevel=error --force $packageWithVersion
29+
if (-not $?) {
30+
Write-Error "`nERROR: Failed to install $packageWithVersion in $folderName"
31+
throw "Installation failed for $packageWithVersion in $folderName"
32+
}
4933
}
34+
35+
Write-Output "`nAll packages installed successfully in $folderName"
5036
}
5137

5238
function Build-Project {
@@ -98,6 +84,9 @@ function Process-JavaScriptProjects {
9884
Push-Location $folderName
9985

10086
try {
87+
Write-Output "`nRemoving node_modules & package-lock.json: $pwd"
88+
Remove-Item -Recurse -Force node_modules -ErrorAction SilentlyContinue
89+
Remove-Item -Force package-lock.json -ErrorAction SilentlyContinue
10190
Install-Packages -folderName $folderName -packages $packages -buildVersion $buildVersion
10291
Write-Output "`nInstalling remaining packages in $folderName"
10392
npm install --save --save-exact --no-fund --loglevel=error
@@ -155,71 +144,17 @@ function Process-DotNetProjects {
155144
Write-Output "`nCompleted .NET project processing."
156145
}
157146

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-
204147
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-
211148
$BUILD_VERSION = if ($global:BUILD_VERSION -ne $null -and $global:BUILD_VERSION -ne "") {
212149
$global:BUILD_VERSION
213150
} else {
214151
"(empty)"
215152
}
216153

217-
Write-Output "`nBranch Name: $BRANCH_NAME"
218154
Write-Output "Build Version: $BUILD_VERSION"
219155
}
220156

221157
Write-BuildInfo
222-
Set-BuildVersion
223158
Process-JavaScriptProjects -buildVersion $global:BUILD_VERSION
224159
Process-DotNetProjects
225160

@@ -228,4 +163,4 @@ if ($global:ERROR_CODE -ne 0 -and $global:FAILED_PROJECTS.Count -gt 0) {
228163
Write-Output "`FAILED PROJECTS: $(($global:FAILED_PROJECTS -join ", "))"
229164
}
230165

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

0 commit comments

Comments
 (0)