Skip to content

Commit 713ce78

Browse files
committed
Improve existing scripts, add PSES update script
1 parent fe93cf2 commit 713ce78

File tree

5 files changed

+330
-51
lines changed

5 files changed

+330
-51
lines changed

tools/FileUpdateTools.psm1

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,61 @@ function SetFileContent
185185

186186
$FilePath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($FilePath)
187187
[System.IO.File]::WriteAllText($FilePath, $Value, $Encoding)
188-
}
188+
}
189+
190+
function IncrementVersion
191+
{
192+
param(
193+
[Parameter(Mandatory)]
194+
[semver]
195+
$CurrentVersion,
196+
197+
[Parameter(Mandatory)]
198+
[ValidateSet('Major', 'Minor', 'Patch', 'Preview')]
199+
[string]
200+
$IncrementLevel
201+
)
202+
203+
switch ($IncrementLevel)
204+
{
205+
'Major'
206+
{
207+
return [semver]::new($version.Major+1, $version.Minor, $version.Patch, $version.PreReleaseLabel)
208+
}
209+
210+
'Minor'
211+
{
212+
return [semver]::new($version.Major, $version.Minor+1, $version.Patch, $version.PreReleaseLabel)
213+
}
214+
215+
'Patch'
216+
{
217+
return [semver]::new($version.Major, $version.Minor, $version.Patch+1, $version.PreReleaseLabel)
218+
}
219+
220+
'Preview'
221+
{
222+
$newPreviewNumber = [int]$version.PreReleaseLabel.Substring(8) + 1
223+
return [semver]::new($version.Major, $version.Minor, $version.Patch, "preview.$newPreviewNumber")
224+
}
225+
}
226+
}
227+
228+
function GetVersionFromSemVer
229+
{
230+
[OutputType([version])]
231+
param(
232+
[Parameter(Mandatory)]
233+
[semver]
234+
$SemVer
235+
)
236+
237+
$svStr = $SemVer.ToString()
238+
239+
if (-not $SemVer.PreReleaseLabel)
240+
{
241+
return [version]$svStr
242+
}
243+
244+
return $svStr.Substring(0, $svStr.IndexOf('-'))
245+
}

tools/GitHubTools.psm1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ function CloneRepo
6161
if ($remote['upstream'])
6262
{
6363
git pull upstream $CloneBranch
64-
git push --force-with-lease $OriginRemote $CloneBranch
6564
}
6665

6766
if ($CheckoutBranch)

tools/repoUpdateScripts/updateAzureDataStudio.ps1

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ param(
1616

1717
[Parameter()]
1818
[string]
19-
$TargetFork = 'Microsoft'
19+
$TargetFork = 'Microsoft',
20+
21+
[Parameter()]
22+
[string]
23+
$BranchName,
24+
25+
[Parameter()]
26+
[string]
27+
$PRDescription
2028
)
2129

2230
Import-Module "$PSScriptRoot/../GitHubTools.psm1" -Force
@@ -226,7 +234,16 @@ function UpdateGalleryFile
226234
}
227235

228236
$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'ads-temp-checkout'
229-
$branchName = "update-psext-$ExtensionVersion"
237+
238+
if (-not $BranchName)
239+
{
240+
$BranchName = "update-psext-$ExtensionVersion"
241+
}
242+
243+
if (-not $PRDescription)
244+
{
245+
$PRDescription = "Updates the version of the PowerShell extension in ADS to $ExtensionVersion.`n**Note**: This is an automated PR."
246+
}
230247

231248
$cloneParams = @{
232249
OriginRemote = 'https://github.com/rjmholt/AzureDataStudio'
@@ -250,7 +267,7 @@ $prParams = @{
250267
TargetBranch = 'release/extensions'
251268
Branch = $branchName
252269
Title = "Update PowerShell extension to v$ExtensionVersion"
253-
Description = "Updates the version of the PowerShell extension in ADS to $ExtensionVersion.`n**Note**: This is an automated PR."
270+
Description = $PRDescription
254271
GitHubToken = $GitHubToken
255272
FromOrg = 'rjmholt'
256273
}

tools/repoUpdateScripts/updateExtensionVersions.ps1

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ param(
1818

1919
[Parameter()]
2020
[string]
21-
$TargetFork = 'PowerShell'
21+
$TargetFork = 'PowerShell',
22+
23+
[Parameter()]
24+
[string]
25+
$BranchName,
26+
27+
[Parameter()]
28+
[string]
29+
$PRDescription
2230
)
2331

2432
Import-Module -Force "$PSScriptRoot/../FileUpdateTools.psm1"
@@ -138,42 +146,6 @@ function FindVstsBuildVersionSpan
138146
}
139147
}
140148

