forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildDrop.ps1
251 lines (194 loc) · 8.86 KB
/
BuildDrop.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
# .\BuildDrop.ps1 -BuildArtifactsPath "SAMPLE_PATH\archive" -PSVersion "2.1.0" -CodePlexUsername "cormacpayne" -CodePlexFork "ps0901" -ReleaseDate "2016-09-08" -PathToShared "SAMPLE_PATH\PowerShell"
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True, Position=0)]
[String]$BuildArtifactsPath,
[Parameter(Mandatory=$True, Position=1)]
[String]$PSVersion,
[Parameter(Mandatory=$True, Position=2)]
[String]$CodePlexUsername,
[Parameter(Mandatory=$True, Position=3)]
[String]$CodePlexFork,
[Parameter(Mandatory=$True, Position=4)]
[String]$ReleaseDate,
[Parameter(Mandatory=$True, Position=5)]
[String]$PathToShared
)
# This function will get the ProductCode from a given msi file
function Get-ProductCode
{
param(
[Parameter(Mandatory=$True)]
[System.IO.FileInfo]$Path
)
try
{
# Read property from MSI database
$WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $null, $WindowsInstaller, @($Path.FullName, 0))
$Query = "SELECT Value FROM Property WHERE Property = 'ProductCode'"
$View = $MSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $MSIDatabase, ($Query))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null)
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $View, $null)
$Value = $Record.GetType().InvokeMember("StringData", "GetProperty", $null, $Record, 1)
# Commit database and close view
$MSIDatabase.GetType().InvokeMember("Commit", "InvokeMethod", $null, $MSIDatabase, $null)
$View.GetType().InvokeMember("Close", "InvokeMethod", $null, $View, $null)
$MSIDatabase = $null
$View = $null
# Return the value
return $Value
}
catch
{
Write-Warning -Message $_.Exception.Message ; break
}
}
# ==================================================================================================
# Getting the ProductCode from the msi
# ==================================================================================================
Rename-Item "$BuildArtifactsPath\signed\AzurePowerShell.msi" "azure-powershell.$PSVersion.msi"
# Get the ProductCode of the msi
$msiFile = Get-Item "$BuildArtifactsPath\signed\azure-powershell.$PSVersion.msi"
$ProductCode = ([string](Get-ProductCode $msiFile)).Trim()
# ==================================================================================================
# Cloning CodePlex WebPI feed and creating the new branch
# ==================================================================================================
# Clone your fork of the CodePlex WebPI repository
$fork = "https://git01.codeplex.com/forks/$CodePlexUsername/$CodePlexFork"
git clone $fork $CodePlexFork
cd $CodePlexFork
# Create a branch that's in the format of YYYY-MM-DDTHH-MM
$date = Get-Date -Format u
$branch = $date.Substring(0, $date.Length - 4).Replace(":", "-").Replace(" ", "T");
git checkout -b $branch
# ==================================================================================================
# Update the DH_AzurePS.xml file
# ==================================================================================================
cd "Src\azuresdk\AzurePS"
# Get the text for DH_AzurePS.xml
$content = Get-Content "DH_AzurePS.xml"
# $newContent will be the text for the updated DH_AzurePS.xml
$newContentLength = $content.Length + 3
$newContent = New-Object string[] $newContentLength
$VSFeedSeen = $False
$PSGetSeen = $False
$buffer = 0
for ($idx = 0; $idx -lt $content.Length; $idx++)
{
# Flag that we will be looking at the entries for DH_WindowsAzurePowerShellVSFeed next
if ($content[$idx] -like "*VSFeed*")
{
$VSFeedSeen = $True
}
# Flag that we will be looking at the entry for DH_WindowsAzurePowerShellGet next
if ($content[$idx] -like "*PowerShellGet*")
{
$PSGetSeen = $True
}
# Check if we are looking at the DiscoveryHints for DH_WindowsAzurePowerShellVSFeed
# and if we have reached the end of the entry so we can add the new msi Product Code
if ($VSFeedSeen -and $content[$idx] -like "*</or>*")
{
$newContent[$idx] = " <discoveryHint>"
$newContent[$idx + 1] = " <msiProductCode>$ProductCode</msiProductCode>"
$newContent[$idx + 2] = " </discoveryHint>"
# Change the buffer size to include the three lines just added
$buffer = 3
# Flag that we are no longer in the VSFeed entry
$VSFeedSeen = $False
}
# Check if we are looking at the entry for DH_WindowsAzurePowerShellGet
if ($PSGetSeen -and $content[$idx] -like "*msiProductCode*")
{
$content[$idx] = " <msiProductCode>$ProductCode</msiProductCode>"
# Flag that we are no longer in the PSGet entry
$PSGetSeen = $False
}
$newContent[$idx + $buffer] = $content[$idx]
}
# Replace the contents of the current file with the updated content
$result = $newContent -join "`r`n"
$tempFile = Get-Item "DH_AzurePS.xml"
[System.IO.File]::WriteAllText($tempFile.FullName, $result)
# ==================================================================================================
# Update the WebProductList_AzurePS.xml file
# ==================================================================================================
# Get the text for WebProductList_AzurePS.xml
$content = Get-Content "WebProductList_AzurePS.xml"
$PSGetSeen = $false
for ($idx = 0; $idx -lt $content.Length; $idx++)
{
# Flag that we will be looking at the entry for WindowsAzurePowerShellGet next
if ($content[$idx] -contains " <productId>WindowsAzurePowershellGet</productId>")
{
$PSGetSeen = $true
}
# If we are in the WindowsAzurePowerShellGet entry, replace the necessary lines
if ($PSGetSeen)
{
if ($content[$idx] -like "*<version>*")
{
$content[$idx] = " <version>$PSVersion</version>"
}
if ($content[$idx] -like "*<published>*")
{
$content[$idx] = " <published>$($ReleaseDate)T12:00:00Z</published>"
}
if ($content[$idx] -like "*<updated>*")
{
$content[$idx] = " <updated>$($ReleaseDate)T12:00:00Z</updated>"
}
if ($content[$idx] -like "*<trackingURL>*")
{
$content[$idx] = " <trackingURL>http://www.microsoft.com/web/handlers/webpi.ashx?command=incrementproddownloadcount&prodid=WindowsAzurePowershell&version=$PSVersion&prodlang=en</trackingURL>"
}
if ($content[$idx] -like "*</entry>*")
{
$PSGetSeen = $False
}
}
}
# Replace the contents of the current file with the updated content
$result = $content -join "`r`n"
$tempFile = Get-Item "WebProductList_AzurePS.xml"
[System.IO.File]::WriteAllText($tempFile.FullName, $result)
# ==================================================================================================
# Create registry entry, and rename any prior release candidates
# ==================================================================================================
# Get the name of the folder - YYYY_MM_DD_PowerShell
$entryName = "$($ReleaseDate.Replace("-", "_"))_PowerShell"
# If the folder already exists, we need to rename it to what RC version it is
if (Test-Path "$PathToShared\$entryName")
{
$id = 1
# Keep incrementing the RC verison until we find the version we are on
while (Test-Path "$PathToShared\$($entryName)_RC$id")
{
$id++
}
# Rename the folder to include the RC version
Rename-Item "$PathToShared\$entryName" "$($entryName)_RC$id"
}
# Create the new folder
New-Item "$PathToShared\$entryName" -Type Directory > $null
New-Item "$PathToShared\$entryName\pkgs" -Type Directory > $null
# Copy all of the scripts and WebPI items into the new folder
Copy-Item "$PathToShared\PSReleaseDrop\*" "$PathToShared\$entryName" -Recurse
# Copy the msi and packages into the new folder
Copy-Item $msiFile.FullName "$PathToShared\$entryName"
Copy-Item "$BuildArtifactsPath\artifacts\*.nupkg" "$PathToShared\$entryName\pkgs"
# ==================================================================================================
# Update other xml files using Build.sh and copy them to entry
# ==================================================================================================
cd ../../../Tools
.\Build.cmd
cd ../bin
Copy-Item .\* $PathToShared\$entryName
# ==================================================================================================
# Commit and push changes to CodePlex
# ==================================================================================================
cd ..
git add .
git commit -m "Update DH_AzurePS.xml and WebProductList_AzurePS.xml"
git push origin $branch