Skip to content

Commit b1690fd

Browse files
2 parents 9db1128 + 790445d commit b1690fd

File tree

2 files changed

+162
-107
lines changed

2 files changed

+162
-107
lines changed

ASP.NET Core/ASP.NET Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
</PropertyGroup>
66
<Target Name="DebugEnsureNodeEnv" BeforeTargets="BeforeBuild" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
77
<!-- Ensure Node.js is installed -->

test-example.ps1

Lines changed: 161 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,82 @@
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-
)
14+
function Test-NpmVersionExists {
15+
param ([string]$Pkg, [string]$Ver)
16+
npm view "$Pkg@$Ver" > $null 2>&1
17+
return ($LASTEXITCODE -eq 0)
18+
}
19+
20+
function Get-ValidNpmVersion {
21+
param (
22+
[string]$PackageName,
23+
[string]$Version
24+
)
25+
26+
Write-Host "Checking $PackageName@$Version..."
27+
if (Test-NpmVersionExists -Pkg $PackageName -Ver $Version) {
28+
Write-Host "$PackageName@$Version exists."
29+
return $Version
30+
}
31+
32+
try {
33+
$v = [version]$Version
34+
$fallback = "$($v.Major).$($v.Minor)-stable"
35+
} catch {
36+
Write-Host "Invalid version format: $Version"
37+
return $null
38+
}
39+
40+
Write-Host "$PackageName@$Version not found. Trying fallback: $PackageName@$fallback..."
41+
if (Test-NpmVersionExists -Pkg $PackageName -Ver $fallback) {
42+
Write-Host "$PackageName@$fallback exists (fallback)."
43+
return $fallback
44+
}
45+
46+
Write-Host "Neither $PackageName@$Version nor @$fallback exist."
47+
return $null
48+
}
3349

3450
function Install-Packages {
3551
param (
3652
[string]$folderName,
3753
[string[]]$packages,
3854
[string]$buildVersion
3955
)
56+
4057
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"
58+
59+
foreach ($package in $packages) {
60+
$packageVersion = Get-ValidNpmVersion -PackageName $package -Version $buildVersion
61+
$packageWithVersion = "$package@$packageVersion"
62+
Write-Output "Installing $packageWithVersion..."
63+
64+
npm install --save --save-exact --no-fund --loglevel=error --force $packageWithVersion
65+
if (-not $?) {
66+
Write-Error "`nERROR: Failed to install $packageWithVersion in $folderName"
67+
throw "Installation failed for $packageWithVersion in $folderName"
68+
}
4969
}
70+
71+
Write-Output "`nAll packages installed successfully in $folderName"
5072
}
5173

