-
Notifications
You must be signed in to change notification settings - Fork 6
/
test-example.ps1
231 lines (191 loc) · 7.28 KB
/
test-example.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# 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:FAILED_PROJECTS = @()
$global:ALL_VERSIONS = @(
"14.1", "14.2",
"15.1", "15.2",
"16.1", "16.2",
"17.1", "17.2",
"18.1", "18.2",
"19.1", "19.2",
"20.1", "20.2",
"21.1", "21.2",
"22.1", "22.2",
"23.1", "23.2",
"24.1", "24.2",
"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--== Starting JavaScript Projects Processing ==--"
[hashtable[]]$folders = @(
@{ Name = "Angular"; Packages = @("devextreme", "devextreme-angular") },
@{ Name = "React"; Packages = @("devextreme", "devextreme-react") },
@{ Name = "Vue"; Packages = @("devextreme", "devextreme-vue") }
)
$jQueryEntry = @{
Name = "jQuery";
Packages = if ([version]$buildVersion -ge [version]23.1) { # `devextreme-dist` appeared in 23.1
@("devextreme", "devextreme-dist")
} else {
@("devextreme")
}
}
$folders = @($jQueryEntry) + $folders
foreach ($folder in $folders) {
$folderName = $folder.Name
$packages = $folder.Packages
if (-not (Test-Path $folderName)) {
Write-Output "`nDirectory $folderName does not exist. Skipping..."
continue
}
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:ERROR_CODE = 1
$global:FAILED_PROJECTS += $folderName
} finally {
Pop-Location
}
}
Write-Output "`n--== JavaScript Projects Processing Completed ==--"
}
function Process-DotNetProjects {
param (
[string]$RootDirectory = "."
)
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."
return
}
foreach ($slnFile in $slnFiles) {
Write-Output "`nFound solution file: $($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:ERROR_CODE = 1
$global:FAILED_PROJECTS += "ASP.NET"
}
}
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:BRANCH_NAME -replace "\.\d+\+$", ""
Write-Output "Extracted major.minor version from branch name: $inputMajorMinor"
$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 "The list in the environment variable has only one item."
$inputMajorMinor = $currentList[0]
$updatedList = @()
}
$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 "Environment variable '$BUILD_VERSIONS_LIST' updated."
Write-Output "New list: $updatedList"
}
function Write-BuildInfo {
$BRANCH_NAME = if ($global:BRANCH_NAME -ne $null -and $global:BRANCH_NAME -ne "") {
$global:BRANCH_NAME
} else {
"(empty)"
}
$BUILD_VERSION = if ($global:BUILD_VERSION -ne $null -and $global:BUILD_VERSION -ne "") {
$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:BUILD_VERSION
Process-DotNetProjects
Write-Output "`nFinished testing version: $global:BUILD_VERSION. Error code: $global:ERROR_CODE"
if ($global:ERROR_CODE -ne 0 -and $global:FAILED_PROJECTS.Count -gt 0) {
Write-Output "`FAILED PROJECTS: $(($global:FAILED_PROJECTS -join ", "))"
}
exit $global:ERROR_CODE