-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-example.ps1
166 lines (135 loc) · 5.15 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
# For local testing, you can pass buildVersion.
# Example usage:
# ./test-example.ps1 -buildVersion 23.1.13
param (
[string]$buildVersion = $Env:CodeCentralBuildVersion
)
# Masstest-specific parameter. Specifies the minor version (example: '21.1.5')
$global:BUILD_VERSION = $buildVersion
$global:ERROR_CODE = 0
$global:FAILED_PROJECTS = @()
function Install-Packages {
param (
[string]$folderName,
[string[]]$packages,
[string]$buildVersion
)
Write-Output "`nInstalling packages in folder: $folderName"
# Loop through each package and install it individually
foreach ($package in $packages) {
$packageWithVersion = "$package@$buildVersion"
Write-Output "Installing $packageWithVersion..."
npm install --save --save-exact --no-fund --loglevel=error --force $packageWithVersion
if (-not $?) {
Write-Error "`nERROR: Failed to install $packageWithVersion in $folderName"
throw "Installation failed for $packageWithVersion in $folderName"
}
}
Write-Output "`nAll packages installed successfully 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 {
Write-Output "`nRemoving node_modules & package-lock.json: $pwd.Path"
Remove-Item -Recurse -Force node_modules -ErrorAction SilentlyContinue
Remove-Item -Force package-lock.json -ErrorAction SilentlyContinue
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 Write-BuildInfo {
$BUILD_VERSION = if ($global:BUILD_VERSION -ne $null -and $global:BUILD_VERSION -ne "") {
$global:BUILD_VERSION
} else {
"(empty)"
}
Write-Output "Build Version: $BUILD_VERSION"
}
Write-BuildInfo
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