1
+ # .\BuildDrop.ps1 -BuildArtifactsPath "SAMPLE_PATH\archive" -PSVersion "2.1.0" -CodePlexUsername "cormacpayne" -CodePlexFork "ps0901" -ReleaseDate "2016-09-08" -PathToShared "SAMPLE_PATH\PowerShell"
2
+
3
+ [CmdletBinding ()]
4
+ Param (
5
+ [Parameter (Mandatory = $True , Position = 0 )]
6
+ [String ]$BuildArtifactsPath ,
7
+ [Parameter (Mandatory = $True , Position = 1 )]
8
+ [String ]$PSVersion ,
9
+ [Parameter (Mandatory = $True , Position = 2 )]
10
+ [String ]$CodePlexUsername ,
11
+ [Parameter (Mandatory = $True , Position = 3 )]
12
+ [String ]$CodePlexFork ,
13
+ [Parameter (Mandatory = $True , Position = 4 )]
14
+ [String ]$ReleaseDate ,
15
+ [Parameter (Mandatory = $True , Position = 5 )]
16
+ [String ]$PathToShared
17
+ )
18
+
19
+ # This function will get the ProductCode from a given msi file
20
+ function Get-ProductCode
21
+ {
22
+ param (
23
+ [Parameter (Mandatory = $True )]
24
+ [System.IO.FileInfo ]$Path
25
+ )
26
+
27
+ try
28
+ {
29
+ # Read property from MSI database
30
+ $WindowsInstaller = New-Object - ComObject WindowsInstaller.Installer
31
+ $MSIDatabase = $WindowsInstaller.GetType ().InvokeMember(" OpenDatabase" , " InvokeMethod" , $null , $WindowsInstaller , @ ($Path.FullName , 0 ))
32
+ $Query = " SELECT Value FROM Property WHERE Property = 'ProductCode'"
33
+ $View = $MSIDatabase.GetType ().InvokeMember(" OpenView" , " InvokeMethod" , $null , $MSIDatabase , ($Query ))
34
+ $View.GetType ().InvokeMember(" Execute" , " InvokeMethod" , $null , $View , $null )
35
+ $Record = $View.GetType ().InvokeMember(" Fetch" , " InvokeMethod" , $null , $View , $null )
36
+ $Value = $Record.GetType ().InvokeMember(" StringData" , " GetProperty" , $null , $Record , 1 )
37
+
38
+ # Commit database and close view
39
+ $MSIDatabase.GetType ().InvokeMember(" Commit" , " InvokeMethod" , $null , $MSIDatabase , $null )
40
+ $View.GetType ().InvokeMember(" Close" , " InvokeMethod" , $null , $View , $null )
41
+ $MSIDatabase = $null
42
+ $View = $null
43
+
44
+ # Return the value
45
+ return $Value
46
+ }
47
+ catch
48
+ {
49
+ Write-Warning - Message $_.Exception.Message ; break
50
+ }
51
+ }
52
+
53
+ # ==================================================================================================
54
+ # Getting the ProductCode from the msi
55
+ # ==================================================================================================
56
+
57
+ Rename-Item " $BuildArtifactsPath \signed\AzurePowerShell.msi" " azure-powershell.$PSVersion .msi"
58
+
59
+ # Get the ProductCode of the msi
60
+ $msiFile = Get-Item " $BuildArtifactsPath \signed\azure-powershell.$PSVersion .msi"
61
+ $ProductCode = ([string ](Get-ProductCode $msiFile )).Trim()
62
+
63
+ # ==================================================================================================
64
+ # Cloning CodePlex WebPI feed and creating the new branch
65
+ # ==================================================================================================
66
+
67
+ # Clone your fork of the CodePlex WebPI repository
68
+ $fork = " https://git01.codeplex.com/forks/$CodePlexUsername /$CodePlexFork "
69
+ git clone $fork $CodePlexFork
70
+
71
+ cd $CodePlexFork
72
+
73
+ # Create a branch that's in the format of YYYY-MM-DDTHH-MM
74
+ $date = Get-Date - Format u
75
+ $branch = $date.Substring (0 , $date.Length - 4 ).Replace(" :" , " -" ).Replace(" " , " T" );
76
+ git checkout - b $branch
77
+
78
+ # ==================================================================================================
79
+ # Update the DH_AzurePS.xml file
80
+ # ==================================================================================================
81
+
82
+ cd " Src\azuresdk\AzurePS"
83
+
84
+ # Get the text for DH_AzurePS.xml
85
+ $content = Get-Content " DH_AzurePS.xml"
86
+
87
+ # $newContent will be the text for the updated DH_AzurePS.xml
88
+ $newContentLength = $content.Length + 3
89
+ $newContent = New-Object string[] $newContentLength
90
+
91
+ $VSFeedSeen = $False
92
+ $PSGetSeen = $False
93
+ $buffer = 0
94
+
95
+ for ($idx = 0 ; $idx -lt $content.Length ; $idx ++ )
96
+ {
97
+ # Flag that we will be looking at the entries for DH_WindowsAzurePowerShellVSFeed next
98
+ if ($content [$idx ] -like " *VSFeed*" )
99
+ {
100
+ $VSFeedSeen = $True
101
+ }
102
+
103
+ # Flag that we will be looking at the entry for DH_WindowsAzurePowerShellGet next
104
+ if ($content [$idx ] -like " *PowerShellGet*" )
105
+ {
106
+ $PSGetSeen = $True
107
+ }
108
+
109
+ # Check if we are looking at the DiscoveryHints for DH_WindowsAzurePowerShellVSFeed
110
+ # and if we have reached the end of the entry so we can add the new msi Product Code
111
+ if ($VSFeedSeen -and $content [$idx ] -like " *</or>*" )
112
+ {
113
+ $newContent [$idx ] = " <discoveryHint>"
114
+ $newContent [$idx + 1 ] = " <msiProductCode>$ProductCode </msiProductCode>"
115
+ $newContent [$idx + 2 ] = " </discoveryHint>"
116
+
117
+ # Change the buffer size to include the three lines just added
118
+ $buffer = 3
119
+
120
+ # Flag that we are no longer in the VSFeed entry
121
+ $VSFeedSeen = $False
122
+ }
123
+
124
+ # Check if we are looking at the entry for DH_WindowsAzurePowerShellGet
125
+ if ($PSGetSeen -and $content [$idx ] -like " *msiProductCode*" )
126
+ {
127
+ $content [$idx ] = " <msiProductCode>$ProductCode </msiProductCode>"
128
+
129
+ # Flag that we are no longer in the PSGet entry
130
+ $PSGetSeen = $False
131
+ }
132
+
133
+ $newContent [$idx + $buffer ] = $content [$idx ]
134
+ }
135
+
136
+ # Replace the contents of the current file with the updated content
137
+ $result = $newContent -join " `r`n "
138
+ $tempFile = Get-Item " DH_AzurePS.xml"
139
+
140
+ [System.IO.File ]::WriteAllText($tempFile.FullName , $result )
141
+
142
+ # ==================================================================================================
143
+ # Update the WebProductList_AzurePS.xml file
144
+ # ==================================================================================================
145
+
146
+ # Get the text for WebProductList_AzurePS.xml
147
+ $content = Get-Content " WebProductList_AzurePS.xml"
148
+
149
+ $PSGetSeen = $false
150
+
151
+ for ($idx = 0 ; $idx -lt $content.Length ; $idx ++ )
152
+ {
153
+ # Flag that we will be looking at the entry for WindowsAzurePowerShellGet next
154
+ if ($content [$idx ] -contains " <productId>WindowsAzurePowershellGet</productId>" )
155
+ {
156
+ $PSGetSeen = $true
157
+ }
158
+
159
+ # If we are in the WindowsAzurePowerShellGet entry, replace the necessary lines
160
+ if ($PSGetSeen )
161
+ {
162
+ if ($content [$idx ] -like " *<version>*" )
163
+ {
164
+ $content [$idx ] = " <version>$PSVersion </version>"
165
+ }
166
+
167
+ if ($content [$idx ] -like " *<published>*" )
168
+ {
169
+ $content [$idx ] = " <published>$ ( $ReleaseDate ) T12:00:00Z</published>"
170
+ }
171
+
172
+ if ($content [$idx ] -like " *<updated>*" )
173
+ {
174
+ $content [$idx ] = " <updated>$ ( $ReleaseDate ) T12:00:00Z</updated>"
175
+ }
176
+
177
+ if ($content [$idx ] -like " *<trackingURL>*" )
178
+ {
179
+ $content [$idx ] = " <trackingURL>http://www.microsoft.com/web/handlers/webpi.ashx?command=incrementproddownloadcount&prodid=WindowsAzurePowershell&version=$PSVersion &prodlang=en</trackingURL>"
180
+ }
181
+
182
+ if ($content [$idx ] -like " *</entry>*" )
183
+ {
184
+ $PSGetSeen = $False
185
+ }
186
+ }
187
+
188
+ }
189
+
190
+ # Replace the contents of the current file with the updated content
191
+ $result = $content -join " `r`n "
192
+ $tempFile = Get-Item " WebProductList_AzurePS.xml"
193
+
194
+ [System.IO.File ]::WriteAllText($tempFile.FullName , $result )
195
+
196
+ # ==================================================================================================
197
+ # Create registry entry, and rename any prior release candidates
198
+ # ==================================================================================================
199
+
200
+ # Get the name of the folder - YYYY_MM_DD_PowerShell
201
+ $entryName = " $ ( $ReleaseDate.Replace (" -" , " _" )) _PowerShell"
202
+
203
+ # If the folder already exists, we need to rename it to what RC version it is
204
+ if (Test-Path " $PathToShared \$entryName " )
205
+ {
206
+ $id = 1
207
+
208
+ # Keep incrementing the RC verison until we find the version we are on
209
+ while (Test-Path " $PathToShared \$ ( $entryName ) _RC$id " )
210
+ {
211
+ $id ++
212
+ }
213
+
214
+ # Rename the folder to include the RC version
215
+ Rename-Item " $PathToShared \$entryName " " $ ( $entryName ) _RC$id "
216
+ }
217
+
218
+ # Create the new folder
219
+ New-Item " $PathToShared \$entryName " - Type Directory > $null
220
+ New-Item " $PathToShared \$entryName \pkgs" - Type Directory > $null
221
+
222
+ # Copy all of the scripts and WebPI items into the new folder
223
+ Copy-Item " $PathToShared \PSReleaseDrop\*" " $PathToShared \$entryName " - Recurse
224
+
225
+ # Copy the msi and packages into the new folder
226
+ Copy-Item $msiFile.FullName " $PathToShared \$entryName "
227
+ Copy-Item " $BuildArtifactsPath \src\Package\*.nupkg" " $PathToShared \$entryName \pkgs"
228
+
229
+ # ==================================================================================================
230
+ # Update other xml files using Build.sh and copy them to entry
231
+ # ==================================================================================================
232
+
233
+ cd ../ ../ ../ Tools
234
+
235
+ .\Build.cmd
236
+
237
+ cd ../ bin
238
+
239
+ Copy-Item .\* $PathToShared \$entryName
240
+
241
+ # ==================================================================================================
242
+ # Commit and push changes to CodePlex
243
+ # ==================================================================================================
244
+
245
+ cd ..
246
+
247
+ git add .
248
+
249
+ git commit - m " Update DH_AzurePS.xml and WebProductList_AzurePS.xml"
250
+
251
+ git push origin $branch
0 commit comments