From 37a095ea029e92473f63379ddd7a5c6b0895c6eb Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 29 Apr 2019 13:24:37 +1000 Subject: [PATCH 01/18] Add AzureDataStudio update script --- .../updateAzureDataStudio.ps1 | 254 ++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 tools/repoUpdateScripts/updateAzureDataStudio.ps1 diff --git a/tools/repoUpdateScripts/updateAzureDataStudio.ps1 b/tools/repoUpdateScripts/updateAzureDataStudio.ps1 new file mode 100644 index 0000000000..c33d7e47e1 --- /dev/null +++ b/tools/repoUpdateScripts/updateAzureDataStudio.ps1 @@ -0,0 +1,254 @@ +param( + [Parameter(Mandatory)] + [string] + $GitHubToken, + + [Parameter(Mandatory)] + [version] + $ExtensionVersion, + + [Parameter()] + [string] + $GalleryFileName = 'extensionsGallery.json', + + [Parameter()] + [string] + $TargetFork = 'Microsoft' +) + +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/PowerShell-$Version.vsix" + } + [ordered]@{ + assetType = 'Microsoft.VisualStudio.Services.Icons.Default' + source = 'https://raw.githubusercontent.com/PowerShell/vscode-powershell/master/images/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 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()] + [string] + $GalleryFilePath = './extensionsGallery-insider.json' + ) + + # Create a new PowerShell extension entry + $powershellEntry = NewPowerShellExtensionEntry -ExtensionVersion $ExtensionVersion + $entryStr = ConvertToIndentedJson $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 = GetStringOffsetFromSpan -String $galleryFileContent -EndLine $span.Start.Line -Column $span.Start.Column + $endOffset = GetStringOffsetFromSpan -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 = ReplaceStringSegment -String $galleryFileContent -NewSegment $entryStr -StartIndex $startOffset -EndIndex $endOffset + + # Write out the new entry + [System.IO.File]::WriteAllText($GalleryFilePath, $newGalleryFileContent, [System.Text.UTF8Encoding]::new(<# BOM #> $false)) +} + +$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'ads-temp-checkout' +$branchName = "update-psext-$ExtensionVersion" + +$cloneParams = @{ + OriginRemote = 'https://github.com/rjmholt/AzureDataStudio' + Destination = $repoLocation + CloneBranch = 'release/extensions' + CheckoutBranch = $branchName + Clobber = $true + Remotes = @{ + upstream = 'https://github.com/Microsoft/AzureDataStudio' + } +} +CloneRepo @cloneParams + +UpdateGalleryFile -ExtensionVersion $ExtensionVersion -GalleryFilePath "$repoLocation/$GalleryFileName" + +CommitAndPushChanges -RepoLocation $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 = "Updates the version of the PowerShell extension in ADS to $ExtensionVersion.`n**Note**: This is an automated PR." + GitHubToken = $GitHubToken + FromOrg = 'rjmholt' +} +OpenGitHubPr @prParams \ No newline at end of file From 229a61102ade66f7800af64047c688aa3f204a7b Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 29 Apr 2019 13:36:24 +1000 Subject: [PATCH 02/18] Copyright headers --- tools/repoUpdateScripts/updateAzureDataStudio.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/repoUpdateScripts/updateAzureDataStudio.ps1 b/tools/repoUpdateScripts/updateAzureDataStudio.ps1 index c33d7e47e1..e9b0f04bbf 100644 --- a/tools/repoUpdateScripts/updateAzureDataStudio.ps1 +++ b/tools/repoUpdateScripts/updateAzureDataStudio.ps1 @@ -1,3 +1,6 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + param( [Parameter(Mandatory)] [string] @@ -219,7 +222,7 @@ function UpdateGalleryFile $newGalleryFileContent = ReplaceStringSegment -String $galleryFileContent -NewSegment $entryStr -StartIndex $startOffset -EndIndex $endOffset # Write out the new entry - [System.IO.File]::WriteAllText($GalleryFilePath, $newGalleryFileContent, [System.Text.UTF8Encoding]::new(<# BOM #> $false)) + SetFileContent $GalleryFilePath $newGalleryFileContent } $repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'ads-temp-checkout' From d14b2c5cf39ccd413c2d45b246a646ae1aff5083 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 29 Apr 2019 17:02:25 +1000 Subject: [PATCH 03/18] Fix ads updater, add vsix version updater script --- .../updateAzureDataStudio.ps1 | 2 +- .../updateExtensionVersions.ps1 | 294 ++++++++++++++++++ 2 files changed, 295 insertions(+), 1 deletion(-) create mode 100644 tools/repoUpdateScripts/updateExtensionVersions.ps1 diff --git a/tools/repoUpdateScripts/updateAzureDataStudio.ps1 b/tools/repoUpdateScripts/updateAzureDataStudio.ps1 index e9b0f04bbf..324df87e57 100644 --- a/tools/repoUpdateScripts/updateAzureDataStudio.ps1 +++ b/tools/repoUpdateScripts/updateAzureDataStudio.ps1 @@ -219,7 +219,7 @@ function UpdateGalleryFile $endOffset = GetStringOffsetFromSpan -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 = ReplaceStringSegment -String $galleryFileContent -NewSegment $entryStr -StartIndex $startOffset -EndIndex $endOffset + $newGalleryFileContent = ReplaceStringSegment -String $galleryFileContent -NewSegment $entryStr -StartIndex $startOffset -EndIndex ($endOffset+1) -AutoIndent # Write out the new entry SetFileContent $GalleryFilePath $newGalleryFileContent diff --git a/tools/repoUpdateScripts/updateExtensionVersions.ps1 b/tools/repoUpdateScripts/updateExtensionVersions.ps1 new file mode 100644 index 0000000000..5185b01c33 --- /dev/null +++ b/tools/repoUpdateScripts/updateExtensionVersions.ps1 @@ -0,0 +1,294 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +[CmdletBinding(DefaultParameterSetName='Increment')] +param( + [Parameter(ParameterSetName='Increment')] + [ValidateSet('Major', 'Minor', 'Patch', 'Preview')] + [string] + $IncrementLevel = 'Preview', + + [Parameter(Mandatory, ParameterSetName='SetVersion')] + [semver] + $NewVersion, + + [Parameter(Mandatory)] + [string] + $GitHubToken, + + [Parameter()] + [string] + $TargetFork = 'PowerShell' +) + +Import-Module -Force "$PSScriptRoot/../FileUpdateTools.psm1" +Import-Module -Force "$PSScriptRoot/../GitHubTools.psm1" + +function FindPackageJsonVersionSpan +{ + param( + [Parameter(Mandatory)] + [string] + $PackageJsonContent + ) + + try + { + $reader = [System.IO.StringReader]::new($PackageJsonContent) + $jsonReader = [Newtonsoft.Json.JsonTextReader]::new($reader) + + $depth = 0 + $seenVersion = $false + $versionStartOffset = -1 + $versionStartColumn = -1 + while ($jsonReader.Read()) + { + switch ($jsonReader.TokenType) + { + 'StartObject' + { + $depth++ + continue + } + + 'EndObject' + { + $depth-- + continue + } + + 'PropertyName' + { + if ($depth -ne 1) + { + continue + } + + $seenVersion = $jsonReader.Value -eq 'version' + + if (-not $seenVersion) + { + continue + } + + $currIndex = GetStringOffsetFromSpan -String $PackageJsonContent -EndLine $jsonReader.LineNumber -Column $jsonReader.LinePosition + $versionStartOffset = $PackageJsonContent.IndexOf('"', $currIndex) + 1 + $versionStartColumn = $jsonReader.LinePosition + $versionStartOffset - $currIndex + + continue + } + + 'String' + { + if (-not $seenVersion -or $depth -ne 1) + { + continue + } + + return @{ + Start = $versionStartOffset + End = $versionStartOffset + $jsonReader.LinePosition - $versionStartColumn + } + + continue + } + } + } + } + finally + { + $reader.Dispose() + $jsonReader.Dispose() + } + + throw 'Did not find package.json version field' +} + +function FindRequiredPsesVersionSpan +{ + param( + [Parameter(Mandatory)] + [string] + $MainTsContent + ) + + $pattern = [regex]'const\s+requiredEditorServicesVersion\s+=\s+"(.*)"' + $versionGroup = $pattern.Match($MainTsContent).Groups[1] + + return @{ + Start = $versionGroup.Index + End = $versionGroup.Index + $versionGroup.Length + } +} + +function FindVstsBuildVersionSpan +{ + param( + [Parameter(Mandatory)] + [string] + $DockerFileContent + ) + + $pattern = [regex]'ENV VSTS_BUILD_VERSION=(.*)' + $versionGroup = $pattern.Match($DockerFileContent).Groups[1] + + return @{ + Start = $versionGroup.Index + End = $versionGroup.Index + $versionGroup.Length + } +} + +function IncrementVersion +{ + param( + [Parameter(Mandatory)] + [semver] + $CurrentVersion, + + [Parameter(Mandatory)] + $IncrementLevel + ) + + switch ($IncrementLevel) + { + 'Major' + { + return [semver]::new($version.Major+1, $version.Minor, $version.Patch, $version.PreReleaseLabel) + } + + 'Minor' + { + return [semver]::new($version.Major, $version.Minor+1, $version.Patch, $version.PreReleaseLabel) + } + + 'Patch' + { + return [semver]::new($version.Major, $version.Minor, $version.Patch+1, $version.PreReleaseLabel) + } + + 'Preview' + { + $newPreviewNumber = [int]$version.PreReleaseLabel.Substring(8) + 1 + return [semver]::new($version.Major, $version.Minor, $version.Patch, "preview.$newPreviewNumber") + } + } +} + +function UpdateMainTsPsesVersion +{ + param( + [Parameter(Mandatory)] + [string] + $MainTsPath, + + [Parameter(Mandatory)] + [version] + $Version + ) + + $mainTsContent = Get-Content -Raw $MainTsPath + $mainTsVersionSpan = FindRequiredPsesVersionSpan $mainTsContent + $newMainTsContent = ReplaceStringSegment -String $mainTsContent -NewSegment $Version -StartIndex $mainTsVersionSpan.Start -EndIndex $mainTsVersionSpan.End + if ($newMainTsContent -ne $mainTsContent) + { + SetFileContent -FilePath $MainTsPath -Value $newMainTsContent + } +} + +function UpdateDockerFileVersion +{ + param( + [Parameter(Mandatory)] + [string] + $DockerFilePath, + + [Parameter(Mandatory)] + [version] + $Version + ) + + $vstsDockerFileContent = Get-Content -Raw $DockerFilePath + $vstsDockerFileVersionSpan = FindVstsBuildVersionSpan -DockerFileContent $vstsDockerFileContent + $newDockerFileContent = ReplaceStringSegment -String $vstsDockerFileContent -NewSegment $Version -StartIndex $vstsDockerFileVersionSpan.Start -EndIndex $vstsDockerFileVersionSpan.End + SetFileContent -FilePath $DockerFilePath -Value $newDockerFileContent +} + +# Define locations/branch name +$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'vscps-updateversion-temp' +$paths = @{ + packageJson = "$repoLocation/package.json" + mainTs = "$repoLocation/src/main.ts" + vstsDockerFile = "$repoLocation/tools/releaseBuild/Image/DockerFile" +} + +# Clone the repo +$cloneParams = @{ + OriginRemote = 'https://github.com/rjmholt/vscode-powershell' + Destination = $repoLocation + Clobber = $true + Remotes = @{ + upstream = 'https://github.com/PowerShell/vscode-powershell' + } +} +CloneRepo @cloneParams + +# We may need the version from the package.json, so get that first +$packageJson = Get-Content -Raw $paths.packageJson +$pkgJsonVersionOffsetSpan = FindPackageJsonVersionSpan -PackageJsonContent $packageJson + +# If the option was to increment, we take the existing version and increment it +if ($IncrementLevel) +{ + $version = [semver]$packageJson.Substring($pkgJsonVersionOffsetSpan.Start, $pkgJsonVersionOffsetSpan.End - $pkgJsonVersionOffsetSpan.Start) + $NewVersion = IncrementVersion -CurrentVersion $version -IncrementLevel $IncrementLevel +} + +# Get the marketplace/non-semver versions for various files +$newVersionStr = $NewVersion.ToString() +if ($NewVersion.PreReleaseLabel) +{ + $psesVersion = $newVersionStr.Substring(0, $newVersionStr.IndexOf('-')) + $marketPlaceVersion = [version]::new($NewVersion.Major, $NewVersion.Minor, $NewVersion.PreReleaseLabel.Substring(8)-1) +} +else +{ + $psesVersion = $newVersionStr + $marketPlaceVersion = $newVersionStr +} + +$branchName = "update-version-$newVersionStr" + +# Finally create the new package.json file +$newPkgJsonContent = ReplaceStringSegment -String $packageJson -NewSegment $newVersionStr -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End +SetFileContent -FilePath $paths.packageJson -Value $newPkgJsonContent + +# Create the new content for the main.ts required version file +UpdateMainTsPsesVersion -MainTsPath $paths.mainTs -Version $psesVersion + +# Create the new content for the VSTS dockerfile +UpdateDockerFileVersion -DockerFilePath $paths.vstsDockerFile -Version $marketPlaceVersion + +# Commit and push the changes +$commitParams = @{ + Message = "[Ignore] Increment version to $newVersionStr" + Branch = $branchName + RepoLocation = $repoLocation + File = @( + 'package.json' + 'src/main.ts' + 'tools/releaseBuild/Image/DockerFile' + ) +} +CommitAndPushChanges @commitParams + +# Open a new PR in GitHub +$prParams = @{ + Organization = $TargetFork + Repository = 'vscode-PowerShell' + Branch = $branchName + Title = "Update version to v$newVersionStr" + Description = "Updates version strings in vscode-PowerShell to $newVersionStr.`n**Note**: This is an automated PR." + GitHubToken = $GitHubToken + FromOrg = 'rjmholt' +} +OpenGitHubPr @prParams \ No newline at end of file From 0695254ac6e315e7932012c01ec27784abc46f07 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 30 Apr 2019 09:57:47 +1000 Subject: [PATCH 04/18] Improve existing scripts, add PSES update script --- .../updateAzureDataStudio.ps1 | 23 +- .../updateExtensionVersions.ps1 | 81 +++---- .../repoUpdateScripts/updatePsesVersions.ps1 | 217 ++++++++++++++++++ 3 files changed, 272 insertions(+), 49 deletions(-) create mode 100644 tools/repoUpdateScripts/updatePsesVersions.ps1 diff --git a/tools/repoUpdateScripts/updateAzureDataStudio.ps1 b/tools/repoUpdateScripts/updateAzureDataStudio.ps1 index 324df87e57..932d2d679a 100644 --- a/tools/repoUpdateScripts/updateAzureDataStudio.ps1 +++ b/tools/repoUpdateScripts/updateAzureDataStudio.ps1 @@ -16,7 +16,15 @@ param( [Parameter()] [string] - $TargetFork = 'Microsoft' + $TargetFork = 'Microsoft', + + [Parameter()] + [string] + $BranchName, + + [Parameter()] + [string] + $PRDescription ) Import-Module "$PSScriptRoot/../GitHubTools.psm1" -Force @@ -226,7 +234,16 @@ function UpdateGalleryFile } $repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'ads-temp-checkout' -$branchName = "update-psext-$ExtensionVersion" + +if (-not $BranchName) +{ + $BranchName = "update-psext-$ExtensionVersion" +} + +if (-not $PRDescription) +{ + $PRDescription = "Updates the version of the PowerShell extension in ADS to $ExtensionVersion.`n**Note**: This is an automated PR." +} $cloneParams = @{ OriginRemote = 'https://github.com/rjmholt/AzureDataStudio' @@ -250,7 +267,7 @@ $prParams = @{ TargetBranch = 'release/extensions' Branch = $branchName Title = "Update PowerShell extension to v$ExtensionVersion" - Description = "Updates the version of the PowerShell extension in ADS to $ExtensionVersion.`n**Note**: This is an automated PR." + Description = $PRDescription GitHubToken = $GitHubToken FromOrg = 'rjmholt' } diff --git a/tools/repoUpdateScripts/updateExtensionVersions.ps1 b/tools/repoUpdateScripts/updateExtensionVersions.ps1 index 5185b01c33..f3999cc60c 100644 --- a/tools/repoUpdateScripts/updateExtensionVersions.ps1 +++ b/tools/repoUpdateScripts/updateExtensionVersions.ps1 @@ -18,7 +18,15 @@ param( [Parameter()] [string] - $TargetFork = 'PowerShell' + $TargetFork = 'PowerShell', + + [Parameter()] + [string] + $BranchName, + + [Parameter()] + [string] + $PRDescription ) Import-Module -Force "$PSScriptRoot/../FileUpdateTools.psm1" @@ -138,42 +146,6 @@ function FindVstsBuildVersionSpan } } -function IncrementVersion -{ - param( - [Parameter(Mandatory)] - [semver] - $CurrentVersion, - - [Parameter(Mandatory)] - $IncrementLevel - ) - - switch ($IncrementLevel) - { - 'Major' - { - return [semver]::new($version.Major+1, $version.Minor, $version.Patch, $version.PreReleaseLabel) - } - - 'Minor' - { - return [semver]::new($version.Major, $version.Minor+1, $version.Patch, $version.PreReleaseLabel) - } - - 'Patch' - { - return [semver]::new($version.Major, $version.Minor, $version.Patch+1, $version.PreReleaseLabel) - } - - 'Preview' - { - $newPreviewNumber = [int]$version.PreReleaseLabel.Substring(8) + 1 - return [semver]::new($version.Major, $version.Minor, $version.Patch, "preview.$newPreviewNumber") - } - } -} - function UpdateMainTsPsesVersion { param( @@ -213,6 +185,23 @@ function UpdateDockerFileVersion SetFileContent -FilePath $DockerFilePath -Value $newDockerFileContent } +function GetMarketplaceVersionFromSemVer +{ + [OutputType([version])] + param( + [Parameter(Mandatory)] + [semver] + $SemVer + ) + + if (-not $SemVer.PreReleaseLabel) + { + return [version]($SemVer.ToString()) + } + + return [version]::new($NewVersion.Major, $NewVersion.Minor, $NewVersion.PreReleaseLabel.Substring(8)-1) +} + # Define locations/branch name $repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'vscps-updateversion-temp' $paths = @{ @@ -245,19 +234,19 @@ if ($IncrementLevel) # Get the marketplace/non-semver versions for various files $newVersionStr = $NewVersion.ToString() -if ($NewVersion.PreReleaseLabel) +$psesVersion = GetVersionFromSemVer -SemVer $NewVersion +$marketPlaceVersion = GetMarketplaceVersionFromSemVer -SemVer $NewVersion + +if (-not $BranchName) { - $psesVersion = $newVersionStr.Substring(0, $newVersionStr.IndexOf('-')) - $marketPlaceVersion = [version]::new($NewVersion.Major, $NewVersion.Minor, $NewVersion.PreReleaseLabel.Substring(8)-1) + $BranchName = "update-version-$newVersionStr" } -else + +if (-not $PRDescription) { - $psesVersion = $newVersionStr - $marketPlaceVersion = $newVersionStr + $PRDescription = "Updates version strings in vscode-PowerShell to $newVersionStr.`n**Note**: This is an automated PR." } -$branchName = "update-version-$newVersionStr" - # Finally create the new package.json file $newPkgJsonContent = ReplaceStringSegment -String $packageJson -NewSegment $newVersionStr -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End SetFileContent -FilePath $paths.packageJson -Value $newPkgJsonContent @@ -287,7 +276,7 @@ $prParams = @{ Repository = 'vscode-PowerShell' Branch = $branchName Title = "Update version to v$newVersionStr" - Description = "Updates version strings in vscode-PowerShell to $newVersionStr.`n**Note**: This is an automated PR." + Description = $PRDescription GitHubToken = $GitHubToken FromOrg = 'rjmholt' } diff --git a/tools/repoUpdateScripts/updatePsesVersions.ps1 b/tools/repoUpdateScripts/updatePsesVersions.ps1 new file mode 100644 index 0000000000..437675043c --- /dev/null +++ b/tools/repoUpdateScripts/updatePsesVersions.ps1 @@ -0,0 +1,217 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +[CmdletBinding(DefaultParameterSetName='Increment')] +param( + [Parameter(ParameterSetName='Increment')] + [ValidateSet('Major', 'Minor', 'Patch', 'Preview')] + [string] + $IncrementLevel = 'Preview', + + [Parameter(Mandatory, ParameterSetName='SetVersion')] + [semver] + $NewVersion, + + [Parameter(Mandatory)] + [string] + $GitHubToken, + + [Parameter()] + [string] + $TargetFork = 'PowerShell', + + [Parameter()] + [string] + $BranchName, + + [Parameter()] + [string] + $PRDescription +) + +Import-Module "$PSScriptRoot/../GitHubTools.psm1" +Import-Module "$PSScriptRoot/../FileUpdateTools.psm1" + +function FindPsesModuleSpan +{ + param( + [Parameter()] + [string] + $ModuleManifestContent + ) + + # Inscrutable regex looks for PSD1 "ModuleVersion = '2.0.0'" type of field + $pattern = [regex]'\s*ModuleVersion\s*=\s*(?:''|")(\d+?(?:\.\d+?(?:\.\d+)))(?:''|")' + + $versionGroup = $pattern.Match($ModuleManifestContent).Groups[1] + + return @{ + Start = $versionGroup.Index + End = $versionGroup.Index + $versionGroup.Length + } +} + +function UpdatePsesModuleVersion +{ + param( + [Parameter()] + [string] + $PsesModuleManifestPath, + + [Parameter()] + [semver] + $NewVersion + ) + + $version = GetVersionFromSemVer -SemVer $NewVersion + + $PsesModuleManifestPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PsesModuleManifestPath) + + $manifestContent = Get-Content -Raw $PsesModuleManifestPath + + $span = FindPsesModuleSpan -ModuleManifestContent $manifestContent + + $newContent = ReplaceStringSegment -String $manifestContent -NewSegment $version -StartIndex $span.Start -EndIndex $span.End + + SetFileContent -FilePath $PsesModuleManifestPath -Value $newContent +} + +function GetPsesCurrentVersion +{ + [OutputType([semver])] + param( + [Parameter()] + [string] + $PsesPropsPath + ) + + $propsXml = [xml](Get-Content -Raw $PsesPropsPath) + + $version = $propsXml.Project.PropertyGroup.VersionPrefix + $prereleaseTag = $propsXml.Project.PropertyGroup.VersionSuffix + if ($prereleaseTag) + { + $version = "$version-$prereleaseTag" + } + + return [semver]$version +} + +function UpdatePsesPropsXml +{ + param( + [Parameter(Mandatory)] + [semver] + $NewVersion, + + [Parameter(Mandatory)] + [string] + $PsesPropsPath + ) + + $PsesPropsPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PsesPropsPath) + + $propsXml = [xml](Get-Content -Raw $PsesPropsPath) + + $versionParts = $NewVersion.ToString().Split('-') + + if ($versionParts.Length -eq 2) + { + $propsXml.Project.PropertyGroup.VersionPrefix = $versionParts[0] + $propsXml.Project.PropertyGroup.VersionSuffix = $versionParts[1] + } + else + { + $propsXml.Project.PropertyGroup.VersionPrefix = $versionParts[0] + + # Remove the prerelease tag if it's present + $prereleaseNode = $propsXml.Project.PropertyGroup.GetElementsByTagName('VersionSuffix') + if ($prereleaseNode) + { + $null = $propsXml.Project.PropertyGroup.RemoveChild($prereleaseNode[0]) + } + } + + $xmlWriterSettings = [System.Xml.XmlWriterSettings]@{ + Encoding = [System.Text.UTF8Encoding]::new(<# BOM #>$false) + OmitXmlDeclaration = $true + Indent = $true + IndentChars = " " + NewLineHandling = 'Replace' + NewLineChars = "`r`n" + } + $xmlWriter = [System.Xml.XmlWriter]::Create($PsesPropsPath, $xmlWriterSettings) + try + { + $propsXml.Save($xmlWriter) + } + finally + { + $xmlWriter.Dispose() + } +} + +$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'pses-update-temp' +$paths = @{ + props = "$repoLocation/PowerShellEditorServices.Common.props" + manifest = "$repoLocation/module/PowerShellEditorServices/PowerShellEditorServices.psd1" +} + +if (-not $BranchName) +{ + $BranchName = "update-pses-version-$NewVersion" +} + +if (-not $PRDescription) +{ + $PRDescription = "Updates PSES to version $NewVersion.**Note**: This is an automated PR." +} + +# Clone the PSES repo +$cloneParams = @{ + OriginRemote = 'https://github.com/rjmholt/PowerShellEditorServices' + Destination = $repoLocation + CheckoutBranch = $BranchName + Remotes = @{ + upstream = 'https://github.com/PowerShell/PowerShellEditorServices' + } + Clobber = $true +} +CloneRepo @cloneParams + +# If we need to increment the version, do that +if ($IncrementLevel) +{ + $currVersion = GetPsesCurrentVersion -PsesPropsPath $paths.props + $NewVersion = IncrementVersion -CurrentVersion $currVersion -IncrementLevel $IncrementLevel +} + +# Update the Props XML file +UpdatePsesPropsXml -NewVersion $NewVersion -PsesPropsPath $paths.props + +# Update the PSD1 file +UpdatePsesModuleVersion -PsesModuleManifestPath $paths.manifest -NewVersion $NewVersion + +# Commit changes +$commitParams = @{ + RepoLocation = $repoLocation + Message = "[Ignore] Update PSES version to $NewVersion" + Branch = $BranchName + File = @( + 'PowerShellEditorServices.Common.props' + 'module/PowerShellEditorServices/PowerShellEditorServices.psd1' + ) +} +CommitAndPushChanges @commitParams + +# Open a PR +$prParams = @{ + Branch = $BranchName + Title = "Update PowerShellEditorServices version to $NewVersion" + GitHubToken = $GitHubToken + Organization = $TargetFork + Repository = 'PowerShellEditorServices' + Description = $PRDescription + FromOrg = 'rjmholt' +} +OpenGitHubPr @prParams \ No newline at end of file From 1d68f0c9adaf3833c523ea661ac6b18e8e030b35 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 30 Apr 2019 10:10:49 +1000 Subject: [PATCH 05/18] Fix param name issue --- tools/repoUpdateScripts/updateExtensionVersions.ps1 | 2 +- tools/repoUpdateScripts/updatePsesVersions.ps1 | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/repoUpdateScripts/updateExtensionVersions.ps1 b/tools/repoUpdateScripts/updateExtensionVersions.ps1 index f3999cc60c..96f60fee35 100644 --- a/tools/repoUpdateScripts/updateExtensionVersions.ps1 +++ b/tools/repoUpdateScripts/updateExtensionVersions.ps1 @@ -229,7 +229,7 @@ $pkgJsonVersionOffsetSpan = FindPackageJsonVersionSpan -PackageJsonContent $pack if ($IncrementLevel) { $version = [semver]$packageJson.Substring($pkgJsonVersionOffsetSpan.Start, $pkgJsonVersionOffsetSpan.End - $pkgJsonVersionOffsetSpan.Start) - $NewVersion = IncrementVersion -CurrentVersion $version -IncrementLevel $IncrementLevel + $NewVersion = IncrementVersion -Version $version -IncrementLevel $IncrementLevel } # Get the marketplace/non-semver versions for various files diff --git a/tools/repoUpdateScripts/updatePsesVersions.ps1 b/tools/repoUpdateScripts/updatePsesVersions.ps1 index 437675043c..45f277d623 100644 --- a/tools/repoUpdateScripts/updatePsesVersions.ps1 +++ b/tools/repoUpdateScripts/updatePsesVersions.ps1 @@ -29,8 +29,8 @@ param( $PRDescription ) -Import-Module "$PSScriptRoot/../GitHubTools.psm1" -Import-Module "$PSScriptRoot/../FileUpdateTools.psm1" +Import-Module "$PSScriptRoot/../GitHubTools.psm1" -Force +Import-Module "$PSScriptRoot/../FileUpdateTools.psm1" -Force function FindPsesModuleSpan { @@ -144,6 +144,7 @@ function UpdatePsesPropsXml try { $propsXml.Save($xmlWriter) + $xmlWriter.WriteWhitespace("`r`n") } finally { @@ -183,7 +184,7 @@ CloneRepo @cloneParams if ($IncrementLevel) { $currVersion = GetPsesCurrentVersion -PsesPropsPath $paths.props - $NewVersion = IncrementVersion -CurrentVersion $currVersion -IncrementLevel $IncrementLevel + $NewVersion = IncrementVersion -Version $currVersion -IncrementLevel $IncrementLevel } # Update the Props XML file From bd2001e8110eb8d076213166ec3bae4caba0ad93 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Wed, 1 May 2019 08:45:58 +1000 Subject: [PATCH 06/18] Update tools/repoUpdateScripts/updatePsesVersions.ps1 Co-Authored-By: rjmholt --- tools/repoUpdateScripts/updatePsesVersions.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/repoUpdateScripts/updatePsesVersions.ps1 b/tools/repoUpdateScripts/updatePsesVersions.ps1 index 45f277d623..4dd40eff03 100644 --- a/tools/repoUpdateScripts/updatePsesVersions.ps1 +++ b/tools/repoUpdateScripts/updatePsesVersions.ps1 @@ -215,4 +215,4 @@ $prParams = @{ Description = $PRDescription FromOrg = 'rjmholt' } -OpenGitHubPr @prParams \ No newline at end of file +OpenGitHubPr @prParams From 934f71a5b9fed40b7f188451f246260e4913bd9d Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 09:10:50 +1000 Subject: [PATCH 07/18] Simplify default parameters, move dir --- .../updateAzureDataStudio.ps1 | 18 +- .../updateExtensionVersions.ps1 | 49 ++- .../postReleaseScripts/updatePsesVersions.ps1 | 32 +- .../updateAzureDataStudio.ps1 | 274 ----------------- .../updateExtensionVersions.ps1 | 283 ------------------ .../repoUpdateScripts/updatePsesVersions.ps1 | 218 -------------- 6 files changed, 36 insertions(+), 838 deletions(-) delete mode 100644 tools/repoUpdateScripts/updateAzureDataStudio.ps1 delete mode 100644 tools/repoUpdateScripts/updateExtensionVersions.ps1 delete mode 100644 tools/repoUpdateScripts/updatePsesVersions.ps1 diff --git a/tools/postReleaseScripts/updateAzureDataStudio.ps1 b/tools/postReleaseScripts/updateAzureDataStudio.ps1 index 55ff86794c..00cd9eb656 100644 --- a/tools/postReleaseScripts/updateAzureDataStudio.ps1 +++ b/tools/postReleaseScripts/updateAzureDataStudio.ps1 @@ -1,8 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -#requires -Version 6.0 - param( [Parameter(Mandatory)] [string] @@ -220,19 +218,19 @@ function UpdateGalleryFile # Create a new PowerShell extension entry $powershellEntry = NewPowerShellExtensionEntry -ExtensionVersion $ExtensionVersion - $entryStr = ConvertTo-IndentedJson $powershellEntry -IndentChar "`t" -IndentWidth 1 + $entryStr = ConvertToIndentedJson $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 + $startOffset = GetStringOffsetFromSpan -String $galleryFileContent -EndLine $span.Start.Line -Column $span.Start.Column + $endOffset = GetStringOffsetFromSpan -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 + $newGalleryFileContent = ReplaceStringSegment -String $galleryFileContent -NewSegment $entryStr -StartIndex $startOffset -EndIndex ($endOffset+1) -AutoIndent # Write out the new entry - Set-Content -Path $GalleryFilePath -Value $newGalleryFileContent -Encoding utf8NoBOM -NoNewline + SetFileContent $GalleryFilePath $newGalleryFileContent } $repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'ads-temp-checkout' @@ -247,11 +245,11 @@ $cloneParams = @{ upstream = 'https://github.com/Microsoft/AzureDataStudio' } } -Copy-GitRepository @cloneParams +CloneRepo @cloneParams UpdateGalleryFile -ExtensionVersion $ExtensionVersion -GalleryFilePath "$repoLocation/$GalleryFileName" -Submit-GitChanges -RepositoryLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update PS extension to v$ExtensionVersion" +CommitAndPushChanges -RepoLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update PS extension to v$ExtensionVersion" $prParams = @{ Organization = $TargetFork @@ -263,4 +261,4 @@ $prParams = @{ GitHubToken = $GitHubToken FromOrg = 'rjmholt' } -New-GitHubPR @prParams +OpenGitHubPr @prParams \ No newline at end of file diff --git a/tools/postReleaseScripts/updateExtensionVersions.ps1 b/tools/postReleaseScripts/updateExtensionVersions.ps1 index 974a6e43f7..9f8d909595 100644 --- a/tools/postReleaseScripts/updateExtensionVersions.ps1 +++ b/tools/postReleaseScripts/updateExtensionVersions.ps1 @@ -1,8 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -#requires -Version 6.0 - [CmdletBinding(DefaultParameterSetName='Increment')] param( [Parameter(ParameterSetName='Increment')] @@ -24,13 +22,11 @@ param( [Parameter()] [string] - # Default set below, requires processing when $IncrementVersion is used - $BranchName, + $BranchName = "update-version-$newVersionStr", [Parameter()] [string] - # Default set below, requires processing when $IncrementVersion is used - $PRDescription + $PRDescription = "Updates version strings in vscode-PowerShell to $newVersionStr.`n**Note**: This is an automated PR." ) Import-Module -Force "$PSScriptRoot/../FileUpdateTools.psm1" @@ -83,7 +79,7 @@ function FindPackageJsonVersionSpan continue } - $currIndex = Get-StringOffsetFromSpan -String $PackageJsonContent -EndLine $jsonReader.LineNumber -Column $jsonReader.LinePosition + $currIndex = GetStringOffsetFromSpan -String $PackageJsonContent -EndLine $jsonReader.LineNumber -Column $jsonReader.LinePosition $versionStartOffset = $PackageJsonContent.IndexOf('"', $currIndex) + 1 $versionStartColumn = $jsonReader.LinePosition + $versionStartOffset - $currIndex @@ -164,10 +160,10 @@ function UpdateMainTsPsesVersion $mainTsContent = Get-Content -Raw $MainTsPath $mainTsVersionSpan = FindRequiredPsesVersionSpan $mainTsContent - $newMainTsContent = New-StringWithSegment -String $mainTsContent -NewSegment $Version -StartIndex $mainTsVersionSpan.Start -EndIndex $mainTsVersionSpan.End + $newMainTsContent = ReplaceStringSegment -String $mainTsContent -NewSegment $Version -StartIndex $mainTsVersionSpan.Start -EndIndex $mainTsVersionSpan.End if ($newMainTsContent -ne $mainTsContent) { - Set-Content -Path $MainTsPath -Value $newMainTsContent -Encoding utf8NoBOM -NoNewline + SetFileContent -FilePath $MainTsPath -Value $newMainTsContent } } @@ -185,8 +181,8 @@ function UpdateDockerFileVersion $vstsDockerFileContent = Get-Content -Raw $DockerFilePath $vstsDockerFileVersionSpan = FindVstsBuildVersionSpan -DockerFileContent $vstsDockerFileContent - $newDockerFileContent = New-StringWithSegment -String $vstsDockerFileContent -NewSegment $Version -StartIndex $vstsDockerFileVersionSpan.Start -EndIndex $vstsDockerFileVersionSpan.End - Set-Content -Path $DockerFilePath -Value $newDockerFileContent -Encoding utf8NoBOM -NoNewline + $newDockerFileContent = ReplaceStringSegment -String $vstsDockerFileContent -NewSegment $Version -StartIndex $vstsDockerFileVersionSpan.Start -EndIndex $vstsDockerFileVersionSpan.End + SetFileContent -FilePath $DockerFilePath -Value $newDockerFileContent } function GetMarketplaceVersionFromSemVer @@ -223,7 +219,7 @@ $cloneParams = @{ upstream = 'https://github.com/PowerShell/vscode-powershell' } } -Copy-GitRepository @cloneParams +CloneRepo @cloneParams # We may need the version from the package.json, so get that first $packageJson = Get-Content -Raw $paths.packageJson @@ -233,26 +229,17 @@ $pkgJsonVersionOffsetSpan = FindPackageJsonVersionSpan -PackageJsonContent $pack if ($IncrementLevel) { $version = [semver]$packageJson.Substring($pkgJsonVersionOffsetSpan.Start, $pkgJsonVersionOffsetSpan.End - $pkgJsonVersionOffsetSpan.Start) - $NewVersion = Get-IncrementedVersion -Version $version -IncrementLevel $IncrementLevel -} - -if (-not $BranchName) -{ - $BranchName = "update-version-$NewVersion" -} - -if (-not $PRDescription) -{ - $PRDescription = "Updates version strings in vscode-PowerShell to $NewVersion.`n**Note**: This is an automated PR." + $NewVersion = IncrementVersion -Version $version -IncrementLevel $IncrementLevel } # Get the marketplace/non-semver versions for various files -$psesVersion = Get-VersionFromSemVer -SemVer $NewVersion +$newVersionStr = $NewVersion.ToString() +$psesVersion = GetVersionFromSemVer -SemVer $NewVersion $marketPlaceVersion = GetMarketplaceVersionFromSemVer -SemVer $NewVersion # Finally create the new package.json file -$newPkgJsonContent = New-StringWithSegment -String $packageJson -NewSegment $NewVersion -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End -Set-Content -Path $paths.packageJson -Value $newPkgJsonContent -Encoding utf8NoBOM -NoNewline +$newPkgJsonContent = ReplaceStringSegment -String $packageJson -NewSegment $newVersionStr -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End +SetFileContent -FilePath $paths.packageJson -Value $newPkgJsonContent # Create the new content for the main.ts required version file UpdateMainTsPsesVersion -MainTsPath $paths.mainTs -Version $psesVersion @@ -262,25 +249,25 @@ UpdateDockerFileVersion -DockerFilePath $paths.vstsDockerFile -Version $marketPl # Commit and push the changes $commitParams = @{ - Message = "[Ignore] Increment version to $NewVersion" + Message = "[Ignore] Increment version to $newVersionStr" Branch = $branchName - RepositoryLocation = $repoLocation + RepoLocation = $repoLocation File = @( 'package.json' 'src/main.ts' 'tools/releaseBuild/Image/DockerFile' ) } -Submit-GitChanges @commitParams +CommitAndPushChanges @commitParams # Open a new PR in GitHub $prParams = @{ Organization = $TargetFork Repository = 'vscode-PowerShell' Branch = $branchName - Title = "Update version to v$NewVersion" + Title = "Update version to v$newVersionStr" Description = $PRDescription GitHubToken = $GitHubToken FromOrg = 'rjmholt' } -New-GitHubPR @prParams +OpenGitHubPr @prParams \ No newline at end of file diff --git a/tools/postReleaseScripts/updatePsesVersions.ps1 b/tools/postReleaseScripts/updatePsesVersions.ps1 index c4222d1d71..093fae9812 100644 --- a/tools/postReleaseScripts/updatePsesVersions.ps1 +++ b/tools/postReleaseScripts/updatePsesVersions.ps1 @@ -1,8 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -#requires -Version 6.0 - [CmdletBinding(DefaultParameterSetName='Increment')] param( [Parameter(ParameterSetName='Increment')] @@ -24,11 +22,11 @@ param( [Parameter()] [string] - $BranchName, + $BranchName = "update-pses-version-$NewVersion", [Parameter()] [string] - $PRDescription + $PRDescription = "Updates PSES to version $NewVersion.**Note**: This is an automated PR." ) Import-Module "$PSScriptRoot/../GitHubTools.psm1" -Force @@ -65,7 +63,7 @@ function UpdatePsesModuleVersion $NewVersion ) - $version = Get-VersionFromSemVer -SemVer $NewVersion + $version = GetVersionFromSemVer -SemVer $NewVersion $PsesModuleManifestPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PsesModuleManifestPath) @@ -73,9 +71,9 @@ function UpdatePsesModuleVersion $span = FindPsesModuleSpan -ModuleManifestContent $manifestContent - $newContent = New-StringWithSegment -String $manifestContent -NewSegment $version -StartIndex $span.Start -EndIndex $span.End + $newContent = ReplaceStringSegment -String $manifestContent -NewSegment $version -StartIndex $span.Start -EndIndex $span.End - Set-Content -Path $PsesModuleManifestPath -Value $newContent -Encoding utf8NoBOM -NoNewline + SetFileContent -FilePath $PsesModuleManifestPath -Value $newContent } function GetPsesCurrentVersion @@ -170,23 +168,13 @@ $cloneParams = @{ } Clobber = $true } -Copy-GitRepository @cloneParams +CloneRepo @cloneParams # If we need to increment the version, do that if ($IncrementLevel) { $currVersion = GetPsesCurrentVersion -PsesPropsPath $paths.props - $NewVersion = Get-IncrementedVersion -Version $currVersion -IncrementLevel $IncrementLevel -} - -if (-not $BranchName) -{ - $BranchName = "update-pses-version-$NewVersion" -} - -if (-not $PRDescription) -{ - $PRDescription = "Updates PSES to version $NewVersion.**Note**: This is an automated PR." + $NewVersion = IncrementVersion -Version $currVersion -IncrementLevel $IncrementLevel } # Update the Props XML file @@ -197,7 +185,7 @@ UpdatePsesModuleVersion -PsesModuleManifestPath $paths.manifest -NewVersion $New # Commit changes $commitParams = @{ - RepositoryLocation = $repoLocation + RepoLocation = $repoLocation Message = "[Ignore] Update PSES version to $NewVersion" Branch = $BranchName File = @( @@ -205,7 +193,7 @@ $commitParams = @{ 'module/PowerShellEditorServices/PowerShellEditorServices.psd1' ) } -Submit-GitChanges @commitParams +CommitAndPushChanges @commitParams # Open a PR $prParams = @{ @@ -217,4 +205,4 @@ $prParams = @{ Description = $PRDescription FromOrg = 'rjmholt' } -New-GitHubPR @prParams +OpenGitHubPr @prParams diff --git a/tools/repoUpdateScripts/updateAzureDataStudio.ps1 b/tools/repoUpdateScripts/updateAzureDataStudio.ps1 deleted file mode 100644 index 932d2d679a..0000000000 --- a/tools/repoUpdateScripts/updateAzureDataStudio.ps1 +++ /dev/null @@ -1,274 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -param( - [Parameter(Mandatory)] - [string] - $GitHubToken, - - [Parameter(Mandatory)] - [version] - $ExtensionVersion, - - [Parameter()] - [string] - $GalleryFileName = 'extensionsGallery.json', - - [Parameter()] - [string] - $TargetFork = 'Microsoft', - - [Parameter()] - [string] - $BranchName, - - [Parameter()] - [string] - $PRDescription -) - -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/PowerShell-$Version.vsix" - } - [ordered]@{ - assetType = 'Microsoft.VisualStudio.Services.Icons.Default' - source = 'https://raw.githubusercontent.com/PowerShell/vscode-powershell/master/images/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 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()] - [string] - $GalleryFilePath = './extensionsGallery-insider.json' - ) - - # Create a new PowerShell extension entry - $powershellEntry = NewPowerShellExtensionEntry -ExtensionVersion $ExtensionVersion - $entryStr = ConvertToIndentedJson $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 = GetStringOffsetFromSpan -String $galleryFileContent -EndLine $span.Start.Line -Column $span.Start.Column - $endOffset = GetStringOffsetFromSpan -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 = ReplaceStringSegment -String $galleryFileContent -NewSegment $entryStr -StartIndex $startOffset -EndIndex ($endOffset+1) -AutoIndent - - # Write out the new entry - SetFileContent $GalleryFilePath $newGalleryFileContent -} - -$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'ads-temp-checkout' - -if (-not $BranchName) -{ - $BranchName = "update-psext-$ExtensionVersion" -} - -if (-not $PRDescription) -{ - $PRDescription = "Updates the version of the PowerShell extension in ADS to $ExtensionVersion.`n**Note**: This is an automated PR." -} - -$cloneParams = @{ - OriginRemote = 'https://github.com/rjmholt/AzureDataStudio' - Destination = $repoLocation - CloneBranch = 'release/extensions' - CheckoutBranch = $branchName - Clobber = $true - Remotes = @{ - upstream = 'https://github.com/Microsoft/AzureDataStudio' - } -} -CloneRepo @cloneParams - -UpdateGalleryFile -ExtensionVersion $ExtensionVersion -GalleryFilePath "$repoLocation/$GalleryFileName" - -CommitAndPushChanges -RepoLocation $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 = 'rjmholt' -} -OpenGitHubPr @prParams \ No newline at end of file diff --git a/tools/repoUpdateScripts/updateExtensionVersions.ps1 b/tools/repoUpdateScripts/updateExtensionVersions.ps1 deleted file mode 100644 index 96f60fee35..0000000000 --- a/tools/repoUpdateScripts/updateExtensionVersions.ps1 +++ /dev/null @@ -1,283 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -[CmdletBinding(DefaultParameterSetName='Increment')] -param( - [Parameter(ParameterSetName='Increment')] - [ValidateSet('Major', 'Minor', 'Patch', 'Preview')] - [string] - $IncrementLevel = 'Preview', - - [Parameter(Mandatory, ParameterSetName='SetVersion')] - [semver] - $NewVersion, - - [Parameter(Mandatory)] - [string] - $GitHubToken, - - [Parameter()] - [string] - $TargetFork = 'PowerShell', - - [Parameter()] - [string] - $BranchName, - - [Parameter()] - [string] - $PRDescription -) - -Import-Module -Force "$PSScriptRoot/../FileUpdateTools.psm1" -Import-Module -Force "$PSScriptRoot/../GitHubTools.psm1" - -function FindPackageJsonVersionSpan -{ - param( - [Parameter(Mandatory)] - [string] - $PackageJsonContent - ) - - try - { - $reader = [System.IO.StringReader]::new($PackageJsonContent) - $jsonReader = [Newtonsoft.Json.JsonTextReader]::new($reader) - - $depth = 0 - $seenVersion = $false - $versionStartOffset = -1 - $versionStartColumn = -1 - while ($jsonReader.Read()) - { - switch ($jsonReader.TokenType) - { - 'StartObject' - { - $depth++ - continue - } - - 'EndObject' - { - $depth-- - continue - } - - 'PropertyName' - { - if ($depth -ne 1) - { - continue - } - - $seenVersion = $jsonReader.Value -eq 'version' - - if (-not $seenVersion) - { - continue - } - - $currIndex = GetStringOffsetFromSpan -String $PackageJsonContent -EndLine $jsonReader.LineNumber -Column $jsonReader.LinePosition - $versionStartOffset = $PackageJsonContent.IndexOf('"', $currIndex) + 1 - $versionStartColumn = $jsonReader.LinePosition + $versionStartOffset - $currIndex - - continue - } - - 'String' - { - if (-not $seenVersion -or $depth -ne 1) - { - continue - } - - return @{ - Start = $versionStartOffset - End = $versionStartOffset + $jsonReader.LinePosition - $versionStartColumn - } - - continue - } - } - } - } - finally - { - $reader.Dispose() - $jsonReader.Dispose() - } - - throw 'Did not find package.json version field' -} - -function FindRequiredPsesVersionSpan -{ - param( - [Parameter(Mandatory)] - [string] - $MainTsContent - ) - - $pattern = [regex]'const\s+requiredEditorServicesVersion\s+=\s+"(.*)"' - $versionGroup = $pattern.Match($MainTsContent).Groups[1] - - return @{ - Start = $versionGroup.Index - End = $versionGroup.Index + $versionGroup.Length - } -} - -function FindVstsBuildVersionSpan -{ - param( - [Parameter(Mandatory)] - [string] - $DockerFileContent - ) - - $pattern = [regex]'ENV VSTS_BUILD_VERSION=(.*)' - $versionGroup = $pattern.Match($DockerFileContent).Groups[1] - - return @{ - Start = $versionGroup.Index - End = $versionGroup.Index + $versionGroup.Length - } -} - -function UpdateMainTsPsesVersion -{ - param( - [Parameter(Mandatory)] - [string] - $MainTsPath, - - [Parameter(Mandatory)] - [version] - $Version - ) - - $mainTsContent = Get-Content -Raw $MainTsPath - $mainTsVersionSpan = FindRequiredPsesVersionSpan $mainTsContent - $newMainTsContent = ReplaceStringSegment -String $mainTsContent -NewSegment $Version -StartIndex $mainTsVersionSpan.Start -EndIndex $mainTsVersionSpan.End - if ($newMainTsContent -ne $mainTsContent) - { - SetFileContent -FilePath $MainTsPath -Value $newMainTsContent - } -} - -function UpdateDockerFileVersion -{ - param( - [Parameter(Mandatory)] - [string] - $DockerFilePath, - - [Parameter(Mandatory)] - [version] - $Version - ) - - $vstsDockerFileContent = Get-Content -Raw $DockerFilePath - $vstsDockerFileVersionSpan = FindVstsBuildVersionSpan -DockerFileContent $vstsDockerFileContent - $newDockerFileContent = ReplaceStringSegment -String $vstsDockerFileContent -NewSegment $Version -StartIndex $vstsDockerFileVersionSpan.Start -EndIndex $vstsDockerFileVersionSpan.End - SetFileContent -FilePath $DockerFilePath -Value $newDockerFileContent -} - -function GetMarketplaceVersionFromSemVer -{ - [OutputType([version])] - param( - [Parameter(Mandatory)] - [semver] - $SemVer - ) - - if (-not $SemVer.PreReleaseLabel) - { - return [version]($SemVer.ToString()) - } - - return [version]::new($NewVersion.Major, $NewVersion.Minor, $NewVersion.PreReleaseLabel.Substring(8)-1) -} - -# Define locations/branch name -$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'vscps-updateversion-temp' -$paths = @{ - packageJson = "$repoLocation/package.json" - mainTs = "$repoLocation/src/main.ts" - vstsDockerFile = "$repoLocation/tools/releaseBuild/Image/DockerFile" -} - -# Clone the repo -$cloneParams = @{ - OriginRemote = 'https://github.com/rjmholt/vscode-powershell' - Destination = $repoLocation - Clobber = $true - Remotes = @{ - upstream = 'https://github.com/PowerShell/vscode-powershell' - } -} -CloneRepo @cloneParams - -# We may need the version from the package.json, so get that first -$packageJson = Get-Content -Raw $paths.packageJson -$pkgJsonVersionOffsetSpan = FindPackageJsonVersionSpan -PackageJsonContent $packageJson - -# If the option was to increment, we take the existing version and increment it -if ($IncrementLevel) -{ - $version = [semver]$packageJson.Substring($pkgJsonVersionOffsetSpan.Start, $pkgJsonVersionOffsetSpan.End - $pkgJsonVersionOffsetSpan.Start) - $NewVersion = IncrementVersion -Version $version -IncrementLevel $IncrementLevel -} - -# Get the marketplace/non-semver versions for various files -$newVersionStr = $NewVersion.ToString() -$psesVersion = GetVersionFromSemVer -SemVer $NewVersion -$marketPlaceVersion = GetMarketplaceVersionFromSemVer -SemVer $NewVersion - -if (-not $BranchName) -{ - $BranchName = "update-version-$newVersionStr" -} - -if (-not $PRDescription) -{ - $PRDescription = "Updates version strings in vscode-PowerShell to $newVersionStr.`n**Note**: This is an automated PR." -} - -# Finally create the new package.json file -$newPkgJsonContent = ReplaceStringSegment -String $packageJson -NewSegment $newVersionStr -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End -SetFileContent -FilePath $paths.packageJson -Value $newPkgJsonContent - -# Create the new content for the main.ts required version file -UpdateMainTsPsesVersion -MainTsPath $paths.mainTs -Version $psesVersion - -# Create the new content for the VSTS dockerfile -UpdateDockerFileVersion -DockerFilePath $paths.vstsDockerFile -Version $marketPlaceVersion - -# Commit and push the changes -$commitParams = @{ - Message = "[Ignore] Increment version to $newVersionStr" - Branch = $branchName - RepoLocation = $repoLocation - File = @( - 'package.json' - 'src/main.ts' - 'tools/releaseBuild/Image/DockerFile' - ) -} -CommitAndPushChanges @commitParams - -# Open a new PR in GitHub -$prParams = @{ - Organization = $TargetFork - Repository = 'vscode-PowerShell' - Branch = $branchName - Title = "Update version to v$newVersionStr" - Description = $PRDescription - GitHubToken = $GitHubToken - FromOrg = 'rjmholt' -} -OpenGitHubPr @prParams \ No newline at end of file diff --git a/tools/repoUpdateScripts/updatePsesVersions.ps1 b/tools/repoUpdateScripts/updatePsesVersions.ps1 deleted file mode 100644 index 4dd40eff03..0000000000 --- a/tools/repoUpdateScripts/updatePsesVersions.ps1 +++ /dev/null @@ -1,218 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -[CmdletBinding(DefaultParameterSetName='Increment')] -param( - [Parameter(ParameterSetName='Increment')] - [ValidateSet('Major', 'Minor', 'Patch', 'Preview')] - [string] - $IncrementLevel = 'Preview', - - [Parameter(Mandatory, ParameterSetName='SetVersion')] - [semver] - $NewVersion, - - [Parameter(Mandatory)] - [string] - $GitHubToken, - - [Parameter()] - [string] - $TargetFork = 'PowerShell', - - [Parameter()] - [string] - $BranchName, - - [Parameter()] - [string] - $PRDescription -) - -Import-Module "$PSScriptRoot/../GitHubTools.psm1" -Force -Import-Module "$PSScriptRoot/../FileUpdateTools.psm1" -Force - -function FindPsesModuleSpan -{ - param( - [Parameter()] - [string] - $ModuleManifestContent - ) - - # Inscrutable regex looks for PSD1 "ModuleVersion = '2.0.0'" type of field - $pattern = [regex]'\s*ModuleVersion\s*=\s*(?:''|")(\d+?(?:\.\d+?(?:\.\d+)))(?:''|")' - - $versionGroup = $pattern.Match($ModuleManifestContent).Groups[1] - - return @{ - Start = $versionGroup.Index - End = $versionGroup.Index + $versionGroup.Length - } -} - -function UpdatePsesModuleVersion -{ - param( - [Parameter()] - [string] - $PsesModuleManifestPath, - - [Parameter()] - [semver] - $NewVersion - ) - - $version = GetVersionFromSemVer -SemVer $NewVersion - - $PsesModuleManifestPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PsesModuleManifestPath) - - $manifestContent = Get-Content -Raw $PsesModuleManifestPath - - $span = FindPsesModuleSpan -ModuleManifestContent $manifestContent - - $newContent = ReplaceStringSegment -String $manifestContent -NewSegment $version -StartIndex $span.Start -EndIndex $span.End - - SetFileContent -FilePath $PsesModuleManifestPath -Value $newContent -} - -function GetPsesCurrentVersion -{ - [OutputType([semver])] - param( - [Parameter()] - [string] - $PsesPropsPath - ) - - $propsXml = [xml](Get-Content -Raw $PsesPropsPath) - - $version = $propsXml.Project.PropertyGroup.VersionPrefix - $prereleaseTag = $propsXml.Project.PropertyGroup.VersionSuffix - if ($prereleaseTag) - { - $version = "$version-$prereleaseTag" - } - - return [semver]$version -} - -function UpdatePsesPropsXml -{ - param( - [Parameter(Mandatory)] - [semver] - $NewVersion, - - [Parameter(Mandatory)] - [string] - $PsesPropsPath - ) - - $PsesPropsPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PsesPropsPath) - - $propsXml = [xml](Get-Content -Raw $PsesPropsPath) - - $versionParts = $NewVersion.ToString().Split('-') - - if ($versionParts.Length -eq 2) - { - $propsXml.Project.PropertyGroup.VersionPrefix = $versionParts[0] - $propsXml.Project.PropertyGroup.VersionSuffix = $versionParts[1] - } - else - { - $propsXml.Project.PropertyGroup.VersionPrefix = $versionParts[0] - - # Remove the prerelease tag if it's present - $prereleaseNode = $propsXml.Project.PropertyGroup.GetElementsByTagName('VersionSuffix') - if ($prereleaseNode) - { - $null = $propsXml.Project.PropertyGroup.RemoveChild($prereleaseNode[0]) - } - } - - $xmlWriterSettings = [System.Xml.XmlWriterSettings]@{ - Encoding = [System.Text.UTF8Encoding]::new(<# BOM #>$false) - OmitXmlDeclaration = $true - Indent = $true - IndentChars = " " - NewLineHandling = 'Replace' - NewLineChars = "`r`n" - } - $xmlWriter = [System.Xml.XmlWriter]::Create($PsesPropsPath, $xmlWriterSettings) - try - { - $propsXml.Save($xmlWriter) - $xmlWriter.WriteWhitespace("`r`n") - } - finally - { - $xmlWriter.Dispose() - } -} - -$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'pses-update-temp' -$paths = @{ - props = "$repoLocation/PowerShellEditorServices.Common.props" - manifest = "$repoLocation/module/PowerShellEditorServices/PowerShellEditorServices.psd1" -} - -if (-not $BranchName) -{ - $BranchName = "update-pses-version-$NewVersion" -} - -if (-not $PRDescription) -{ - $PRDescription = "Updates PSES to version $NewVersion.**Note**: This is an automated PR." -} - -# Clone the PSES repo -$cloneParams = @{ - OriginRemote = 'https://github.com/rjmholt/PowerShellEditorServices' - Destination = $repoLocation - CheckoutBranch = $BranchName - Remotes = @{ - upstream = 'https://github.com/PowerShell/PowerShellEditorServices' - } - Clobber = $true -} -CloneRepo @cloneParams - -# If we need to increment the version, do that -if ($IncrementLevel) -{ - $currVersion = GetPsesCurrentVersion -PsesPropsPath $paths.props - $NewVersion = IncrementVersion -Version $currVersion -IncrementLevel $IncrementLevel -} - -# Update the Props XML file -UpdatePsesPropsXml -NewVersion $NewVersion -PsesPropsPath $paths.props - -# Update the PSD1 file -UpdatePsesModuleVersion -PsesModuleManifestPath $paths.manifest -NewVersion $NewVersion - -# Commit changes -$commitParams = @{ - RepoLocation = $repoLocation - Message = "[Ignore] Update PSES version to $NewVersion" - Branch = $BranchName - File = @( - 'PowerShellEditorServices.Common.props' - 'module/PowerShellEditorServices/PowerShellEditorServices.psd1' - ) -} -CommitAndPushChanges @commitParams - -# Open a PR -$prParams = @{ - Branch = $BranchName - Title = "Update PowerShellEditorServices version to $NewVersion" - GitHubToken = $GitHubToken - Organization = $TargetFork - Repository = 'PowerShellEditorServices' - Description = $PRDescription - FromOrg = 'rjmholt' -} -OpenGitHubPr @prParams From 90b725537d5fc12a5b744d298cddb8f2f0c6c9af Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 10:52:09 +1000 Subject: [PATCH 08/18] Give proper names to functions --- .../updateAzureDataStudio.ps1 | 16 ++++++++-------- .../updateExtensionVersions.ps1 | 18 +++++++++--------- .../postReleaseScripts/updatePsesVersions.ps1 | 12 ++++++------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tools/postReleaseScripts/updateAzureDataStudio.ps1 b/tools/postReleaseScripts/updateAzureDataStudio.ps1 index 00cd9eb656..25d06037bf 100644 --- a/tools/postReleaseScripts/updateAzureDataStudio.ps1 +++ b/tools/postReleaseScripts/updateAzureDataStudio.ps1 @@ -218,19 +218,19 @@ function UpdateGalleryFile # Create a new PowerShell extension entry $powershellEntry = NewPowerShellExtensionEntry -ExtensionVersion $ExtensionVersion - $entryStr = ConvertToIndentedJson $powershellEntry -IndentChar "`t" -IndentWidth 1 + $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 = GetStringOffsetFromSpan -String $galleryFileContent -EndLine $span.Start.Line -Column $span.Start.Column - $endOffset = GetStringOffsetFromSpan -String $galleryFileContent -EndLine $span.End.Line -StartLine $span.Start.Line -Column $span.End.Column -InitialOffset $startOffset + $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 = ReplaceStringSegment -String $galleryFileContent -NewSegment $entryStr -StartIndex $startOffset -EndIndex ($endOffset+1) -AutoIndent + $newGalleryFileContent = Format-StringWithSegment -String $galleryFileContent -NewSegment $entryStr -StartIndex $startOffset -EndIndex ($endOffset+1) -AutoIndent # Write out the new entry - SetFileContent $GalleryFilePath $newGalleryFileContent + Set-Content -Path $GalleryFilePath -Value $newGalleryFileContent -Encoding utf8NoBOM } $repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'ads-temp-checkout' @@ -245,11 +245,11 @@ $cloneParams = @{ upstream = 'https://github.com/Microsoft/AzureDataStudio' } } -CloneRepo @cloneParams +Copy-GitRepository @cloneParams UpdateGalleryFile -ExtensionVersion $ExtensionVersion -GalleryFilePath "$repoLocation/$GalleryFileName" -CommitAndPushChanges -RepoLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update PS extension to v$ExtensionVersion" +Submit-GitChanges -RepoLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update PS extension to v$ExtensionVersion" $prParams = @{ Organization = $TargetFork @@ -261,4 +261,4 @@ $prParams = @{ GitHubToken = $GitHubToken FromOrg = 'rjmholt' } -OpenGitHubPr @prParams \ No newline at end of file +New-GitHubPR @prParams \ No newline at end of file diff --git a/tools/postReleaseScripts/updateExtensionVersions.ps1 b/tools/postReleaseScripts/updateExtensionVersions.ps1 index 9f8d909595..902ab89726 100644 --- a/tools/postReleaseScripts/updateExtensionVersions.ps1 +++ b/tools/postReleaseScripts/updateExtensionVersions.ps1 @@ -160,10 +160,10 @@ function UpdateMainTsPsesVersion $mainTsContent = Get-Content -Raw $MainTsPath $mainTsVersionSpan = FindRequiredPsesVersionSpan $mainTsContent - $newMainTsContent = ReplaceStringSegment -String $mainTsContent -NewSegment $Version -StartIndex $mainTsVersionSpan.Start -EndIndex $mainTsVersionSpan.End + $newMainTsContent = Format-StringWithSegment -String $mainTsContent -NewSegment $Version -StartIndex $mainTsVersionSpan.Start -EndIndex $mainTsVersionSpan.End if ($newMainTsContent -ne $mainTsContent) { - SetFileContent -FilePath $MainTsPath -Value $newMainTsContent + Set-Content -Path $MainTsPath -Value $newMainTsContent -Encoding utf8NoBOM } } @@ -181,8 +181,8 @@ function UpdateDockerFileVersion $vstsDockerFileContent = Get-Content -Raw $DockerFilePath $vstsDockerFileVersionSpan = FindVstsBuildVersionSpan -DockerFileContent $vstsDockerFileContent - $newDockerFileContent = ReplaceStringSegment -String $vstsDockerFileContent -NewSegment $Version -StartIndex $vstsDockerFileVersionSpan.Start -EndIndex $vstsDockerFileVersionSpan.End - SetFileContent -FilePath $DockerFilePath -Value $newDockerFileContent + $newDockerFileContent = Format-StringWithSegment -String $vstsDockerFileContent -NewSegment $Version -StartIndex $vstsDockerFileVersionSpan.Start -EndIndex $vstsDockerFileVersionSpan.End + Set-Content -Path $DockerFilePath -Value $newDockerFileContent -Encoding utf8NoBOM } function GetMarketplaceVersionFromSemVer @@ -219,7 +219,7 @@ $cloneParams = @{ upstream = 'https://github.com/PowerShell/vscode-powershell' } } -CloneRepo @cloneParams +Copy-GitRepository @cloneParams # We may need the version from the package.json, so get that first $packageJson = Get-Content -Raw $paths.packageJson @@ -229,7 +229,7 @@ $pkgJsonVersionOffsetSpan = FindPackageJsonVersionSpan -PackageJsonContent $pack if ($IncrementLevel) { $version = [semver]$packageJson.Substring($pkgJsonVersionOffsetSpan.Start, $pkgJsonVersionOffsetSpan.End - $pkgJsonVersionOffsetSpan.Start) - $NewVersion = IncrementVersion -Version $version -IncrementLevel $IncrementLevel + $NewVersion = Get-IncrementedVersion -Version $version -IncrementLevel $IncrementLevel } # Get the marketplace/non-semver versions for various files @@ -239,7 +239,7 @@ $marketPlaceVersion = GetMarketplaceVersionFromSemVer -SemVer $NewVersion # Finally create the new package.json file $newPkgJsonContent = ReplaceStringSegment -String $packageJson -NewSegment $newVersionStr -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End -SetFileContent -FilePath $paths.packageJson -Value $newPkgJsonContent +Set-Content -Path $paths.packageJson -Value $newPkgJsonContent -Encoding utf8NoBOM # Create the new content for the main.ts required version file UpdateMainTsPsesVersion -MainTsPath $paths.mainTs -Version $psesVersion @@ -258,7 +258,7 @@ $commitParams = @{ 'tools/releaseBuild/Image/DockerFile' ) } -CommitAndPushChanges @commitParams +Submit-GitChanges @commitParams # Open a new PR in GitHub $prParams = @{ @@ -270,4 +270,4 @@ $prParams = @{ GitHubToken = $GitHubToken FromOrg = 'rjmholt' } -OpenGitHubPr @prParams \ No newline at end of file +New-GitHubPR @prParams \ No newline at end of file diff --git a/tools/postReleaseScripts/updatePsesVersions.ps1 b/tools/postReleaseScripts/updatePsesVersions.ps1 index 093fae9812..3a13ee7fb2 100644 --- a/tools/postReleaseScripts/updatePsesVersions.ps1 +++ b/tools/postReleaseScripts/updatePsesVersions.ps1 @@ -63,7 +63,7 @@ function UpdatePsesModuleVersion $NewVersion ) - $version = GetVersionFromSemVer -SemVer $NewVersion + $version = Get-VersionFromSemVer -SemVer $NewVersion $PsesModuleManifestPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PsesModuleManifestPath) @@ -71,9 +71,9 @@ function UpdatePsesModuleVersion $span = FindPsesModuleSpan -ModuleManifestContent $manifestContent - $newContent = ReplaceStringSegment -String $manifestContent -NewSegment $version -StartIndex $span.Start -EndIndex $span.End + $newContent = Format-StringWithSegment -String $manifestContent -NewSegment $version -StartIndex $span.Start -EndIndex $span.End - SetFileContent -FilePath $PsesModuleManifestPath -Value $newContent + Set-Content -Path $PsesModuleManifestPath -Value $newContent -Encoding utf8NoBOM } function GetPsesCurrentVersion @@ -168,7 +168,7 @@ $cloneParams = @{ } Clobber = $true } -CloneRepo @cloneParams +Copy-GitRepository @cloneParams # If we need to increment the version, do that if ($IncrementLevel) @@ -193,7 +193,7 @@ $commitParams = @{ 'module/PowerShellEditorServices/PowerShellEditorServices.psd1' ) } -CommitAndPushChanges @commitParams +Submit-GitChanges @commitParams # Open a PR $prParams = @{ @@ -205,4 +205,4 @@ $prParams = @{ Description = $PRDescription FromOrg = 'rjmholt' } -OpenGitHubPr @prParams +New-GitHubPR @prParams From aed5afecbaf624e99fb40f3e82f777256c0b12e1 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 11:45:36 +1000 Subject: [PATCH 09/18] Rename functions, fix parameter problems --- .../updateAzureDataStudio.ps1 | 4 +-- .../updateExtensionVersions.ps1 | 35 ++++++++++++------- .../postReleaseScripts/updatePsesVersions.ps1 | 20 ++++++++--- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/tools/postReleaseScripts/updateAzureDataStudio.ps1 b/tools/postReleaseScripts/updateAzureDataStudio.ps1 index 25d06037bf..021f28eada 100644 --- a/tools/postReleaseScripts/updateAzureDataStudio.ps1 +++ b/tools/postReleaseScripts/updateAzureDataStudio.ps1 @@ -230,7 +230,7 @@ function UpdateGalleryFile $newGalleryFileContent = Format-StringWithSegment -String $galleryFileContent -NewSegment $entryStr -StartIndex $startOffset -EndIndex ($endOffset+1) -AutoIndent # Write out the new entry - Set-Content -Path $GalleryFilePath -Value $newGalleryFileContent -Encoding utf8NoBOM + Set-Content -Path $GalleryFilePath -Value $newGalleryFileContent -Encoding utf8NoBOM -NoNewline } $repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'ads-temp-checkout' @@ -249,7 +249,7 @@ Copy-GitRepository @cloneParams UpdateGalleryFile -ExtensionVersion $ExtensionVersion -GalleryFilePath "$repoLocation/$GalleryFileName" -Submit-GitChanges -RepoLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update PS extension to v$ExtensionVersion" +Submit-GitChanges -RepositoryLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update PS extension to v$ExtensionVersion" $prParams = @{ Organization = $TargetFork diff --git a/tools/postReleaseScripts/updateExtensionVersions.ps1 b/tools/postReleaseScripts/updateExtensionVersions.ps1 index 902ab89726..3bcce77a92 100644 --- a/tools/postReleaseScripts/updateExtensionVersions.ps1 +++ b/tools/postReleaseScripts/updateExtensionVersions.ps1 @@ -22,11 +22,13 @@ param( [Parameter()] [string] - $BranchName = "update-version-$newVersionStr", + # Default set below, requires processing when $IncrementVersion is used + $BranchName, [Parameter()] [string] - $PRDescription = "Updates version strings in vscode-PowerShell to $newVersionStr.`n**Note**: This is an automated PR." + # Default set below, requires processing when $IncrementVersion is used + $PRDescription ) Import-Module -Force "$PSScriptRoot/../FileUpdateTools.psm1" @@ -79,7 +81,7 @@ function FindPackageJsonVersionSpan continue } - $currIndex = GetStringOffsetFromSpan -String $PackageJsonContent -EndLine $jsonReader.LineNumber -Column $jsonReader.LinePosition + $currIndex = Get-StringOffsetFromSpan -String $PackageJsonContent -EndLine $jsonReader.LineNumber -Column $jsonReader.LinePosition $versionStartOffset = $PackageJsonContent.IndexOf('"', $currIndex) + 1 $versionStartColumn = $jsonReader.LinePosition + $versionStartOffset - $currIndex @@ -163,7 +165,7 @@ function UpdateMainTsPsesVersion $newMainTsContent = Format-StringWithSegment -String $mainTsContent -NewSegment $Version -StartIndex $mainTsVersionSpan.Start -EndIndex $mainTsVersionSpan.End if ($newMainTsContent -ne $mainTsContent) { - Set-Content -Path $MainTsPath -Value $newMainTsContent -Encoding utf8NoBOM + Set-Content -Path $MainTsPath -Value $newMainTsContent -Encoding utf8NoBOM -NoNewline } } @@ -182,7 +184,7 @@ function UpdateDockerFileVersion $vstsDockerFileContent = Get-Content -Raw $DockerFilePath $vstsDockerFileVersionSpan = FindVstsBuildVersionSpan -DockerFileContent $vstsDockerFileContent $newDockerFileContent = Format-StringWithSegment -String $vstsDockerFileContent -NewSegment $Version -StartIndex $vstsDockerFileVersionSpan.Start -EndIndex $vstsDockerFileVersionSpan.End - Set-Content -Path $DockerFilePath -Value $newDockerFileContent -Encoding utf8NoBOM + Set-Content -Path $DockerFilePath -Value $newDockerFileContent -Encoding utf8NoBOM -NoNewline } function GetMarketplaceVersionFromSemVer @@ -232,14 +234,23 @@ if ($IncrementLevel) $NewVersion = Get-IncrementedVersion -Version $version -IncrementLevel $IncrementLevel } +if (-not $BranchName) +{ + $BranchName = "update-version-$NewVersion" +} + +if (-not $PRDescription) +{ + $PRDescription = "Updates version strings in vscode-PowerShell to $NewVersion.`n**Note**: This is an automated PR." +} + # Get the marketplace/non-semver versions for various files -$newVersionStr = $NewVersion.ToString() -$psesVersion = GetVersionFromSemVer -SemVer $NewVersion +$psesVersion = Get-VersionFromSemVer -SemVer $NewVersion $marketPlaceVersion = GetMarketplaceVersionFromSemVer -SemVer $NewVersion # Finally create the new package.json file -$newPkgJsonContent = ReplaceStringSegment -String $packageJson -NewSegment $newVersionStr -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End -Set-Content -Path $paths.packageJson -Value $newPkgJsonContent -Encoding utf8NoBOM +$newPkgJsonContent = Format-StringWithSegment -String $packageJson -NewSegment $NewVersion -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End +Set-Content -Path $paths.packageJson -Value $newPkgJsonContent -Encoding utf8NoBOM -NoNewline # Create the new content for the main.ts required version file UpdateMainTsPsesVersion -MainTsPath $paths.mainTs -Version $psesVersion @@ -249,9 +260,9 @@ UpdateDockerFileVersion -DockerFilePath $paths.vstsDockerFile -Version $marketPl # Commit and push the changes $commitParams = @{ - Message = "[Ignore] Increment version to $newVersionStr" + Message = "[Ignore] Increment version to $NewVersion" Branch = $branchName - RepoLocation = $repoLocation + RepositoryLocation = $repoLocation File = @( 'package.json' 'src/main.ts' @@ -265,7 +276,7 @@ $prParams = @{ Organization = $TargetFork Repository = 'vscode-PowerShell' Branch = $branchName - Title = "Update version to v$newVersionStr" + Title = "Update version to v$NewVersion" Description = $PRDescription GitHubToken = $GitHubToken FromOrg = 'rjmholt' diff --git a/tools/postReleaseScripts/updatePsesVersions.ps1 b/tools/postReleaseScripts/updatePsesVersions.ps1 index 3a13ee7fb2..c41a5455d3 100644 --- a/tools/postReleaseScripts/updatePsesVersions.ps1 +++ b/tools/postReleaseScripts/updatePsesVersions.ps1 @@ -22,11 +22,11 @@ param( [Parameter()] [string] - $BranchName = "update-pses-version-$NewVersion", + $BranchName, [Parameter()] [string] - $PRDescription = "Updates PSES to version $NewVersion.**Note**: This is an automated PR." + $PRDescription ) Import-Module "$PSScriptRoot/../GitHubTools.psm1" -Force @@ -73,7 +73,7 @@ function UpdatePsesModuleVersion $newContent = Format-StringWithSegment -String $manifestContent -NewSegment $version -StartIndex $span.Start -EndIndex $span.End - Set-Content -Path $PsesModuleManifestPath -Value $newContent -Encoding utf8NoBOM + Set-Content -Path $PsesModuleManifestPath -Value $newContent -Encoding utf8NoBOM -NoNewline } function GetPsesCurrentVersion @@ -174,7 +174,17 @@ Copy-GitRepository @cloneParams if ($IncrementLevel) { $currVersion = GetPsesCurrentVersion -PsesPropsPath $paths.props - $NewVersion = IncrementVersion -Version $currVersion -IncrementLevel $IncrementLevel + $NewVersion = Get-IncrementedVersion -Version $currVersion -IncrementLevel $IncrementLevel +} + +if (-not $BranchName) +{ + $BranchName = "update-pses-version-$NewVersion" +} + +if (-not $PRDescription) +{ + $PRDescription = "Updates PSES to version $NewVersion.**Note**: This is an automated PR." } # Update the Props XML file @@ -185,7 +195,7 @@ UpdatePsesModuleVersion -PsesModuleManifestPath $paths.manifest -NewVersion $New # Commit changes $commitParams = @{ - RepoLocation = $repoLocation + RepositoryLocation = $repoLocation Message = "[Ignore] Update PSES version to $NewVersion" Branch = $BranchName File = @( From bdd250de393fa07755afed299a5df4e0c374c54a Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 12:16:08 +1000 Subject: [PATCH 10/18] Change segment function verb --- tools/postReleaseScripts/updateAzureDataStudio.ps1 | 2 +- tools/postReleaseScripts/updateExtensionVersions.ps1 | 6 +++--- tools/postReleaseScripts/updatePsesVersions.ps1 | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/postReleaseScripts/updateAzureDataStudio.ps1 b/tools/postReleaseScripts/updateAzureDataStudio.ps1 index 021f28eada..eac785c785 100644 --- a/tools/postReleaseScripts/updateAzureDataStudio.ps1 +++ b/tools/postReleaseScripts/updateAzureDataStudio.ps1 @@ -227,7 +227,7 @@ function UpdateGalleryFile $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 = Format-StringWithSegment -String $galleryFileContent -NewSegment $entryStr -StartIndex $startOffset -EndIndex ($endOffset+1) -AutoIndent + $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 diff --git a/tools/postReleaseScripts/updateExtensionVersions.ps1 b/tools/postReleaseScripts/updateExtensionVersions.ps1 index 3bcce77a92..af87fa7b21 100644 --- a/tools/postReleaseScripts/updateExtensionVersions.ps1 +++ b/tools/postReleaseScripts/updateExtensionVersions.ps1 @@ -162,7 +162,7 @@ function UpdateMainTsPsesVersion $mainTsContent = Get-Content -Raw $MainTsPath $mainTsVersionSpan = FindRequiredPsesVersionSpan $mainTsContent - $newMainTsContent = Format-StringWithSegment -String $mainTsContent -NewSegment $Version -StartIndex $mainTsVersionSpan.Start -EndIndex $mainTsVersionSpan.End + $newMainTsContent = New-StringWithSegment -String $mainTsContent -NewSegment $Version -StartIndex $mainTsVersionSpan.Start -EndIndex $mainTsVersionSpan.End if ($newMainTsContent -ne $mainTsContent) { Set-Content -Path $MainTsPath -Value $newMainTsContent -Encoding utf8NoBOM -NoNewline @@ -183,7 +183,7 @@ function UpdateDockerFileVersion $vstsDockerFileContent = Get-Content -Raw $DockerFilePath $vstsDockerFileVersionSpan = FindVstsBuildVersionSpan -DockerFileContent $vstsDockerFileContent - $newDockerFileContent = Format-StringWithSegment -String $vstsDockerFileContent -NewSegment $Version -StartIndex $vstsDockerFileVersionSpan.Start -EndIndex $vstsDockerFileVersionSpan.End + $newDockerFileContent = New-StringWithSegment -String $vstsDockerFileContent -NewSegment $Version -StartIndex $vstsDockerFileVersionSpan.Start -EndIndex $vstsDockerFileVersionSpan.End Set-Content -Path $DockerFilePath -Value $newDockerFileContent -Encoding utf8NoBOM -NoNewline } @@ -249,7 +249,7 @@ $psesVersion = Get-VersionFromSemVer -SemVer $NewVersion $marketPlaceVersion = GetMarketplaceVersionFromSemVer -SemVer $NewVersion # Finally create the new package.json file -$newPkgJsonContent = Format-StringWithSegment -String $packageJson -NewSegment $NewVersion -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End +$newPkgJsonContent = New-StringWithSegment -String $packageJson -NewSegment $NewVersion -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End Set-Content -Path $paths.packageJson -Value $newPkgJsonContent -Encoding utf8NoBOM -NoNewline # Create the new content for the main.ts required version file diff --git a/tools/postReleaseScripts/updatePsesVersions.ps1 b/tools/postReleaseScripts/updatePsesVersions.ps1 index c41a5455d3..829084f16f 100644 --- a/tools/postReleaseScripts/updatePsesVersions.ps1 +++ b/tools/postReleaseScripts/updatePsesVersions.ps1 @@ -71,7 +71,7 @@ function UpdatePsesModuleVersion $span = FindPsesModuleSpan -ModuleManifestContent $manifestContent - $newContent = Format-StringWithSegment -String $manifestContent -NewSegment $version -StartIndex $span.Start -EndIndex $span.End + $newContent = New-StringWithSegment -String $manifestContent -NewSegment $version -StartIndex $span.Start -EndIndex $span.End Set-Content -Path $PsesModuleManifestPath -Value $newContent -Encoding utf8NoBOM -NoNewline } From 45fe271e2b6ba5097b6b5eb4897982dfaa33fc19 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 30 Apr 2019 17:40:47 +1000 Subject: [PATCH 11/18] Add GitHub release script --- tools/GitHubTools.psm1 | 105 +++++++++++++++++- .../publishVsixGHRelease.ps1 | 68 ++++++++++++ 2 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 tools/postReleaseScripts/publishVsixGHRelease.ps1 diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index bc5ad6b3fb..b562ada32e 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -229,4 +229,107 @@ function New-GitHubPR Invoke-RestMethod -Method Post -Uri $uri -Body $body -Headers $headers } -Export-ModuleMember -Function Copy-GitRepository,Submit-GitChanges,New-GitHubPR +function Publish-GitHubRelease +{ + param( + [Parameter(Mandatory)] + [string] + $Organization, + + [Parameter(Mandatory)] + [string] + $Repository, + + [Parameter(Mandatory)] + [string] + $Tag, + + [Parameter(Mandatory)] + [string] + $ReleaseName, + + [Parameter(Mandatory)] + [string] + $Description, + + [Parameter(Mandatory)] + [string] + $GitHubToken, + + [Parameter()] + [Alias('Branch', 'Commit')] + [string] + $Commitish, + + [Parameter()] + [string[]] + $AssetPath, + + [switch] + $Draft, + + [switch] + $Prerelease + ) + + $restParams = @{ + tag_name = $Tag + name = $ReleaseName + body = $Description + draft = [bool]$Draft + prerelease = [bool]$Prerelease + } + + if ($Commitish) + { + $restParams.target_commitish = $Commitish + } + + $restBody = ConvertTo-Json -InputObject $restParams + $uri = "https://api.github.com/repos/$Organization/$Repository/releases" + $headers = @{ + Accept = 'application/vnd.github.v3+json' + Authorization = "token $GitHubToken" + } + + $response = Invoke-RestMethod -Method Post -Uri $uri -Body $restBody -Headers $headers + + $releaseId = $response.id + $assetBaseUri = "https://uploads.github.com/repos/$Organization/$Repository/releases/$releaseId/assets" + foreach ($asset in $AssetPath) + { + $extension = [System.IO.Path]::GetExtension($asset) + $fileName = [uri]::EscapeDataString([System.IO.Path]::GetFileName($asset)) + $contentType = 'text/plain' + switch ($extension) + { + { $_ -in '.zip','.vsix' } + { + $contentType = 'application/zip' + break + } + + '.json' + { + $contentType = 'application/json' + break + } + + default + { + $contentType = 'text/plain' + } + } + + $assetUri = "${assetBaseUri}?name=$fileName" + $headers = @{ + Authorization = "token $GitHubToken" + } + # This can be very slow, but it does work + $null = Invoke-RestMethod -Method Post -Uri $assetUri -InFile $asset -ContentType $contentType -Headers $headers + } + + return $response +} + +Export-ModuleMember -Function Copy-GitRepository,Submit-GitChanges,New-GitHubPR \ No newline at end of file diff --git a/tools/postReleaseScripts/publishVsixGHRelease.ps1 b/tools/postReleaseScripts/publishVsixGHRelease.ps1 new file mode 100644 index 0000000000..e3af41badf --- /dev/null +++ b/tools/postReleaseScripts/publishVsixGHRelease.ps1 @@ -0,0 +1,68 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +param( + [Parameter(Mandatory)] + [semver] + $Version, + + [Parameter(Mandatory)] + [string] + $GitHubToken, + + [Parameter()] + [string] + $TargetFork = 'PowerShell', + + [Parameter()] + [string] + $ChangelogPath = "$PSScriptRoot/../../CHANGELOG.md", + + [Parameter()] + [string[]] + $AssetPath +) + +Import-Module "$PSScriptRoot/../GitHubTools.psm1" + +function GetDescriptionFromChangelog +{ + param( + [Parameter(Mandatory)] + [string] + $ChangelogPath + ) + + $lines = Get-Content -Path $ChangelogPath + $sb = [System.Text.StringBuilder]::new($lines[2]) + for ($i = 3; -not $lines[$i].StartsWith('## '); $i++) + { + $null = $sb.Append("`n").Append($lines[$i]) + } + + return $sb.ToString() +} + +$tag = "v$Version" + +if (-not $PSBoundParameters.ContainsKey('AssetPath')) +{ + $AssetPath = @( + "$PSScriptRoot/../../PowerShell-$Version.vsix" + "$PSScriptRoot/../../scripts/Install-VSCode.ps1" + ) +} + +$releaseParams = @{ + Organization = $TargetFork + Repository = 'vscode-PowerShell' + Tag = $tag + ReleaseName = $tag + Branch = "release/$Version" + AssetPath = $AssetPath + Prerelease = [bool]($Version.PreReleaseLabel) + Description = GetDescriptionFromChangelog -ChangelogPath $ChangelogPath + GitHubToken = $GitHubToken +} +CreateNewRelease @releaseParams + From 2616e7c0e3277434b9c970180e9600350536b3d4 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 30 Apr 2019 18:03:46 +1000 Subject: [PATCH 12/18] Generalize release script to work with PSES --- ...ishVsixGHRelease.ps1 => publishGHRelease.ps1} | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) rename tools/postReleaseScripts/{publishVsixGHRelease.ps1 => publishGHRelease.ps1} (80%) diff --git a/tools/postReleaseScripts/publishVsixGHRelease.ps1 b/tools/postReleaseScripts/publishGHRelease.ps1 similarity index 80% rename from tools/postReleaseScripts/publishVsixGHRelease.ps1 rename to tools/postReleaseScripts/publishGHRelease.ps1 index e3af41badf..07b5cd8aef 100644 --- a/tools/postReleaseScripts/publishVsixGHRelease.ps1 +++ b/tools/postReleaseScripts/publishGHRelease.ps1 @@ -10,6 +10,10 @@ param( [string] $GitHubToken, + [Parameter(Mandatory)] + [string] + $Repository, + [Parameter()] [string] $TargetFork = 'PowerShell', @@ -23,7 +27,7 @@ param( $AssetPath ) -Import-Module "$PSScriptRoot/../GitHubTools.psm1" +Import-Module "$PSScriptRoot/../GitHubTools.psm1" -Force function GetDescriptionFromChangelog { @@ -45,17 +49,9 @@ function GetDescriptionFromChangelog $tag = "v$Version" -if (-not $PSBoundParameters.ContainsKey('AssetPath')) -{ - $AssetPath = @( - "$PSScriptRoot/../../PowerShell-$Version.vsix" - "$PSScriptRoot/../../scripts/Install-VSCode.ps1" - ) -} - $releaseParams = @{ Organization = $TargetFork - Repository = 'vscode-PowerShell' + Repository = $Repository Tag = $tag ReleaseName = $tag Branch = "release/$Version" From 3213a6f7b35074372b0ac6ed1cb1d85108e32068 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 14:57:26 +1000 Subject: [PATCH 13/18] Update GH module --- tools/GitHubTools.psm1 | 2 +- tools/postReleaseScripts/publishGHRelease.ps1 | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index b562ada32e..4017223045 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -332,4 +332,4 @@ function Publish-GitHubRelease return $response } -Export-ModuleMember -Function Copy-GitRepository,Submit-GitChanges,New-GitHubPR \ No newline at end of file +Export-ModuleMember -Function Copy-GitRepository,Submit-GitChanges,New-GitHubPR,Publish-GitHubRelease \ No newline at end of file diff --git a/tools/postReleaseScripts/publishGHRelease.ps1 b/tools/postReleaseScripts/publishGHRelease.ps1 index 07b5cd8aef..fee3906c19 100644 --- a/tools/postReleaseScripts/publishGHRelease.ps1 +++ b/tools/postReleaseScripts/publishGHRelease.ps1 @@ -60,5 +60,4 @@ $releaseParams = @{ Description = GetDescriptionFromChangelog -ChangelogPath $ChangelogPath GitHubToken = $GitHubToken } -CreateNewRelease @releaseParams - +Publish-GitHubRelease @releaseParams From 93d3a7ac818173435b43d2daa1a11897c794344b Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 13 May 2019 11:28:32 -0700 Subject: [PATCH 14/18] Add requires back in --- tools/postReleaseScripts/publishGHRelease.ps1 | 2 ++ tools/postReleaseScripts/updateAzureDataStudio.ps1 | 2 ++ tools/postReleaseScripts/updateExtensionVersions.ps1 | 2 ++ tools/postReleaseScripts/updatePsesVersions.ps1 | 2 ++ 4 files changed, 8 insertions(+) diff --git a/tools/postReleaseScripts/publishGHRelease.ps1 b/tools/postReleaseScripts/publishGHRelease.ps1 index fee3906c19..55ecf24625 100644 --- a/tools/postReleaseScripts/publishGHRelease.ps1 +++ b/tools/postReleaseScripts/publishGHRelease.ps1 @@ -1,6 +1,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +#requires -Version 6.0 + param( [Parameter(Mandatory)] [semver] diff --git a/tools/postReleaseScripts/updateAzureDataStudio.ps1 b/tools/postReleaseScripts/updateAzureDataStudio.ps1 index eac785c785..0641eba504 100644 --- a/tools/postReleaseScripts/updateAzureDataStudio.ps1 +++ b/tools/postReleaseScripts/updateAzureDataStudio.ps1 @@ -1,6 +1,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +#requires -Version 6.0 + param( [Parameter(Mandatory)] [string] diff --git a/tools/postReleaseScripts/updateExtensionVersions.ps1 b/tools/postReleaseScripts/updateExtensionVersions.ps1 index af87fa7b21..f05ab843c4 100644 --- a/tools/postReleaseScripts/updateExtensionVersions.ps1 +++ b/tools/postReleaseScripts/updateExtensionVersions.ps1 @@ -1,6 +1,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +#requires -Version 6.0 + [CmdletBinding(DefaultParameterSetName='Increment')] param( [Parameter(ParameterSetName='Increment')] diff --git a/tools/postReleaseScripts/updatePsesVersions.ps1 b/tools/postReleaseScripts/updatePsesVersions.ps1 index 829084f16f..c4222d1d71 100644 --- a/tools/postReleaseScripts/updatePsesVersions.ps1 +++ b/tools/postReleaseScripts/updatePsesVersions.ps1 @@ -1,6 +1,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +#requires -Version 6.0 + [CmdletBinding(DefaultParameterSetName='Increment')] param( [Parameter(ParameterSetName='Increment')] From 81110dfedf754ba2bdcb242e13349fbe913e55ec Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 13 May 2019 11:29:16 -0700 Subject: [PATCH 15/18] Add newlines back in --- tools/postReleaseScripts/updateAzureDataStudio.ps1 | 2 +- tools/postReleaseScripts/updateExtensionVersions.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/postReleaseScripts/updateAzureDataStudio.ps1 b/tools/postReleaseScripts/updateAzureDataStudio.ps1 index 0641eba504..55ff86794c 100644 --- a/tools/postReleaseScripts/updateAzureDataStudio.ps1 +++ b/tools/postReleaseScripts/updateAzureDataStudio.ps1 @@ -263,4 +263,4 @@ $prParams = @{ GitHubToken = $GitHubToken FromOrg = 'rjmholt' } -New-GitHubPR @prParams \ No newline at end of file +New-GitHubPR @prParams diff --git a/tools/postReleaseScripts/updateExtensionVersions.ps1 b/tools/postReleaseScripts/updateExtensionVersions.ps1 index f05ab843c4..974a6e43f7 100644 --- a/tools/postReleaseScripts/updateExtensionVersions.ps1 +++ b/tools/postReleaseScripts/updateExtensionVersions.ps1 @@ -283,4 +283,4 @@ $prParams = @{ GitHubToken = $GitHubToken FromOrg = 'rjmholt' } -New-GitHubPR @prParams \ No newline at end of file +New-GitHubPR @prParams From 2347792d2855070a6b932c38fb1d63ac750b830f Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 13 May 2019 11:29:59 -0700 Subject: [PATCH 16/18] Add newline back in --- tools/GitHubTools.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index 4017223045..d3b14bde35 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -332,4 +332,4 @@ function Publish-GitHubRelease return $response } -Export-ModuleMember -Function Copy-GitRepository,Submit-GitChanges,New-GitHubPR,Publish-GitHubRelease \ No newline at end of file +Export-ModuleMember -Function Copy-GitRepository,Submit-GitChanges,New-GitHubPR,Publish-GitHubRelease From 02c015b30008206a5b7a6242a588d2b9e89e2447 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 13 May 2019 11:33:16 -0700 Subject: [PATCH 17/18] Remove redundant default --- tools/GitHubTools.psm1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index d3b14bde35..bb4bb43309 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -314,11 +314,6 @@ function Publish-GitHubRelease $contentType = 'application/json' break } - - default - { - $contentType = 'text/plain' - } } $assetUri = "${assetBaseUri}?name=$fileName" From fa290354c8113401b3267e577e843a8a09180b96 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 13 May 2019 13:59:55 -0700 Subject: [PATCH 18/18] Add comments for function --- tools/postReleaseScripts/publishGHRelease.ps1 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/postReleaseScripts/publishGHRelease.ps1 b/tools/postReleaseScripts/publishGHRelease.ps1 index 55ecf24625..435c2f715c 100644 --- a/tools/postReleaseScripts/publishGHRelease.ps1 +++ b/tools/postReleaseScripts/publishGHRelease.ps1 @@ -31,6 +31,17 @@ param( Import-Module "$PSScriptRoot/../GitHubTools.psm1" -Force +<# +.SYNOPSIS +Get the release description from the CHANGELOG + +.DESCRIPTION +Gets the latest CHANGELOG entry from the CHANGELOG for use as the GitHub release description + +.PARAMETER ChangelogPath +Path to the changelog file +#> + function GetDescriptionFromChangelog { param( @@ -40,7 +51,10 @@ function GetDescriptionFromChangelog ) $lines = Get-Content -Path $ChangelogPath + # First two lines are the title and newline + # Third looks like '## vX.Y.Z-releasetag' $sb = [System.Text.StringBuilder]::new($lines[2]) + # Read through until the next '## vX.Y.Z-releasetag' H2 for ($i = 3; -not $lines[$i].StartsWith('## '); $i++) { $null = $sb.Append("`n").Append($lines[$i])