141-
function IncrementVersion
142-
{
143-
param(
144-
[Parameter(Mandatory)]
145-
[semver]
146-
$CurrentVersion,
147-
148-
[Parameter(Mandatory)]
149-
$IncrementLevel
150-
)
151-
152-
switch ($IncrementLevel)
153-
{
154-
'Major'
155-
{
156-
return [semver]::new($version.Major+1, $version.Minor, $version.Patch, $version.PreReleaseLabel)
157-
}
158-
159-
'Minor'
160-
{
161-
return [semver]::new($version.Major, $version.Minor+1, $version.Patch, $version.PreReleaseLabel)
162-
}
163-
164-
'Patch'
165-
{
166-
return [semver]::new($version.Major, $version.Minor, $version.Patch+1, $version.PreReleaseLabel)
167-
}
168-
169-
'Preview'
170-
{
171-
$newPreviewNumber = [int]$version.PreReleaseLabel.Substring(8) + 1
172-
return [semver]::new($version.Major, $version.Minor, $version.Patch, "preview.$newPreviewNumber")
173-
}
174-
}
175-
}
176-
177149
function UpdateMainTsPsesVersion
178150
{
179151
param(
@@ -213,6 +185,23 @@ function UpdateDockerFileVersion
213185
SetFileContent -FilePath $DockerFilePath -Value $newDockerFileContent
214186
}
215187

188+
function GetMarketplaceVersionFromSemVer
189+
{
190+
[OutputType([version])]
191+
param(
192+
[Parameter(Mandatory)]
193+
[semver]
194+
$SemVer
195+
)
196+
197+
if (-not $SemVer.PreReleaseLabel)
198+
{
199+
return [version]($SemVer.ToString())
200+
}
201+
202+
return [version]::new($NewVersion.Major, $NewVersion.Minor, $NewVersion.PreReleaseLabel.Substring(8)-1)
203+
}
204+
216205
# Define locations/branch name
217206
$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'vscps-updateversion-temp'
218207
$paths = @{
@@ -245,19 +234,19 @@ if ($IncrementLevel)
245234

246235
# Get the marketplace/non-semver versions for various files
247236
$newVersionStr = $NewVersion.ToString()
248-
if ($NewVersion.PreReleaseLabel)
237+
$psesVersion = GetVersionFromSemVer -SemVer $NewVersion
238+
$marketPlaceVersion = GetMarketplaceVersionFromSemVer -SemVer $NewVersion
239+
240+
if (-not $BranchName)
249241
{
250-
$psesVersion = $newVersionStr.Substring(0, $newVersionStr.IndexOf('-'))
251-
$marketPlaceVersion = [version]::new($NewVersion.Major, $NewVersion.Minor, $NewVersion.PreReleaseLabel.Substring(8)-1)
242+
$BranchName = "update-version-$newVersionStr"
252243
}
253-
else
244+
245+
if (-not $PRDescription)
254246
{
255-
$psesVersion = $newVersionStr
256-
$marketPlaceVersion = $newVersionStr
247+
$PRDescription = "Updates version strings in vscode-PowerShell to $newVersionStr.`n**Note**: This is an automated PR."
257248
}
258249

259-
$branchName = "update-version-$newVersionStr"
260-
261250
# Finally create the new package.json file
262251
$newPkgJsonContent = ReplaceStringSegment -String $packageJson -NewSegment $newVersionStr -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End
263252
SetFileContent -FilePath $paths.packageJson -Value $newPkgJsonContent
@@ -287,7 +276,7 @@ $prParams = @{
287276
Repository = 'vscode-PowerShell'
288277
Branch = $branchName
289278
Title = "Update version to v$newVersionStr"
290-
Description = "Updates version strings in vscode-PowerShell to $newVersionStr.`n**Note**: This is an automated PR."
279+
Description = $PRDescription
291280
GitHubToken = $GitHubToken
292281
FromOrg = 'rjmholt'
293282
}

0 commit comments

Comments
 (0)