Skip to content

Commit 3ded07c

Browse files
committed
Add script to create a build drop from a sign job
1 parent f4b20ef commit 3ded07c

File tree

1 file changed

+240
-0
lines changed

1 file changed

+240
-0
lines changed

tools/BuildDrop.ps1

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
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+
121+
# Check if we are looking at the entry for DH_WindowsAzurePowerShellGet
122+
if ($PSGetSeen -and $content[$idx] -like "*msiProductCode*")
123+
{
124+
$content[$idx] = " <msiProductCode>$ProductCode</msiProductCode>"
125+
}
126+
127+
$newContent[$idx + $buffer] = $content[$idx]
128+
}
129+
130+
# Replace the contents of the current file with the updated content
131+
$result = $newContent -join "`r`n"
132+
$tempFile = Get-Item "DH_AzurePS.xml"
133+
134+
[System.IO.File]::WriteAllText($tempFile.FullName, $result)
135+
136+
# ==================================================================================================
137+
# Update the WebProductList_AzurePS.xml file
138+
# ==================================================================================================
139+
140+
# Get the text for WebProductList_AzurePS.xml
141+
$content = Get-Content "WebProductList_AzurePS.xml"
142+
143+
$PSGetSeen = $false
144+
145+
for ($idx = 0; $idx -lt $content.Length; $idx++)
146+
{
147+
# Flag that we will be looking at the entry for WindowsAzurePowerShellGet next
148+
if ($content[$idx] -contains " <productId>WindowsAzurePowershellGet</productId>")
149+
{
150+
$PSGetSeen = $true
151+
}
152+
153+
# If we are in the WindowsAzurePowerShellGet entry, replace the necessary lines
154+
if ($PSGetSeen)
155+
{
156+
if ($content[$idx] -like "*<version>*")
157+
{
158+
$content[$idx] = " <version>$PSVersion</version>"
159+
}
160+
161+
if ($content[$idx] -like "*<published>*")
162+
{
163+
$content[$idx] = " <published>$($ReleaseDate)T12:00:00Z</published>"
164+
}
165+
166+
if ($content[$idx] -like "*<updated>*")
167+
{
168+
$content[$idx] = " <updated>$($ReleaseDate)T12:00:00Z</updated>"
169+
}
170+
171+
if ($content[$idx] -like "*<trackingURL>*")
172+
{
173+
$content[$idx] = " <trackingURL>http://www.microsoft.com/web/handlers/webpi.ashx?command=incrementproddownloadcount&amp;prodid=WindowsAzurePowershell&amp;version=$PSVersion&amp;prodlang=en</trackingURL>"
174+
}
175+
}
176+
177+
}
178+
179+
# Replace the contents of the current file with the updated content
180+
$result = $content -join "`r`n"
181+
$tempFile = Get-Item "WebProductList_AzurePS.xml"
182+
183+
[System.IO.File]::WriteAllText($tempFile.FullName, $result)
184+
185+
# ==================================================================================================
186+
# Create registry entry, and rename any prior release candidates
187+
# ==================================================================================================
188+
189+
# Get the name of the folder - YYYY_MM_DD_PowerShell
190+
$entryName = "$($ReleaseDate.Replace("-", "_"))_PowerShell"
191+
192+
# If the folder already exists, we need to rename it to what RC version it is
193+
if (Test-Path "$PathToShared\$entryName")
194+
{
195+
$id = 1
196+
197+
# Keep incrementing the RC verison until we find the version we are on
198+
while (Test-Path "$PathToShared\$($entryName)_RC$id")
199+
{
200+
$id++
201+
}
202+
203+
# Rename the folder to include the RC version
204+
Rename-Item "$PathToShared\$entryName" "$($entryName)_RC$id"
205+
}
206+
207+
# Create the new folder
208+
New-Item "$PathToShared\$entryName" -Type Directory > $null
209+
New-Item "$PathToShared\$entryName\pkgs" -Type Directory > $null
210+
211+
# Copy all of the scripts and WebPI items into the new folder
212+
Copy-Item "$PathToShared\PSReleaseDrop\*" "$PathToShared\$entryName" -Recurse
213+
214+
# Copy the msi and packages into the new folder
215+
Copy-Item $msiFile.FullName "$PathToShared\$entryName"
216+
Copy-Item "$BuildArtifactsPath\src\Package\*.nupkg" "$PathToShared\$entryName\pkgs"
217+
218+
# ==================================================================================================
219+
# Update other xml files using Build.sh and copy them to entry
220+
# ==================================================================================================
221+
222+
cd ../../../Tools
223+
224+
.\Build.cmd
225+
226+
cd ../bin
227+
228+
Copy-Item .\* $PathToShared\$entryName
229+
230+
# ==================================================================================================
231+
# Commit and push changes to CodePlex
232+
# ==================================================================================================
233+
234+
cd ..
235+
236+
git add .
237+
238+
git commit -m "Update DH_AzurePS.xml and WebProductList_AzurePS.xml"
239+
240+
git push origin $branch

0 commit comments

Comments
 (0)