Skip to content

Commit 285423f

Browse files
authored
Edit MinimalVersion.csv in batch (#25997)
1 parent 64f9db2 commit 285423f

File tree

3 files changed

+103
-39
lines changed

3 files changed

+103
-39
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Param(
2+
[Parameter()]
3+
[ValidateSet("Major", "MINOR", "PATCH", "NONE")]
4+
[System.String]
5+
$VersionBump = "MINOR",
6+
[Parameter()]
7+
[System.String]
8+
$MinimalVersionFilePath = "$PSScriptRoot/../VersionController/MinimalVersion.csv"
9+
)
10+
Import-Module -Name "$PSScriptRoot/VersionBumpUtils.psm1" -Force
11+
12+
if(-not (Test-Path -Path $MinimalVersionFilePath)){
13+
throw "$MinimalVersionFilePath does not exist"
14+
}
15+
$file = [System.IO.File]::ReadAllLines($MinimalVersionFilePath)
16+
$header = $file[0]
17+
$lines = $file | Select-Object -Skip 1 | Where-Object {-not [System.String]::IsNullOrWhiteSpace($_)}
18+
$minimalVersionContent = @($header)
19+
20+
# Read existing minimal versions
21+
$minimalVersionHashTable = @{}
22+
foreach ($line in $lines)
23+
{
24+
$cols = $line.Split(",")
25+
if($cols.Count -ge 2){
26+
# Remove the first and last quote
27+
$key = $cols[0].Substring(1, $cols[0].Length - 2)
28+
$value = $cols[1].Substring(1, $cols[1].Length - 2)
29+
$minimalVersionHashTable[$key] = $value
30+
}
31+
}
32+
33+
$az = Import-PowerShellDataFile -Path "$PSScriptRoot/../Az/Az.psd1"
34+
foreach ($module in $az.RequiredModules)
35+
{
36+
$moduleName = $module.ModuleName
37+
$moduleVersion = $module.RequiredVersion
38+
# Az.Accounts uses ModuleVersion to annote Version
39+
if ([string]::IsNullOrEmpty($moduleVersion))
40+
{
41+
$moduleVersion = $module.ModuleVersion
42+
}
43+
$minimalModuleVersion = Get-BumpedVersion -Version $moduleVersion -VersionBump $VersionBump
44+
45+
if($minimalVersionHashTable.Contains($moduleName) -and [System.Version]$minimalVersionHashTable[$moduleName] -gt [System.Version]$minimalModuleVersion)
46+
{
47+
$minimalModuleVersion = $minimalVersionHashTable[$moduleName]
48+
}
49+
50+
$minimalVersionHashTable[$moduleName] = $minimalModuleVersion
51+
}
52+
$minimalVersionHashTable.GetEnumerator() | ForEach-Object {
53+
$minimalVersionContent += """$($_.Key)"",""$($_.Value)"""
54+
}
55+
Set-Content -Path $MinimalVersionFilePath -Value $minimalVersionContent -Encoding UTF8
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
enum PSVersion
2+
{
3+
NONE = 0
4+
PATCH = 1
5+
MINOR = 2
6+
MAJOR = 3
7+
}
8+
9+
function Get-BumpedVersion
10+
{
11+
Param(
12+
[Parameter(Mandatory = $true)]
13+
[string]$Version,
14+
[Parameter(Mandatory = $true)]
15+
[PSVersion]$VersionBump
16+
)
17+
18+
$versionSplit = $Version.Split('.')
19+
if ($VersionBump -eq [PSVersion]::MAJOR)
20+
{
21+
$versionSplit[0] = 1 + $versionSplit[0]
22+
$versionSplit[1] = "0"
23+
$versionSplit[2] = "0"
24+
}
25+
elseif ($VersionBump -eq [PSVersion]::MINOR)
26+
{
27+
$versionSplit[1] = 1 + $versionSplit[1]
28+
$versionSplit[2] = "0"
29+
}
30+
elseif ($VersionBump -eq [PSVersion]::PATCH)
31+
{
32+
$versionSplit[2] = 1 + $versionSplit[2]
33+
}
34+
35+
return $versionSplit -join "."
36+
}

tools/RunVersionController.ps1

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Param(
2828
[string]$ReleaseType = "STS"
2929
)
3030

31+
Import-Module -Name "$PSScriptRoot/ReleaseTools/VersionBumpUtils.psm1" -Force
32+
3133
enum PSVersion
3234
{
3335
NONE = 0
@@ -64,35 +66,6 @@ function Get-VersionBump
6466
return [PSVersion]::NONE
6567
}
6668

67-
function Get-BumpedVersion
68-
{
69-
Param(
70-
[Parameter(Mandatory = $true)]
71-
[string]$Version,
72-
[Parameter(Mandatory = $true)]
73-
[PSVersion]$VersionBump
74-
)
75-
76-
$versionSplit = $Version.Split('.')
77-
if ($VersionBump -eq [PSVersion]::MAJOR)
78-
{
79-
$versionSplit[0] = 1 + $versionSplit[0]
80-
$versionSplit[1] = "0"
81-
$versionSplit[2] = "0"
82-
}
83-
elseif ($VersionBump -eq [PSVersion]::MINOR)
84-
{
85-
$versionSplit[1] = 1 + $versionSplit[1]
86-
$versionSplit[2] = "0"
87-
}
88-
elseif ($VersionBump -eq [PSVersion]::PATCH)
89-
{
90-
$versionSplit[2] = 1 + $versionSplit[2]
91-
}
92-
93-
return $versionSplit -join "."
94-
}
95-
9669
function Update-AzurecmdFile
9770
{
9871
Param(
@@ -312,7 +285,7 @@ function Bump-AzVersion
312285
function Update-AzPreview
313286
{
314287
# The version of AzPrview aligns with Az
315-
$AzPrviewVersion = (Import-PowerShellDataFile "$PSScriptRoot\Az\Az.psd1").ModuleVersion
288+
$AzPreviewVersion = (Import-PowerShellDataFile "$PSScriptRoot\Az\Az.psd1").ModuleVersion
316289

317290
$requiredModulesString = "RequiredModules = @("
318291
$rawRequiredModulesString = "RequiredModules = @\("
@@ -332,21 +305,21 @@ function Update-AzPreview
332305
$requiredModulesString = $requiredModulesString.Trim()
333306
$requiredModulesString = $requiredModulesString.TrimEnd(",")
334307

335-
$AzPrviewTemplate = Get-Item -Path "$PSScriptRoot\AzPreview.psd1.template"
336-
$AzPrviewTemplateContent = Get-Content -Path $AzPrviewTemplate.FullName
337-
$AzPreviewPsd1Content = $AzPrviewTemplateContent | % {
338-
$_ -replace "ModuleVersion = 'x.x.x'", "ModuleVersion = '$AzPrviewVersion'"
308+
$AzPreviewTemplate = Get-Item -Path "$PSScriptRoot\AzPreview.psd1.template"
309+
$AzPreviewTemplateContent = Get-Content -Path $AzPreviewTemplate.FullName
310+
$AzPreviewPsd1Content = $AzPreviewTemplateContent | % {
311+
$_ -replace "ModuleVersion = 'x.x.x'", "ModuleVersion = '$AzPreviewVersion'"
339312
} | % {
340313
$_ -replace "$rawRequiredModulesString", "$requiredModulesString"
341314
}
342315

343-
$AzPrviewPsd1 = New-Item -Path "$PSScriptRoot\AzPreview\" -Name "AzPreview.psd1" -ItemType "file" -Force
344-
Set-Content -Path $AzPrviewPsd1.FullName -Value $AzPreviewPsd1Content -Encoding UTF8
316+
$AzPreviewPsd1 = New-Item -Path "$PSScriptRoot\AzPreview\" -Name "AzPreview.psd1" -ItemType "file" -Force
317+
Set-Content -Path $AzPreviewPsd1.FullName -Value $AzPreviewPsd1Content -Encoding UTF8
345318
}
346319

347320
function Update-AzPreviewChangelog
348321
{
349-
$AzPrviewVersion = (Import-PowerShellDataFile "$PSScriptRoot\Az\Az.psd1").ModuleVersion
322+
$AzPreviewVersion = (Import-PowerShellDataFile "$PSScriptRoot\Az\Az.psd1").ModuleVersion
350323
$localAz = Import-PowerShellDataFile -Path "$PSScriptRoot\AzPreview\AzPreview.psd1"
351324
Write-Host "Getting gallery AzPreview information..." -ForegroundColor Yellow
352325
$galleryAz = Find-Module -Name AzPreview -Repository $GalleryName
@@ -381,9 +354,9 @@ function Update-AzPreviewChangelog
381354
}
382355

383356
$releaseNotes = @()
384-
$releaseNotes += "$AzPrviewVersion - $Release"
357+
$releaseNotes += "$AzPreviewVersion - $Release"
385358
$changeLog = @()
386-
$changeLog += "## $AzPrviewVersion - $Release"
359+
$changeLog += "## $AzPreviewVersion - $Release"
387360
$rootPath = "$PSScriptRoot\.."
388361
foreach ($updatedModule in $updatedModules)
389362
{

0 commit comments

Comments
 (0)