-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathupdateAzureDataStudio.ps1
280 lines (244 loc) · 8.42 KB
/
updateAzureDataStudio.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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
#requires -Version 6.0
param(
[Parameter(Mandatory)]
[string]
$GitHubToken,
[Parameter(Mandatory)]
[version]
$ExtensionVersion,
[Parameter()]
[string[]]
$GalleryFileName = ('extensionsGallery.json','extensionsGallery-insider.json'),
[Parameter()]
[string]
$SourceFork = 'rjmholt',
[Parameter()]
[string]
$TargetFork = 'Microsoft',
[Parameter()]
[string]
$BranchName = "update-psext-$ExtensionVersion",
[Parameter()]
[string]
$PRDescription = "Updates the version of the PowerShell extension in ADS to $ExtensionVersion.`n**Note**: This is an automated PR."
)
Import-Module "$PSScriptRoot/../GitHubTools.psm1" -Force
Import-Module "$PSScriptRoot/../FileUpdateTools.psm1" -Force
function NewReleaseVersionEntry
{
param(
[Parameter()]
[version]
$Version,
[Parameter()]
[datetime]
$UpdateDate = [datetime]::Now.Date
)
return [ordered]@{
version = "$Version"
lastUpdated = $UpdateDate.ToString('M/dd/yyyy')
assetUri = ''
fallbackAssetUri = 'fallbackAssetUri'
files = @(
[ordered]@{
assetType = 'Microsoft.VisualStudio.Services.VSIXPackage'
source = "https://sqlopsextensions.blob.core.windows.net/extensions/powershell/ms-vscode.PowerShell-$Version.vsix"
}
[ordered]@{
assetType = 'Microsoft.VisualStudio.Services.Icons.Default'
source = 'https://raw.githubusercontent.com/PowerShell/vscode-powershell/master/media/PowerShell_Icon.png'
}
[ordered]@{
assetType = 'Microsoft.VisualStudio.Services.Content.Details'
source = 'https://raw.githubusercontent.com/PowerShell/vscode-powershell/master/docs/azure_data_studio/README_FOR_MARKETPLACE.md'
}
[ordered]@{
assetType = 'Microsoft.VisualStudio.Code.Manifest'
source = 'https://raw.githubusercontent.com/PowerShell/vscode-powershell/master/package.json'
}
[ordered]@{
assetType = 'Microsoft.VisualStudio.Services.Content.License'
source = 'https://raw.githubusercontent.com/PowerShell/vscode-powershell/master/LICENSE.txt'
}
)
properties = @(
[ordered]@{
key = 'Microsoft.VisualStudio.Code.ExtensionDependencies'
value = ''
}
[ordered]@{
key = 'Microsoft.VisualStudio.Code.Engine'
value = '>=0.32.1'
}
[ordered]@{
key = 'Microsoft.VisualStudio.Services.Links.Source'
value = 'https://github.com/PowerShell/vscode-powershell/'
}
)
}
}
function NewPowerShellExtensionEntry
{
param(
[Parameter()]
[version]
$ExtensionVersion
)
return [ordered]@{
extensionId = '35'
extensionName = 'powershell'
displayName = 'PowerShell'
shortDescription = 'Develop PowerShell modules, commands and scripts in Azure Data Studio'
publisher = [ordered]@{
displayName = 'Microsoft'
publisherId = 'Microsoft'
publisherName = 'Microsoft'
}
versions = @(
NewReleaseVersionEntry -Version $ExtensionVersion
)
statistics = @()
flags = 'preview'
}
}
function FindPSExtensionJsonSpan
{
param(
[Parameter()]
[string]
$GalleryExtensionFileContent
)
try
{
$reader = [System.IO.StringReader]::new($GalleryExtensionFileContent)
$jsonReader = [Newtonsoft.Json.JsonTextReader]::new($reader)
$depth = 0
$startLine = -1
$startColumn = -1
$startDepth = -1
$awaitingExtensionName = $false
$foundPowerShell = $false
while ($jsonReader.Read())
{
switch ($jsonReader.TokenType)
{
'StartObject'
{
if (-not $foundPowerShell)
{
$startDepth = $depth
$startLine = $jsonReader.LineNumber
$startColumn = $jsonReader.LinePosition
}
$depth++
continue
}
'EndObject'
{
if ($foundPowerShell -and $depth -eq $startDepth + 1)
{
return @{
Start = @{
Line = $startLine
Column = $startColumn
}
End = @{
Line = $jsonReader.LineNumber
Column = $jsonReader.LinePosition
}
}
}
$depth--
continue
}
'PropertyName'
{
if ($jsonReader.Value -eq 'extensionName')
{
$awaitingExtensionName = $true
}
continue
}
'String'
{
if (-not $awaitingExtensionName)
{
continue
}
$awaitingExtensionName = $false
if ($jsonReader.Value -eq 'PowerShell')
{
$foundPowerShell = $true
}
continue
}
}
}
}
finally
{
$reader.Dispose()
$jsonReader.Dispose()
}
throw 'Did not find PowerShell extension'
}
function UpdateGalleryFile
{
param(
[Parameter(Mandatory)]
[version]
$ExtensionVersion,
[Parameter(Mandatory, ValueFromPipeline)]
[string[]]
$GalleryFilePath
)
process
{
foreach ($galleryFile in $GalleryFilePath)
{
# Create a new PowerShell extension entry
$powershellEntry = NewPowerShellExtensionEntry -ExtensionVersion $ExtensionVersion
$entryStr = ConvertTo-IndentedJson $powershellEntry -IndentChar "`t" -IndentWidth 1
# Find the position in the existing file where the PowerShell extension should go
$galleryFileContent = Get-Content -Raw $GalleryFilePath
$span = FindPSExtensionJsonSpan -GalleryExtensionFileContent $galleryFileContent
$startOffset = Get-StringOffsetFromSpan -String $galleryFileContent -EndLine $span.Start.Line -Column $span.Start.Column
$endOffset = Get-StringOffsetFromSpan -String $galleryFileContent -EndLine $span.End.Line -StartLine $span.Start.Line -Column $span.End.Column -InitialOffset $startOffset
# Create the new file contents with the inserted segment
$newGalleryFileContent = New-StringWithSegment -String $galleryFileContent -NewSegment $entryStr -StartIndex $startOffset -EndIndex ($endOffset+1) -AutoIndent
# Write out the new entry
Set-Content -Path $GalleryFilePath -Value $newGalleryFileContent -Encoding utf8NoBOM -NoNewline
}
}
}
$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'ads-temp-checkout'
$cloneParams = @{
OriginRemote = "https://github.com/$SourceFork/AzureDataStudio"
Destination = $repoLocation
CloneBranch = 'release/extensions'
CheckoutBranch = $branchName
Clobber = $true
PullUpstream = $true
UpdateOrigin = $true
Remotes = @{
upstream = 'https://github.com/Microsoft/AzureDataStudio'
}
}
Copy-GitRepository @cloneParams
$GalleryFileName |
ForEach-Object { "$repoLocation/$_" } |
UpdateGalleryFile -ExtensionVersion $ExtensionVersion
Submit-GitChanges -RepositoryLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update PS extension to v$ExtensionVersion"
$prParams = @{
Organization = $TargetFork
Repository = 'AzureDataStudio'
TargetBranch = 'release/extensions'
Branch = $branchName
Title = "Update PowerShell extension to v$ExtensionVersion"
Description = $PRDescription
GitHubToken = $GitHubToken
FromOrg = $SourceFork
}
New-GitHubPR @prParams