1
+ # .\UpdateAzureRM.ps1 -Release "December 2017"
2
+ [CmdletBinding ()]
3
+ Param (
4
+ [Parameter (Mandatory = $true )]
5
+ [string ]$Release
6
+ )
7
+
8
+ enum PSVersion
9
+ {
10
+ NONE = 0
11
+ PATCH = 1
12
+ MINOR = 2
13
+ MAJOR = 3
14
+ }
15
+
16
+ function Get-VersionBump
17
+ {
18
+ Param (
19
+ [Parameter (Mandatory = $true )]
20
+ [string ]$GalleryVersion ,
21
+ [Parameter (Mandatory = $true )]
22
+ [string ]$LocalVersion
23
+ )
24
+
25
+ $gallerySplit = $GalleryVersion.Split (' .' )
26
+ $localSplit = $LocalVersion.Split (' .' )
27
+
28
+ if ($gallerySplit [0 ] -ne $localSplit [0 ])
29
+ {
30
+ return [PSVersion ]::MAJOR
31
+ }
32
+ elseif ($gallerySplit [1 ] -ne $localSplit [1 ])
33
+ {
34
+ return [PSVersion ]::MINOR
35
+ }
36
+ elseif ($gallerySplit [2 ] -ne $localSplit [1 ])
37
+ {
38
+ return [PSVersion ]::PATCH
39
+ }
40
+
41
+ return [PSVersion ]::NONE
42
+ }
43
+
44
+ function Get-BumpedVersion
45
+ {
46
+ Param (
47
+ [Parameter (Mandatory = $true )]
48
+ [string ]$Version ,
49
+ [Parameter (Mandatory = $true )]
50
+ [PSVersion ]$VersionBump
51
+ )
52
+
53
+ $versionSplit = $Version.Split (' .' )
54
+ if ($VersionBump -eq [PSVersion ]::MAJOR)
55
+ {
56
+ $versionSplit [0 ] = 1 + $versionSplit [0 ]
57
+ $versionSplit [1 ] = " 0"
58
+ $versionSplit [2 ] = " 0"
59
+ }
60
+ elseif ($VersionBump -eq [PSVersion ]::MINOR)
61
+ {
62
+ $versionSplit [1 ] = 1 + $versionSplit [1 ]
63
+ $versionSplit [2 ] = " 0"
64
+ }
65
+ elseif ($VersionBump -eq [PSVersion ]::PATCH)
66
+ {
67
+ $versionSplit [2 ] = 1 + $versionSplit [2 ]
68
+ }
69
+
70
+ return $versionSplit -join " ."
71
+ }
72
+
73
+ function Update-AzurecmdFile
74
+ {
75
+ Param (
76
+ [Parameter (Mandatory = $true )]
77
+ [string ]$OldVersion ,
78
+ [Parameter (Mandatory = $true )]
79
+ [string ]$NewVersion ,
80
+ [Parameter (Mandatory = $true )]
81
+ [string ]$Release ,
82
+ [Parameter (Mandatory = $true )]
83
+ [string ]$RootPath
84
+ )
85
+
86
+ $AzurecmdFile = Get-Item - Path " $RootPath \setup\azurecmd.wxs"
87
+ (Get-Content $AzurecmdFile.FullName ) | % {
88
+ $_ -replace " Microsoft Azure PowerShell - (\w*)(\s)(\w*)" , " Microsoft Azure PowerShell - $Release "
89
+ } | Set-Content - Path $AzurecmdFile.FullName - Encoding UTF8
90
+
91
+ (Get-Content $AzurecmdFile.FullName ) | % {
92
+ $_ -replace " $OldVersion " , " $NewVersion "
93
+ } | Set-Content - Path $AzurecmdFile.FullName - Encoding UTF8
94
+ }
95
+
96
+ function Update-AzurePowerShellFile
97
+ {
98
+ Param (
99
+ [Parameter (Mandatory = $true )]
100
+ [string ]$OldVersion ,
101
+ [Parameter (Mandatory = $true )]
102
+ [string ]$NewVersion ,
103
+ [Parameter (Mandatory = $true )]
104
+ [string ]$RootPath
105
+ )
106
+
107
+ $AzurePowerShellFile = Get-Item - Path " $RootPath \src\Common\Commands.Common\AzurePowerShell.cs"
108
+ (Get-Content $AzurePowerShellFile.FullName ) | % {
109
+ $_ -replace " $OldVersion " , " $NewVersion "
110
+ } | Set-Content - Path $AzurePowerShellFile.FullName - Encoding UTF8
111
+ }
112
+
113
+ function Get-ReleaseNotes
114
+ {
115
+ Param (
116
+ [Parameter (Mandatory = $true )]
117
+ [string ]$Module ,
118
+ [Parameter (Mandatory = $true )]
119
+ [string ]$RootPath
120
+ )
121
+
122
+ $ProjectPaths = @ ( " $RootPath \src\ResourceManager" , " $RootPath \src\ServiceManagement" , " $RootPath \src\Storage" )
123
+ $ModuleManifestFile = $ProjectPaths | % { Get-ChildItem - Path $_ - Filter " *.psd1" - Recurse | where { $_.Name.Replace (" .psd1" , " " ) -eq $Module -and `
124
+ $_.FullName -notlike " *Debug*" -and `
125
+ $_.FullName -notlike " *Netcore*" -and `
126
+ $_.FullName -notlike " *dll-Help.psd1*" -and `
127
+ $_.FullName -notlike " *Stack*" } }
128
+
129
+ Import-LocalizedData - BindingVariable ModuleMetadata - BaseDirectory $ModuleManifestFile.DirectoryName - FileName $ModuleManifestFile.Name
130
+ return $ModuleMetadata.PrivateData.PSData.ReleaseNotes
131
+ }
132
+
133
+ function Update-ChangeLog
134
+ {
135
+ Param (
136
+ [Parameter (Mandatory = $true )]
137
+ [string []]$Content ,
138
+ [Parameter (Mandatory = $true )]
139
+ [string ]$RootPath
140
+ )
141
+
142
+ $ChangeLogFile = Get-Item - Path " $RootPath \ChangeLog.md"
143
+ $ChangeLogContent = Get-Content - Path $ChangeLogFile.FullName
144
+ ($Content + $ChangeLogContent ) | Set-Content - Path $ChangeLogFile.FullName - Encoding UTF8
145
+ }
146
+
147
+ Write-Host " Getting local AzureRM information..." - ForegroundColor Yellow
148
+ $localAzureRM = Test-ModuleManifest - Path " $PSScriptRoot \AzureRM\AzureRM.psd1"
149
+
150
+ Write-Host " Getting gallery AzureRM information..." - ForegroundColor Yellow
151
+ $galleryAzureRM = Find-Module - Name AzureRM - Repository PSGallery
152
+
153
+ $versionBump = [PSVersion ]::NONE
154
+ $updatedModules = @ ()
155
+ foreach ($galleryDependency in $galleryAzureRM.Dependencies )
156
+ {
157
+ $localDependency = $localAzureRM.RequiredModules | where { $_.Name -eq $galleryDependency.Name }
158
+ if ($localDependency -eq $null )
159
+ {
160
+ Write-Error " Could not find matching dependency for $ ( $galleryDependency.Name ) "
161
+ }
162
+
163
+ $galleryVersion = $galleryDependency.RequiredVersion.ToString ()
164
+ $localVersion = $localDependency.Version.ToString ()
165
+ if ($galleryVersion -ne $localVersion )
166
+ {
167
+ $updatedModules += $galleryDependency.Name
168
+ $currBump = Get-VersionBump - GalleryVersion $galleryVersion - LocalVersion $localVersion
169
+ Write-Host " Found $currBump version bump for $ ( $localDependency.NAME ) "
170
+ if ($currBump -eq [PSVersion ]::MAJOR)
171
+ {
172
+ $versionBump = [PSVersion ]::MAJOR
173
+ }
174
+ elseif ($currBump -eq [PSVersion ]::MINOR -and $versionBump -ne [Version ]::MAJOR)
175
+ {
176
+ $versionBump = [PSVersion ]::MINOR
177
+ }
178
+ elseif ($currBump -eq [PSVersion ]::PATCH -and $versionBump -eq [Version ]::NONE)
179
+ {
180
+ $versionBump = [PSVersion ]::PATCH
181
+ }
182
+ }
183
+ }
184
+
185
+ if ($versionBump -eq [PSVersion ]::NONE)
186
+ {
187
+ Write-Host " No changes found in AzureRM." - ForegroundColor Green
188
+ return
189
+ }
190
+
191
+ $newVersion = Get-BumpedVersion - Version $localAzureRM.Version - VersionBump $versionBump
192
+
193
+ Write-Host " New version of AzureRM: $newVersion " - ForegroundColor Green
194
+
195
+ $rootPath = " $PSScriptRoot \.."
196
+ $oldVersion = $galleryAzureRM.Version
197
+
198
+ Update-AzurecmdFile - OldVersion $oldVersion - NewVersion $newVersion - Release $Release - RootPath $rootPath
199
+ Update-AzurePowerShellFile - OldVersion $oldVersion - NewVersion $newVersion - RootPath $rootPath
200
+
201
+ $releaseNotes = @ ()
202
+ $releaseNotes += " $newVersion - $Release "
203
+
204
+ $changeLog = @ ()
205
+ $changeLog += " ## $newVersion - $Release "
206
+ foreach ($updatedModule in $updatedModules )
207
+ {
208
+ $releaseNotes += $updatedModule
209
+ $releaseNotes += $ (Get-ReleaseNotes - Module $updatedModule - RootPath $rootPath ) + " `n "
210
+
211
+ $changeLog += " #### $updatedModule "
212
+ $changeLog += $ (Get-ReleaseNotes - Module $updatedModule - RootPath $rootPath ) + " `n "
213
+ }
214
+
215
+ Update-ModuleManifest - Path " $PSScriptRoot \AzureRM\AzureRM.psd1" - ModuleVersion $newVersion - ReleaseNotes $releaseNotes
216
+ Update-ChangeLog - Content $changeLog - RootPath $rootPath
0 commit comments