forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunVersionController.ps1
543 lines (473 loc) · 20.1 KB
/
RunVersionController.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# To version all modules in Az (standard release), run the following command: .\RunVersionController.ps1 -Release "December 2017"
# To version a single module (one-off release), run the following command: .\RunVersionController.ps1 -ModuleName "Az.Compute"
#Requires -Modules @{ModuleName="PowerShellGet"; ModuleVersion="2.2.1"}
[CmdletBinding(DefaultParameterSetName="ReleaseAz")]
Param(
[Parameter(ParameterSetName='ReleaseAz', Mandatory = $true)]
[string]$Release,
[Parameter(ParameterSetName='ReleaseAzByMonthAndYear', Mandatory = $true)]
[string]$MonthName,
[Parameter(ParameterSetName='ReleaseAzByMonthAndYear', Mandatory = $true)]
[string]$Year,
[Parameter(ParameterSetName='ReleaseSingleModule', Mandatory = $true)]
[string]$ModuleName,
[Parameter()]
[string]$GalleryName = "PSGallery",
[Parameter()]
[string]$ArtifactsOutputPath = "$PSScriptRoot/../artifacts/Release/"
)
enum PSVersion
{
NONE = 0
PATCH = 1
MINOR = 2
MAJOR = 3
}
function Get-VersionBump
{
Param(
[Parameter(Mandatory = $true)]
[string]$GalleryVersion,
[Parameter(Mandatory = $true)]
[string]$LocalVersion
)
$gallerySplit = $GalleryVersion.Split('.')
$localSplit = $LocalVersion.Split('.')
if ($gallerySplit[0] -ne $localSplit[0])
{
return [PSVersion]::MAJOR
}
elseif ($gallerySplit[1] -ne $localSplit[1])
{
return [PSVersion]::MINOR
}
elseif ($gallerySplit[2] -ne $localSplit[2])
{
return [PSVersion]::PATCH
}
return [PSVersion]::NONE
}
function Get-BumpedVersion
{
Param(
[Parameter(Mandatory = $true)]
[string]$Version,
[Parameter(Mandatory = $true)]
[PSVersion]$VersionBump
)
$versionSplit = $Version.Split('.')
if ($VersionBump -eq [PSVersion]::MAJOR)
{
$versionSplit[0] = 1 + $versionSplit[0]
$versionSplit[1] = "0"
$versionSplit[2] = "0"
}
elseif ($VersionBump -eq [PSVersion]::MINOR)
{
$versionSplit[1] = 1 + $versionSplit[1]
$versionSplit[2] = "0"
}
elseif ($VersionBump -eq [PSVersion]::PATCH)
{
$versionSplit[2] = 1 + $versionSplit[2]
}
return $versionSplit -join "."
}
function Update-AzurecmdFile
{
Param(
[Parameter(Mandatory = $true)]
[string]$OldVersion,
[Parameter(Mandatory = $true)]
[string]$NewVersion,
[Parameter(Mandatory = $true)]
[string]$Release,
[Parameter(Mandatory = $true)]
[string]$RootPath
)
$AzurecmdFile = Get-Item -Path "$RootPath\setup\generate.ps1"
(Get-Content $AzurecmdFile.FullName) | % {
$_ -replace "Microsoft Azure PowerShell - (\w*)(\s)(\d*)", "Microsoft Azure PowerShell - $Release"
} | Set-Content -Path $AzurecmdFile.FullName -Encoding UTF8
(Get-Content $AzurecmdFile.FullName) | % {
$_ -replace "$OldVersion", "$NewVersion"
} | Set-Content -Path $AzurecmdFile.FullName -Encoding UTF8
}
function Update-AzurePowerShellFile
{
Param(
[Parameter(Mandatory = $true)]
[string]$OldVersion,
[Parameter(Mandatory = $true)]
[string]$NewVersion,
[Parameter(Mandatory = $true)]
[string]$RootPath
)
$AzurePowerShellFile = Get-Item -Path "$RootPath\src\Common\Commands.Common\AzurePowerShell.cs"
(Get-Content $AzurePowerShellFile.FullName) | % {
$_ -replace "$OldVersion", "$NewVersion"
} | Set-Content -Path $AzurePowerShellFile.FullName -Encoding UTF8
}
function Get-ModuleMetadata
{
Param(
[Parameter(Mandatory = $true)]
[string]$Module,
[Parameter(Mandatory = $true)]
[string]$RootPath
)
$ProjectPaths = @( "$RootPath\src" )
.($PSScriptRoot + "\PreloadToolDll.ps1")
$ModuleManifestFile = $ProjectPaths | % { Get-ChildItem -Path $_ -Filter "*.psd1" -Recurse | where { $_.Name.Replace(".psd1", "") -eq $Module -and `
# Skip psd1 of generated modules in HYBRID modules because they are not really used
# This is based on an assumption that the path of the REAL psd1 of a HYBRID module should always not contain "Autorest"
$_.FullName -inotlike "*autorest*" -and `
$_.FullName -notlike "*Debug*" -and `
$_.FullName -notlike "*Netcore*" -and `
$_.FullName -notlike "*dll-Help.psd1*" -and `
(-not [Tools.Common.Utilities.ModuleFilter]::IsAzureStackModule($_.FullName)) } }
if($ModuleManifestFile.Count -gt 1)
{
$ModuleManifestFile = $ModuleManifestFile[0]
}
Import-LocalizedData -BindingVariable ModuleMetadata -BaseDirectory $ModuleManifestFile.DirectoryName -FileName $ModuleManifestFile.Name
return $ModuleMetadata
}
function Update-ChangeLog
{
Param(
[Parameter(Mandatory = $true)]
[string[]]$Content,
[Parameter(Mandatory = $true)]
[string]$FilePath
)
$ChangeLogFile = Get-Item -Path $FilePath
$ChangeLogContent = Get-Content -Path $ChangeLogFile.FullName
($Content + $ChangeLogContent) | Set-Content -Path $ChangeLogFile.FullName -Encoding UTF8
}
function Update-Image-Releases
{
Param(
[Parameter(Mandatory = $true)]
[string]$ReleaseProps,
[Parameter(Mandatory = $true)]
[string]$AzVersion
)
$content = Get-Content $ReleaseProps
$content -Replace "az.version=\d+\.\d+\.\d+", "az.version=$AzVersion" | Set-Content $ReleaseProps
}
function Get-ExistSerializedCmdletJsonFile
{
return $(ls "$PSScriptRoot\Tools.Common\SerializedCmdlets").Name
}
function Bump-AzVersion
{
Write-Host "Getting local Az information..." -ForegroundColor Yellow
$localAz = Import-PowerShellDataFile -Path "$PSScriptRoot\Az\Az.psd1"
Write-Host "Getting gallery Az information..." -ForegroundColor Yellow
$galleryAz = Find-Module -Name Az -Repository $GalleryName
$versionBump = [PSVersion]::NONE
$updatedModules = @()
foreach ($localDependency in $localAz.RequiredModules)
{
$galleryDependency = $galleryAz.Dependencies | where { $_.Name -eq $localDependency.ModuleName }
if ($null -eq $galleryDependency)
{
$updatedModules += $localDependency.ModuleName
if ($versionBump -ne [PSVersion]::MAJOR)
{
$versionBump = [PSVersion]::MINOR
}
Write-Host "Found new added module $($localDependency.ModuleName)"
continue
}
$galleryVersion = $galleryDependency.RequiredVersion
if ([string]::IsNullOrEmpty($galleryVersion))
{
$galleryVersion = $galleryDependency.MinimumVersion
}
$localVersion = $localDependency.RequiredVersion
# Az.Accounts uses ModuleVersion to annote Version
if ([string]::IsNullOrEmpty($localVersion))
{
$localVersion = $localDependency.ModuleVersion
}
if ($galleryVersion.ToString() -ne $localVersion)
{
$updatedModules += $localDependency.ModuleName
$currBump = Get-VersionBump -GalleryVersion $galleryVersion.ToString() -LocalVersion $localVersion
Write-Host "Found $currBump version bump for $($localDependency.ModuleName)"
if ($currBump -eq [PSVersion]::MAJOR)
{
$versionBump = [PSVersion]::MAJOR
}
elseif ($currBump -eq [PSVersion]::MINOR -and $versionBump -ne [PSVersion]::MAJOR)
{
$versionBump = [PSVersion]::MINOR
}
elseif ($currBump -eq [PSVersion]::PATCH -and $versionBump -eq [PSVersion]::NONE)
{
$versionBump = [PSVersion]::PATCH
}
}
}
if ($versionBump -eq [PSVersion]::NONE)
{
Write-Host "No changes found in Az." -ForegroundColor Green
return
}
$newVersion = Get-BumpedVersion -Version $localAz.ModuleVersion -VersionBump $versionBump
Write-Host "New version of Az: $newVersion" -ForegroundColor Green
$rootPath = "$PSScriptRoot\.."
$oldVersion = $galleryAz.Version
Update-AzurecmdFile -OldVersion $oldVersion -NewVersion $newVersion -Release $Release -RootPath $rootPath
# This was moved to the common repo
# Update-AzurePowerShellFile -OldVersion $oldVersion -NewVersion $newVersion -RootPath $rootPath
$releaseNotes = @()
$releaseNotes += "$newVersion - $Release"
$changeLog = @()
$changeLog += "## $newVersion - $Release"
foreach ($updatedModule in $updatedModules)
{
$moduleMetadata = $(Get-ModuleMetadata -Module $updatedModule -RootPath $rootPath)
$moduleReleaseNotes = $moduleMetadata.PrivateData.PSData.ReleaseNotes
$releaseNotes += $updatedModule
$releaseNotes += $moduleReleaseNotes + "`n"
$changeLog += "#### $updatedModule $($moduleMetadata.ModuleVersion)"
$changeLog += $moduleReleaseNotes + "`n"
}
$resolvedArtifactsOutputPath = (Resolve-Path $ArtifactsOutputPath).Path
if(!(Test-Path $resolvedArtifactsOutputPath))
{
throw "Please check artifacts output path: $resolvedArtifactsOutputPath whether exists."
}
# Update-ModuleManifest requires all required modules in Az.psd1 installed in local
# Add artifacts as PSModulePath to skip installation
if(!($env:PSModulePath.Split(";").Contains($resolvedArtifactsOutputPath)))
{
$env:PSModulePath += ";$resolvedArtifactsOutputPath"
}
Update-ModuleManifest -Path "$PSScriptRoot\Az\Az.psd1" -ModuleVersion $newVersion -ReleaseNotes $releaseNotes
Update-ChangeLog -Content $changeLog -FilePath "$rootPath\ChangeLog.md"
New-CommandMappingFile
return $versionBump
}
function Update-AzPreview
{
# The version of AzPrview aligns with Az
$AzPrviewVersion = (Import-PowerShellDataFile "$PSScriptRoot\Az\Az.psd1").ModuleVersion
$requiredModulesString = "RequiredModules = @("
$rawRequiredModulesString = "RequiredModules = @\("
foreach ($Psd1FilePath in (Get-Psd1Path)) {
$Psd1Object = Import-PowerShellDataFile $Psd1FilePath
$moduleName = [System.IO.Path]::GetFileName($Psd1FilePath) -replace ".psd1"
$moduleVersion = $Psd1Object.ModuleVersion.ToString()
if('Az.Accounts' -eq $moduleName)
{
$requiredModulesString += "@{ModuleName = '$moduleName'; ModuleVersion = '$moduleVersion'; }, `n "
}
else
{
$requiredModulesString += "@{ModuleName = '$moduleName'; RequiredVersion = '$moduleVersion'; }, `n "
}
}
$requiredModulesString = $requiredModulesString.Trim()
$requiredModulesString = $requiredModulesString.TrimEnd(",")
$AzPrviewTemplate = Get-Item -Path "$PSScriptRoot\AzPreview.psd1.template"
$AzPrviewTemplateContent = Get-Content -Path $AzPrviewTemplate.FullName
$AzPreviewPsd1Content = $AzPrviewTemplateContent | % {
$_ -replace "ModuleVersion = 'x.x.x'", "ModuleVersion = '$AzPrviewVersion'"
} | % {
$_ -replace "$rawRequiredModulesString", "$requiredModulesString"
}
$AzPrviewPsd1 = New-Item -Path "$PSScriptRoot\AzPreview\" -Name "AzPreview.psd1" -ItemType "file" -Force
Set-Content -Path $AzPrviewPsd1.FullName -Value $AzPreviewPsd1Content -Encoding UTF8
}
function Update-AzPreviewChangelog
{
$AzPrviewVersion = (Import-PowerShellDataFile "$PSScriptRoot\Az\Az.psd1").ModuleVersion
$localAz = Import-PowerShellDataFile -Path "$PSScriptRoot\AzPreview\AzPreview.psd1"
Write-Host "Getting gallery AzPreview information..." -ForegroundColor Yellow
$galleryAz = Find-Module -Name AzPreview -Repository $GalleryName
$updatedModules = @()
foreach ($localDependency in $localAz.RequiredModules)
{
$galleryDependency = $galleryAz.Dependencies | where { $_.Name -eq $localDependency.ModuleName }
if ($null -eq $galleryDependency)
{
$updatedModules += $localDependency.ModuleName
Write-Host "Found new added module $($localDependency.ModuleName)"
continue
}
$galleryVersion = $galleryDependency.RequiredVersion
if ([string]::IsNullOrEmpty($galleryVersion))
{
$galleryVersion = $galleryDependency.MinimumVersion
}
$localVersion = $localDependency.RequiredVersion
# Az.Accounts uses ModuleVersion to annote Version
if ([string]::IsNullOrEmpty($localVersion))
{
$localVersion = $localDependency.ModuleVersion
}
if ($galleryVersion.ToString() -ne $localVersion)
{
$updatedModules += $localDependency.ModuleName
}
}
$releaseNotes = @()
$releaseNotes += "$AzPrviewVersion - $Release"
$changeLog = @()
$changeLog += "## $AzPrviewVersion - $Release"
$rootPath = "$PSScriptRoot\.."
foreach ($updatedModule in $updatedModules)
{
$moduleMetadata = $(Get-ModuleMetadata -Module $updatedModule -RootPath $rootPath)
if ($moduleMetadata.ModuleVersion -eq '0.1.0') {
$moduleReleaseNotes = "* First preview release for module $updatedModule"
} else {
$moduleReleaseNotes = $moduleMetadata.PrivateData.PSData.ReleaseNotes
}
$releaseNotes += $updatedModule
$releaseNotes += $moduleReleaseNotes + "`n"
$changeLog += "#### $updatedModule $($moduleMetadata.ModuleVersion)"
$changeLog += $moduleReleaseNotes + "`n"
}
Update-ChangeLog -Content $changeLog -FilePath "$rootPath/tools/AzPreview/ChangeLog.md"
}
function Update-AzSyntaxChangelog
{
Write-Host "starting revise SyntaxChangeLog"
$rootPath = "$PSScriptRoot\.."
$NewVersion = (Import-PowerShellDataFile "$PSScriptRoot\Az\Az.psd1").ModuleVersion
$majorVersion = $NewVersion.Split('.')[0]
$syntaxChangeLog = "$rootPath\documentation\SyntaxChangeLog\SyntaxChangeLog.md"
Update-ChangeLog -Content "## $NewVersion - $Release" -FilePath $syntaxChangeLog
$changeLog = Get-Content $syntaxChangeLog -Raw
$targetFile = "$rootPath\documentation\SyntaxChangeLog\SyntaxChangeLog-Az$majorVersion.md"
if (-not (Test-Path $targetFile)) {
New-Item -Path $targetFile -ItemType File
}
$regex = '####\s+(Az\.\w+)\s+(?![\d\.])'
$matches = Select-String -Pattern $regex -InputObject $changelog -AllMatches
foreach ($match in $matches.Matches) {
$moduleName = $match.Groups[1].Value
$moduleMetadata = Get-ModuleMetadata -Module $moduleName -RootPath $rootPath
$newVersion = $moduleMetadata.ModuleVersion
$replacement = "#### $moduleName $newVersion `r`n"
$changelog = $changelog -replace [regex]::Escape($match.Value), $replacement
}
$currentContent = Get-Content -Path $targetFile -Raw
$newContent = $changeLog + "`r`n" + $currentContent
Set-Content -Path $targetFile -Value $newContent
Remove-Item -Path $syntaxChangeLog
}
function New-CommandMappingFile
{
# Regenerate the cmdlet-to-module mappings for the recommendation feature of uninstalled modules
$MappingsFilePath = "$PSScriptRoot\..\src\Accounts\Accounts\Utilities\CommandMappings.json"
Write-Host "Generating command mapping file at $MappingsFilePath"
$content = Get-Content $MappingsFilePath | ConvertFrom-Json -Depth 10
$content.modules = [ordered]@{}
foreach ($Psd1FilePath in (Get-Psd1Path))
{
$Psd1Object = Import-PowerShellDataFile $Psd1FilePath
$moduleName = [System.IO.Path]::GetFileName($Psd1FilePath) -replace ".psd1"
$moduleObject = [ordered]@{}
$Psd1Object.CmdletsToExport | Where-Object {$null -ne $_ -and "*" -ne $_} | ForEach-Object {
$moduleObject[$_] = @{}
}
$Psd1Object.FunctionsToExport | Where-Object {$null -ne $_ -and "*" -ne $_} | ForEach-Object {
$moduleObject[$_] = @{}
}
$Psd1Object.AliasesToExport | Where-Object {$null -ne $_ -and "*" -ne $_}| ForEach-Object {
$moduleObject[$_] = @{}
}
if ($moduleObject.Count -gt 0) {
$content.modules[$moduleName] = $moduleObject
}
}
Set-Content -Path $MappingsFilePath -Value ($content | ConvertTo-Json -Depth 10) -Encoding UTF8
Write-Host "Done generating command mapping file"
}
function Get-Psd1Path {
$paths = @()
$SrcPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src"
foreach ($DirName in $(Get-ChildItem $SrcPath -Directory).Name)
{
$ModulePath = $(Join-Path -Path $SrcPath -ChildPath $DirName)
$Psd1FileName = "Az.{0}.psd1" -f $DirName
$Psd1FilePath = Get-ChildItem $ModulePath -Depth 2 -Recurse -Filter $Psd1FileName | Where-Object {
# Skip psd1 of generated modules in HYBRID modules because they are not really used
# This is based on an assumption that the path of the REAL psd1 of a HYBRID module should always not contain "Autorest"
$_.FullName -inotlike "*autorest*"
}
if ($null -ne $Psd1FilePath)
{
if($Psd1FilePath.Count -gt 1)
{
$Psd1FilePath = $Psd1FilePath[0]
}
$paths += $Psd1FilePath
}
}
return $paths
}
switch ($PSCmdlet.ParameterSetName)
{
"ReleaseSingleModule"
{
Write-Host executing dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll $PSScriptRoot/../artifacts/VersionController/Exceptions $ModuleName
dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll $PSScriptRoot/../artifacts/VersionController/Exceptions $ModuleName
Update-AzPreview
}
"ReleaseAzByMonthAndYear"
{
$Release = "$MonthName $Year"
}
{$PSItem.StartsWith("ReleaseAz")}
{
# clean the unnecessary SerializedCmdlets json file
$ExistSerializedCmdletJsonFile = Get-ExistSerializedCmdletJsonFile
$ExpectJsonHashSet = @{}
$SrcPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src"
foreach ($ModuleName in $(Get-ChildItem $SrcPath -Directory).Name)
{
$ModulePath = $(Join-Path -Path $SrcPath -ChildPath $ModuleName)
$Psd1FileName = "Az.{0}.psd1" -f $ModuleName
$Psd1FilePath = $(Get-ChildItem $ModulePath -Depth 2 -Recurse -Filter $Psd1FileName)
if ($null -ne $Psd1FilePath)
{
$Psd1Object = Import-PowerShellDataFile $Psd1FilePath
if ($Psd1Object.ModuleVersion -ge "1.0.0")
{
$ExpectJsonHashSet.Add("Az.${ModuleName}.json", $true)
}
}
}
foreach ($JsonFile in $ExistSerializedCmdletJsonFile)
{
$ModuleName = $JsonFile.Replace('.json', '')
if (!$ExpectJsonHashSet.Contains($JsonFile))
{
Write-Host "Module ${ModuleName} is not GA yet. The json file: ${JsonFile} is for reference"
}
}
Write-Host executing dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll
dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll
$versionBump = Bump-AzVersion
# Each release needs to update AzPreview.psd1 and dotnet csv
# Refresh AzPreview.psd1
Update-AzPreview
Update-AzPreviewChangelog
Update-AzSyntaxChangelog
# We need to generate the upcoming-breaking-changes.md after the process of bump version in minor release
if ([PSVersion]::MINOR -Eq $versionBump)
{
Import-Module $PSScriptRoot/BreakingChanges/GetUpcomingBreakingChange.ps1
Export-AllBreakingChangeMessageUnderArtifacts -ArtifactsPath $PSScriptRoot/../artifacts/Release/ -MarkdownPath $PSScriptRoot/../documentation/breaking-changes/upcoming-breaking-changes.md
}
}
}
# Generate dotnet csv
&$PSScriptRoot/Docs/GenerateDotNetCsv.ps1 -FeedPsd1FullPath "$PSScriptRoot\AzPreview\AzPreview.psd1"