5274
function Build-Project {
5375
param (
5476
[string]$folderName
5577
)
5678
Write-Output "`nBuilding the project in folder: $folderName"
57-
79+
5880
npm run build
5981
if (-not $?) {
6082
Write-Error "`nERROR: Failed to build the project in $folderName"
@@ -76,7 +98,7 @@ function Process-JavaScriptProjects {
7698

7799
$jQueryEntry = @{
78100
Name = "jQuery";
79-
Packages = if ([version]$buildVersion -ge [version]23.1) { # `devextreme-dist` appeared in 23.1
101+
Packages = if ([version]$buildVersion -ge [version]23.1) {
80102
@("devextreme", "devextreme-dist")
81103
} else {
82104
@("devextreme")
@@ -98,6 +120,9 @@ function Process-JavaScriptProjects {
98120
Push-Location $folderName
99121

100122
try {
123+
Write-Output "`nRemoving node_modules & package-lock.json: $pwd"
124+
Remove-Item -Recurse -Force node_modules -ErrorAction SilentlyContinue
125+
Remove-Item -Force package-lock.json -ErrorAction SilentlyContinue
101126
Install-Packages -folderName $folderName -packages $packages -buildVersion $buildVersion
102127
Write-Output "`nInstalling remaining packages in $folderName"
103128
npm install --save --save-exact --no-fund --loglevel=error
@@ -118,110 +143,140 @@ function Process-JavaScriptProjects {
118143
Write-Output "`n--== JavaScript Projects Processing Completed ==--"
119144
}
120145

121-
function Process-DotNetProjects {
146+
function Resolve-NuGetVersionWithFallback {
122147
param (
123-
[string]$RootDirectory = "."
148+
[string]$PackageName,
149+
[string]$RequestedVersion
124150
)
125151

126-
Write-Output "`n--== Starting .NET project processing in directory: $RootDirectory ==--"
127-
128-
$slnFiles = Get-ChildItem -Path $RootDirectory -Filter *.sln -Recurse -Depth 1
152+
function Test-PackageAvailable {
153+
param ([string]$name, [string]$ver)
154+
dotnet add package $name --version $ver > $null 2>&1
155+
return ($LASTEXITCODE -eq 0)
156+
}
129157

130-
if ($slnFiles.Count -eq 0) {
131-
Write-Output "`nNo solution files (.sln) found in the specified directory at level 1."
132-
return
158+
if (Test-PackageAvailable -name $PackageName -ver $RequestedVersion) {
159+
Write-Host "$PackageName@$RequestedVersion is available."
160+
return $RequestedVersion
133161
}
134162

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
163+
Write-Host "$PackageName@$RequestedVersion not found. Checking for -beta and -alpha versions..."
141164

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"
165+
$suffixes = @("beta", "alpha")
166+
foreach ($suffix in $suffixes) {
167+
$fallbackVersion = "$RequestedVersion-$suffix"
168+
if (Test-PackageAvailable -name $PackageName -ver $fallbackVersion) {
169+
Write-Host "Found $PackageName@$fallbackVersion"
170+
return $fallbackVersion
152171
}
153172
}
154173

155-
Write-Output "`nCompleted .NET project processing."
174+
Write-Warning "No matching versions found for $PackageName@$RequestedVersion"
175+
return $null
156176
}
157177

158-
function Set-BuildVersion {
159-
Write-Output "`n--== Starting Set-BuildVersion process. ==--"
178+
function Process-AspNetCoreProject {
179+
param (
180+
[Parameter(Mandatory = $true)]
181+
[string]$buildVersion
182+
)
183+
184+
$folderPath = Get-ChildItem -Directory |
185+
Where-Object { $_.Name -match '(?i)^ASP\.NET\s*Core$' } |
186+
Select-Object -First 1 -ExpandProperty FullName
160187

161-
$BUILD_VERSION = $global:BUILD_VERSION
162-
if ($BUILD_VERSION) {
163-
Write-Output "BUILD_VERSION is already set: $BUILD_VERSION"
188+
if (-not $folderPath) {
189+
Write-Error "Directory matching 'ASP.NET Core' not found."
164190
return
165191
}
166192

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"
193+
Write-Host "Found project directory: $folderPath"
194+
Push-Location $folderPath
171195

172-
$filteredList = $global:ALL_VERSIONS | Where-Object {
173-
($_ -replace "\." -as [double]) -ge ($inputMajorMinor -replace "\." -as [double])
174-
}
175-
Write-Output "Filtered versions list: $filteredList"
196+
try {
197+
$resolvedNugetVersion = Resolve-NuGetVersionWithFallback -PackageName "DevExtreme.AspNet.Core" -RequestedVersion $buildVersion
198+
if (-not $resolvedNugetVersion) {
199+
throw "No valid version found for DevExtreme.AspNet.Core"
200+
}
176201

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"
202+
Write-Host "Installing DevExtreme.AspNet.Core@$resolvedNugetVersion..."
203+
dotnet add package DevExtreme.AspNet.Core --version $resolvedNugetVersion
204+
205+
$packageJsonPath = Get-ChildItem -Path $folderPath -Filter "package.json" -Recurse -File -ErrorAction SilentlyContinue |
206+
Select-Object -First 1 -ExpandProperty FullName
207+
208+
if ($packageJsonPath) {
209+
Write-Host "Found package.json: $packageJsonPath"
210+
211+
try {
212+
$packageJson = Get-Content -Path $packageJsonPath -Raw | ConvertFrom-Json
213+
$updated = $false
214+
215+
if ($packageJson.dependencies.devextreme) {
216+
$validDevextremeVersion = Get-ValidNpmVersion -PackageName "devextreme" -Version $buildVersion
217+
if ($validDevextremeVersion) {
218+
$packageJson.dependencies.devextreme = $validDevextremeVersion
219+
$updated = $true
220+
}
221+
}
222+
223+
if ($packageJson.dependencies.'devextreme-dist') {
224+
$validDevextremeDistVersion = Get-ValidNpmVersion -PackageName "devextreme-dist" -Version $buildVersion
225+
if ($validDevextremeDistVersion) {
226+
$packageJson.dependencies.'devextreme-dist' = $validDevextremeDistVersion
227+
$updated = $true
228+
}
229+
}
230+
231+
if ($updated) {
232+
$packageJson | ConvertTo-Json -Depth 10 | Set-Content -Path $packageJsonPath -Encoding UTF8
233+
Write-Host "Updated package.json with valid versions."
234+
} else {
235+
Write-Host "No matching dependencies found in package.json to update."
236+
}
237+
238+
Write-Host "Installing NPM dependencies..."
239+
npm install --save --save-exact --no-fund --loglevel=error
240+
if (-not $?) {
241+
throw "Failed to install npm dependencies"
242+
}
243+
} catch {
244+
Write-Error "Failed to update package.json: $_"
245+
}
246+
} else {
247+
Write-Warning "No package.json file found in '$folderPath'."
248+
}
184249

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 = @()
250+
Write-Host "Running dotnet build..."
251+
dotnet build
252+
if ($LASTEXITCODE -eq 0) {
253+
Write-Host "Build succeeded."
254+
} else {
255+
throw
256+
}
257+
} catch {
258+
Write-Error "An error occurred: $_"
259+
$global:LASTEXITCODE = 1
260+
$global:ERROR_CODE = 1
261+
$global:FAILED_PROJECTS += "ASP.NET Core"
262+
} finally {
263+
Pop-Location
192264
}
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"
202265
}
203266

204267
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)"
268+
$BUILD_VERSION = if ($global:BUILD_VERSION -ne $null -and $global:BUILD_VERSION -ne "") {
269+
$global:BUILD_VERSION
270+
} else {
271+
"(empty)"
215272
}
216273

217-
Write-Output "`nBranch Name: $BRANCH_NAME"
218274
Write-Output "Build Version: $BUILD_VERSION"
219275
}
220276

221277
Write-BuildInfo
222-
Set-BuildVersion
223278
Process-JavaScriptProjects -buildVersion $global:BUILD_VERSION
224-
Process-DotNetProjects
279+
Process-AspNetCoreProject -buildVersion $global:BUILD_VERSION
225280

226281
Write-Output "`nFinished testing version: $global:BUILD_VERSION. Error code: $global:ERROR_CODE"
227282
if ($global:ERROR_CODE -ne 0 -and $global:FAILED_PROJECTS.Count -gt 0) {

0 commit comments

Comments
 (0)