Skip to content

Commit

Permalink
Merge pull request #5 from DevExpress-Examples/update-ps-script
Browse files Browse the repository at this point in the history
Update test-example.ps1
  • Loading branch information
SavchenkoAlexander authored Dec 11, 2024
2 parents 770c7c6 + ded9442 commit a0fd1d1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 13 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- default badges list -->
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/800447205/23.1.3%2B)
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T1233410)
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
Expand Down
76 changes: 64 additions & 12 deletions test-example.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@ param (
[string]$version = "latest"
)
if (-not $env:buildVersion) {
$global:buildVersion = "24.1.7"
$global:buildVersion = $version
} else {
$global:buildVersion = $env:buildVersion
}
Write-Host "Build: $buildVersion"
Write-Host "Build: $inputVersion"
$global:inputVersion = $env:branchName
$global:errorCode = 0

$BUILD_VERSIONS_LIST = "BUILD_VERSIONS_LIST"

$allVersions = @(
"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"
)

function Process-JavaScriptProjects {
param (
[string]$Path = ".",
Expand All @@ -19,40 +35,44 @@ function Process-JavaScriptProjects {
@{ Name = "React"; Packages = @("devextreme-react", "devextreme") }
)
)
Write-Host "Processing JavaScript Projects"
Write-Host "`n--== Processing JavaScript Projects ==--"

foreach ($folder in $Folders) {
if (-not (Test-Path $($folder.Name))) {
Write-Host "Directory $($folder.Name) does not exist. Skipping..."
continue
}

Write-Host "`nProcessing folder: $($folder.Name)"
Write-Host "`n<-- Processing folder: $($folder.Name) -->"

Set-Location $($folder.Name)

# Prepare the list of packages with their versions
$packages = $folder.Packages | ForEach-Object { "$_@$global:buildVersion" }

# Join the package list into a single string
$packageList = $packages -join " "

# Construct the npm install command
$command = "npm install $packageList --force --save --no-fund"

# Output and execute the command
Write-Output "Running: $command"
Invoke-Expression $command

Write-Host "Running 'npm install' in $($folder.Name)"
$installResult = & npm install --force --no-fund --loglevel=error -PassThru
if ($LASTEXITCODE -ne 0) {
Write-Error "npm install failed in $($folder.Name)"
Write-Error "ERROR: npm install failed in $($folder.Name)"
$global:errorCode = 1
}

Write-Host "`nUpdating packages..."
Write-Host "`n<-- Updating packages... -->"

Write-Host "Running 'npm run build' in $($folder.Name)"
$buildResult = & npm run build
if ($LASTEXITCODE -ne 0) {
Write-Error "npm run build failed in $($folder.Name)"
Write-Error "ERROR: npm run build failed in $($folder.Name)"
$global:errorCode = 1
}

Expand All @@ -70,7 +90,7 @@ function Process-DotNetProjects {

if ($slnFiles.Count -eq 0) {
Write-Host "No solution files (.sln) found in the specified directory at level 1."
$global:errorCode = 1
$global:errorCode = 0
return
}

Expand All @@ -88,11 +108,43 @@ function Process-DotNetProjects {
}
}

Write-Host "Version: $global:buildVersion"
Write-Host "BUILD_NUMBER: $env:BUILD_NUMBER"
Write-Host "BUILD_ID: $env:BUILD_ID"
Write-Host "BUILD_DISPLAY_NAME: $env:BUILD_DISPLAY_NAME"
function Set-BuildVersion {
$inputMajorMinor = $global:inputVersion -replace "\.\d+\+$", ""

$filteredList = $allVersions | Where-Object {
($_ -replace "\." -as [double]) -ge ($inputMajorMinor -replace "\." -as [double])
}

$currentValue = [Environment]::GetEnvironmentVariable($BUILD_VERSIONS_LIST, [EnvironmentVariableTarget]::Machine)

$currentList = if ($currentValue) {
$currentValue -split ";"
} else {
$filteredList
}

if ($currentList.Count -gt 1) {
$inputMajorMinor = $currentList[0]
Write-Output "Input version: '$inputMajorMinor'"
$global:buildVersion = $inputMajorMinor

$updatedList = $currentList[1..($currentList.Count - 1)]
} else {
Write-Output "The list in the environment variable is empty or has only one item. Resetting to the filtered list."
$updatedList = $filteredList
}

$newValue = $updatedList -join ";"

[Environment]::SetEnvironmentVariable($BUILD_VERSIONS_LIST, $newValue, [EnvironmentVariableTarget]::Machine)

Write-Output "Environment variable '$BUILD_VERSIONS_LIST' has been updated."
Write-Output "New List: $updatedList"
}

Write-Host "`nBranch Name: $global:branchName"

Set-BuildVersion
Process-JavaScriptProjects
Process-DotNetProjects

Expand Down

0 comments on commit a0fd1d1

Please sign in to comment.