From bec93f79a4f158368675110161997752c8d0d418 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 29 Apr 2019 13:24:37 +1000 Subject: [PATCH 01/52] 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 83b39a892bd62d959e7a234f8969d778fedde59f Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 29 Apr 2019 13:36:24 +1000 Subject: [PATCH 02/52] 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 88794a60af4a7a067e3a48385f62dea046be2efd Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 29 Apr 2019 17:02:25 +1000 Subject: [PATCH 03/52] 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 947fa3aeac2ad186e6e5df6c21af1fb0af8f08f1 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 30 Apr 2019 09:57:47 +1000 Subject: [PATCH 04/52] 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 ac7c8e6fbfe287d48552699cd99ac0c9df46aeab Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 30 Apr 2019 10:10:49 +1000 Subject: [PATCH 05/52] 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 797cb1ac75f144430b8193b415c7428557d3cb06 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Wed, 1 May 2019 08:45:58 +1000 Subject: [PATCH 06/52] 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 d690cfe7d9bb26bb7bdb00f3e39d6756e6afe749 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 09:10:50 +1000 Subject: [PATCH 07/52] Simplify default parameters, move dir --- .../updateAzureDataStudio.ps1 | 8 +- .../updateExtensionVersions.ps1 | 49 ++- .../postReleaseScripts/updatePsesVersions.ps1 | 32 +- .../updateAzureDataStudio.ps1 | 274 ----------------- .../updateExtensionVersions.ps1 | 283 ------------------ .../repoUpdateScripts/updatePsesVersions.ps1 | 218 -------------- 6 files changed, 31 insertions(+), 833 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 b82fee6eed..d2c5ae3877 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] @@ -255,13 +253,13 @@ $cloneParams = @{ upstream = 'https://github.com/Microsoft/AzureDataStudio' } } -Copy-GitRepository @cloneParams +CloneRepo @cloneParams $GalleryFileName | ForEach-Object { "$repoLocation/$_" } | UpdateGalleryFile -ExtensionVersion $ExtensionVersion -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 @@ -273,4 +271,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 37f9978e8ee4cd81256e81103be5311bd795a777 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 10:52:09 +1000 Subject: [PATCH 08/52] Give proper names to functions --- .../updateAzureDataStudio.ps1 | 6 +++--- .../updateExtensionVersions.ps1 | 18 +++++++++--------- .../postReleaseScripts/updatePsesVersions.ps1 | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tools/postReleaseScripts/updateAzureDataStudio.ps1 b/tools/postReleaseScripts/updateAzureDataStudio.ps1 index d2c5ae3877..3f0affcb95 100644 --- a/tools/postReleaseScripts/updateAzureDataStudio.ps1 +++ b/tools/postReleaseScripts/updateAzureDataStudio.ps1 @@ -253,13 +253,13 @@ $cloneParams = @{ upstream = 'https://github.com/Microsoft/AzureDataStudio' } } -CloneRepo @cloneParams +Copy-GitRepository @cloneParams $GalleryFileName | ForEach-Object { "$repoLocation/$_" } | UpdateGalleryFile -ExtensionVersion $ExtensionVersion -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 @@ -271,4 +271,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 43a902429763d159bcd39692a7ba178428edbe22 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 11:45:36 +1000 Subject: [PATCH 09/52] Rename functions, fix parameter problems --- .../updateAzureDataStudio.ps1 | 2 +- .../updateExtensionVersions.ps1 | 35 ++++++++++++------- .../postReleaseScripts/updatePsesVersions.ps1 | 20 ++++++++--- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/tools/postReleaseScripts/updateAzureDataStudio.ps1 b/tools/postReleaseScripts/updateAzureDataStudio.ps1 index 3f0affcb95..c54e05122e 100644 --- a/tools/postReleaseScripts/updateAzureDataStudio.ps1 +++ b/tools/postReleaseScripts/updateAzureDataStudio.ps1 @@ -259,7 +259,7 @@ $GalleryFileName | ForEach-Object { "$repoLocation/$_" } | UpdateGalleryFile -ExtensionVersion $ExtensionVersion -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 c8da98931339430e6af79d8741353300e2fda7fe Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 12:16:08 +1000 Subject: [PATCH 10/52] Change segment function verb --- tools/postReleaseScripts/updateExtensionVersions.ps1 | 6 +++--- tools/postReleaseScripts/updatePsesVersions.ps1 | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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 8a71fa893789827e775cd8cdbaeb55c5b7624807 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 30 Apr 2019 17:40:47 +1000 Subject: [PATCH 11/52] Add GitHub release script --- .../publishVsixGHRelease.ps1 | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tools/postReleaseScripts/publishVsixGHRelease.ps1 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 96dd4fe86d5376c4f96063b8b73decee7da3cd06 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 30 Apr 2019 18:03:46 +1000 Subject: [PATCH 12/52] Generalize release script to work with PSES --- tools/postReleaseScripts/publishGHRelease.ps1 | 19 +----- .../publishVsixGHRelease.ps1 | 68 ------------------- 2 files changed, 2 insertions(+), 85 deletions(-) delete mode 100644 tools/postReleaseScripts/publishVsixGHRelease.ps1 diff --git a/tools/postReleaseScripts/publishGHRelease.ps1 b/tools/postReleaseScripts/publishGHRelease.ps1 index 435c2f715c..07b5cd8aef 100644 --- a/tools/postReleaseScripts/publishGHRelease.ps1 +++ b/tools/postReleaseScripts/publishGHRelease.ps1 @@ -1,8 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -#requires -Version 6.0 - param( [Parameter(Mandatory)] [semver] @@ -31,17 +29,6 @@ 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( @@ -51,10 +38,7 @@ 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]) @@ -76,4 +60,5 @@ $releaseParams = @{ Description = GetDescriptionFromChangelog -ChangelogPath $ChangelogPath GitHubToken = $GitHubToken } -Publish-GitHubRelease @releaseParams +CreateNewRelease @releaseParams + diff --git a/tools/postReleaseScripts/publishVsixGHRelease.ps1 b/tools/postReleaseScripts/publishVsixGHRelease.ps1 deleted file mode 100644 index e3af41badf..0000000000 --- a/tools/postReleaseScripts/publishVsixGHRelease.ps1 +++ /dev/null @@ -1,68 +0,0 @@ -# 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 435760af537dc158141173e0ca2c0310f2dd4a4a Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 14:57:26 +1000 Subject: [PATCH 13/52] Update GH module --- tools/postReleaseScripts/publishGHRelease.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 28aff44d25b74bc2378a79fe84c945c8e8764c13 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 13 May 2019 11:28:32 -0700 Subject: [PATCH 14/52] 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 c54e05122e..1175938901 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 383481b18ec4d7cf60b9b35fa39a0644532e3836 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 13 May 2019 11:29:16 -0700 Subject: [PATCH 15/52] 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 1175938901..b82fee6eed 100644 --- a/tools/postReleaseScripts/updateAzureDataStudio.ps1 +++ b/tools/postReleaseScripts/updateAzureDataStudio.ps1 @@ -273,4 +273,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 a543049af57c106b7af24f26c4665ff89891dd2b Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 29 Apr 2019 13:24:37 +1000 Subject: [PATCH 16/52] 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 18526cfcf72fb40091a19a28b1d1b52e0453ac45 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 29 Apr 2019 13:36:24 +1000 Subject: [PATCH 17/52] 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 4304175fdc06572bcbe9a7695026323e9765cd19 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 29 Apr 2019 17:02:25 +1000 Subject: [PATCH 18/52] 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 edd924cafb050ede601bed452e517b7d5897499a Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 30 Apr 2019 09:57:47 +1000 Subject: [PATCH 19/52] 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 e418772c4a920174c0183857ed1142ee4fb71e49 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 30 Apr 2019 10:10:49 +1000 Subject: [PATCH 20/52] 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 a82beeb64097fd7a0d60f8d446339d9aeab371cc Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 09:10:50 +1000 Subject: [PATCH 21/52] Simplify default parameters, move dir --- .../updateAzureDataStudio.ps1 | 8 +- .../updateExtensionVersions.ps1 | 49 ++- .../postReleaseScripts/updatePsesVersions.ps1 | 32 +- .../updateAzureDataStudio.ps1 | 274 ----------------- .../updateExtensionVersions.ps1 | 283 ------------------ .../repoUpdateScripts/updatePsesVersions.ps1 | 218 -------------- 6 files changed, 31 insertions(+), 833 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 b82fee6eed..d2c5ae3877 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] @@ -255,13 +253,13 @@ $cloneParams = @{ upstream = 'https://github.com/Microsoft/AzureDataStudio' } } -Copy-GitRepository @cloneParams +CloneRepo @cloneParams $GalleryFileName | ForEach-Object { "$repoLocation/$_" } | UpdateGalleryFile -ExtensionVersion $ExtensionVersion -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 @@ -273,4 +271,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..e56b8aa879 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 \ No newline at end of file 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 45f277d623..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 \ No newline at end of file From b27e90ad44eb421c8c06d842efce176b0470ddcf Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 10:52:09 +1000 Subject: [PATCH 22/52] Give proper names to functions --- .../updateAzureDataStudio.ps1 | 6 +++--- .../updateExtensionVersions.ps1 | 18 +++++++++--------- .../postReleaseScripts/updatePsesVersions.ps1 | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tools/postReleaseScripts/updateAzureDataStudio.ps1 b/tools/postReleaseScripts/updateAzureDataStudio.ps1 index d2c5ae3877..d3df0666b4 100644 --- a/tools/postReleaseScripts/updateAzureDataStudio.ps1 +++ b/tools/postReleaseScripts/updateAzureDataStudio.ps1 @@ -253,13 +253,13 @@ $cloneParams = @{ upstream = 'https://github.com/Microsoft/AzureDataStudio' } } -CloneRepo @cloneParams +Copy-GitRepository @cloneParams $GalleryFileName | ForEach-Object { "$repoLocation/$_" } | UpdateGalleryFile -ExtensionVersion $ExtensionVersion -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 @@ -271,4 +271,4 @@ $prParams = @{ GitHubToken = $GitHubToken FromOrg = 'rjmholt' } -OpenGitHubPr @prParams \ No newline at end of file +New-GitHubPR @prParams diff --git a/tools/postReleaseScripts/updateExtensionVersions.ps1 b/tools/postReleaseScripts/updateExtensionVersions.ps1 index 9f8d909595..57d9687332 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 diff --git a/tools/postReleaseScripts/updatePsesVersions.ps1 b/tools/postReleaseScripts/updatePsesVersions.ps1 index e56b8aa879..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 \ No newline at end of file +New-GitHubPR @prParams From df271e38ab3f652661398174b3e24ed879a19792 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 11:45:36 +1000 Subject: [PATCH 23/52] Rename functions, fix parameter problems --- .../updateAzureDataStudio.ps1 | 2 +- .../updateExtensionVersions.ps1 | 35 ++++++++++++------- .../postReleaseScripts/updatePsesVersions.ps1 | 20 ++++++++--- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/tools/postReleaseScripts/updateAzureDataStudio.ps1 b/tools/postReleaseScripts/updateAzureDataStudio.ps1 index d3df0666b4..872800adef 100644 --- a/tools/postReleaseScripts/updateAzureDataStudio.ps1 +++ b/tools/postReleaseScripts/updateAzureDataStudio.ps1 @@ -259,7 +259,7 @@ $GalleryFileName | ForEach-Object { "$repoLocation/$_" } | UpdateGalleryFile -ExtensionVersion $ExtensionVersion -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 57d9687332..2f3758cd73 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 7ba47ab82d7edc353a5650b0425549b0bde41e9c Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 12:16:08 +1000 Subject: [PATCH 24/52] Change segment function verb --- tools/postReleaseScripts/updateExtensionVersions.ps1 | 6 +++--- tools/postReleaseScripts/updatePsesVersions.ps1 | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/postReleaseScripts/updateExtensionVersions.ps1 b/tools/postReleaseScripts/updateExtensionVersions.ps1 index 2f3758cd73..48b99eb77e 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 b20451624f8fdab8c5d2c56179dc53f19747b111 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 May 2019 18:39:47 +1000 Subject: [PATCH 25/52] Add GH PR/issue fetching --- tools/GitHubTools.psm1 | 238 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 236 insertions(+), 2 deletions(-) diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index 7d348ea8bf..ae57db43ac 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -1,7 +1,134 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -function GetHumanishRepositoryName +class GitHubIssueInfo +{ + [int]$Number + [string]$Organization + [string]$Repository + + [uri]GetHtmlUri() + { + return [uri]"https://github.com/$($this.Organization)/$($this.Repository)/issues/$($this.Number)" + } + + [uri]GetApiUri() + { + return [uri]"https://api.github.com/repos/$($this.Organization)/$($this.Repository)/issues/$($this.Number)" + } +} + +class GitHubIssue : GitHubIssueInfo +{ + [pscustomobject]$RawResponse + [string]$Body + [string[]]$Labels +} + +class GitHubPR : GitHubIssue +{ + hidden [GitHubIssueInfo[]]$ClosedIssues = $null + + [GitHubIssueInfo[]]GetClosedIssueInfos() + { + if ($null -eq $this.ClosedIssues) + { + $this.ClosedIssues = $this.Body | + GetClosedIssueUrisInBodyText | + GetGitHubIssueFromUri + } + + return $this.ClosedIssues + } +} + +$script:CloseKeywords = @( + 'close' + 'closes' + 'closed' + 'fix' + 'fixes' + 'fixed' + 'resolve' + 'resolves' + 'resolved' +) +$script:EndNonCharRegex = [regex]::new('[^0-9]*$', 'compiled') +filter GetClosedIssueUrisInBodyText +{ + param( + [Parameter(ValueFromPipeline)] + [string] + $Text + ) + + $words = $Text.Split() + + $expectIssue = $false + for ($i = 0; $i -lt $words.Length; $i++) + { + $currWord = $words[$i] + + if ($script:CloseKeywords -contains $currWord) + { + $expectIssue = $true + continue + } + + if (-not $expectIssue) + { + continue + } + + $expectIssue = $false + + $trimmedWord = $script:EndNonCharRegex.Replace($currWord, '') + + if ([uri]::IsWellFormedUriString($trimmedWord, 'Absolute')) + { + # Yield + [uri]$trimmedWord + } + } +} + +filter GetGitHubIssueFromUri +{ + param( + [Parameter(ValueFromPipeline)] + [uri] + $IssueUri + ) + + if ($IssueUri.Authority -ne 'github.com') + { + return + } + + if ($IssueUri.Segments.Length -ne 5) + { + return + } + + if ($IssueUri.Segments[3] -ne 'issues/') + { + return + } + + $issueNum = -1 + if (-not [int]::TryParse($IssueUri.Segments[4], [ref]$issueNum)) + { + return + } + + return [GitHubIssueInfo]@{ + Organization = $IssueUri.Segments[1].TrimEnd('/') + Repository = $IssueUri.Segments[2].TrimEnd('/') + Number = $issueNum + } +} + +filter GetHumanishRepositoryName { param( [string] @@ -240,6 +367,113 @@ function New-GitHubPR Invoke-RestMethod -Method Post -Uri $uri -Body $body -Headers $headers } +function Get-GitHubPR +{ + param( + [Parameter(Mandatory)] + [string] + $Organization, + + [Parameter(Mandatory)] + [string] + $Repository, + + [Parameter(Mandatory)] + [int[]] + $PullNumber, + + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] + $GitHubToken + ) + + return $PullNumber | + ForEach-Object { + $params = @{ + Method = 'Get' + Uri = "https://api.github.com/repos/$Organization/$Repository/pulls/$_" + } + + if ($GitHubToken) + { + $params.Headers = @{ + Authorization = "token $GitHubToken" + } + } + + $prResponse = Invoke-RestMethod @params + + [GitHubPR]@{ + RawResponse = $prResponse + Number = $prResponse.Number + Organization = $Organization + Repository = $Repository + Body = $prResponse.body + Labels = $prResponse.labels.name + } + } +} + +function Get-GitHubIssue +{ + [CmdletBinding(DefaultParameterSetName='IssueInfo')] + param( + [Parameter(Mandatory, Position=0, ParameterSetName='IssueInfo')] + [GitHubIssueInfo] + $IssueInfo, + + [Parameter(Mandatory, ParameterSetName='Params')] + [string] + $Organization, + + [Parameter(Mandatory, ParameterSetName='Params')] + [string] + $Repository, + + [Parameter(Mandatory, ParameterSetName='Params')] + [int] + $Number, + + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] + $GitHubToken + ) + + if (-not $IssueInfo) + { + $IssueInfo = [GitHubIssueInfo]@{ + Organization = $Organization + Repository = $Repository + Number = $Number + } + } + + $irmParams = @{ + Method = 'Get' + Uri = $IssueInfo.GetApiUri() + } + + if ($GitHubToken) + { + $irmParams.Headers = @{ + Authorization = "token $GitHubToken" + } + } + + $issueResponse = Invoke-RestMethod @irmParams + + return [GitHubIssue]@{ + Organization = $Organization + Repository = $Repository + Number = $Number + RawResponse = $issueResponse + Body = $issueResponse.body + Labels = $issueResponse.labels.name + } +} + function Publish-GitHubRelease { param( @@ -338,4 +572,4 @@ function Publish-GitHubRelease return $response } -Export-ModuleMember -Function Copy-GitRepository,Submit-GitChanges,New-GitHubPR,Publish-GitHubRelease +Export-ModuleMember -Function Copy-GitRepository,Submit-GitChanges,New-GitHubPR,Get-GitHubPR,Get-GitHubIssue,Publish-GitHubRelease From a0fd0c40feb9d164e514e7752f6cc80da90654f1 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Thu, 2 May 2019 15:18:42 +1000 Subject: [PATCH 26/52] Initial changelog generation --- tools/GitHubTools.psm1 | 262 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 252 insertions(+), 10 deletions(-) diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index ae57db43ac..d16cf4cf98 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -1,6 +1,24 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +class GitCommitInfo +{ + [string]$Hash + [string[]]$ParentHashes + [string]$Subject + [string]$Body + [string]$ContributorName + [string]$ContributorEmail + [string[]]$CommitLabels + [int]$PRNumber = -1 +} + +class GitHubCommitInfo : GitCommitInfo +{ + [string]$Organization + [string]$Repository +} + class GitHubIssueInfo { [int]$Number @@ -42,6 +60,17 @@ class GitHubPR : GitHubIssue } } +class ChangelogItem +{ + [GitHubCommitInfo]$Commit + [GitHubPR]$PR + [GitHubIssue[]]$ClosedIssues + [string[]]$Labels + [int]$IssueNumber = -1 + [int]$PRNumber = -1 + [string]$BodyText +} + $script:CloseKeywords = @( 'close' 'closes' @@ -128,23 +157,31 @@ filter GetGitHubIssueFromUri } } -filter GetHumanishRepositoryName +filter GetHumanishRepositoryDetails { param( [string] - $Repository + $RemoteUrl ) - if ($Repository.EndsWith('.git')) + if ($RemoteUrl.EndsWith('.git')) { - $Repository = $Repository.Substring(0, $Repository.Length - 4) + $RemoteUrl = $RemoteUrl.Substring(0, $RemoteUrl.Length - 4) } else { - $Repository = $Repository.Trim('/') + $RemoteUrl = $RemoteUrl.Trim('/') } - return $Repository.Substring($Repository.LastIndexOf('/') + 1) + $lastSlashIdx = $RemoteUrl.LastIndexOf('/') + $repository = $RemoteUrl.Substring($lastSlashIdx + 1) + $secondLastSlashIdx = $RemoteUrl.LastIndexOfAny(('/', ':'), $lastSlashIdx - 1) + $organization = $RemoteUrl.Substring($secondLastSlashIdx + 1, $lastSlashIdx - $secondLastSlashIdx - 1) + + return @{ + Organization = $organization + Repository = $repository + } } function Exec @@ -180,7 +217,7 @@ function Copy-GitRepository [Parameter()] [ValidateNotNullOrEmpty()] [string] - $Destination = (GetHumanishRepositoryName $OriginRemote), + $Destination = ((GetHumanishRepositoryDetails $OriginRemote).Repository), [Parameter()] [string] @@ -309,6 +346,76 @@ function Submit-GitChanges } } +function Get-GitCommit +{ + [CmdletBinding(DefaultParameterSetName='SinceRef')] + param( + [Parameter(Mandatory, ParameterSetName='SinceRef')] + [Alias('SinceBranch', 'SinceTag')] + [string] + $SinceRef, + + [Parameter(ParameterSetName='SinceRef')] + [Alias('UntilBranch', 'UntilTag')] + [string] + $UntilRef = 'HEAD', + + [Parameter()] + [string] + $Remote + ) + + if (-not $Remote) + { + $Remote = 'upstream' + try + { + $null = Exec { git remote get-url $Remote } + } + catch + { + $Remote = 'origin' + } + } + + $originDetails = GetHumanishRepositoryDetails -RemoteUrl (Exec { git remote get-url $Remote }) + + $format = '%H||%P||%aN||%aE||%s' + $commits = Exec { git --no-pager log "$SinceRef..$UntilRef" --format=$format } + + return $commits | + ForEach-Object { + $hash,$parents,$name,$email,$subject = $_.Split('||') + $body = (Exec { git --no-pager show $hash -s --format=%b }) -join "`n" + $commitVal = [GitHubCommitInfo]@{ + Hash = $hash + ParentHashes = $parents + ContributorName = $name + ContributorEmail = $email + Subject = $subject + Body = $body + Organization = $originDetails.Organization + Repository = $originDetails.Repository + } + + # Look for something like 'This is a commit message (#1224)' + $pr = [regex]::Match($subject, '\(#(\d+)\)$').Groups[1].Value + if ($pr) + { + $commitVal.PRNumber = $pr + } + + # Look for something like '[Ignore] [giraffe] Fix tests' + $commitLabels = [regex]::Matches($subject, '^(\[(.*?)\]\s*)*') + if ($commitLabels.Groups.Length -ge 3 -and $commitLabels.Groups[2].Captures.Value) + { + $commitVal.CommitLabels = $commitLabels.Groups[2].Captures.Value + } + + $commitVal + } +} + function New-GitHubPR { param( @@ -415,11 +522,11 @@ function Get-GitHubPR } } -function Get-GitHubIssue +filter Get-GitHubIssue { [CmdletBinding(DefaultParameterSetName='IssueInfo')] param( - [Parameter(Mandatory, Position=0, ParameterSetName='IssueInfo')] + [Parameter(Mandatory, ValueFromPipeline, Position=0, ParameterSetName='IssueInfo')] [GitHubIssueInfo] $IssueInfo, @@ -572,4 +679,139 @@ function Publish-GitHubRelease return $response } -Export-ModuleMember -Function Copy-GitRepository,Submit-GitChanges,New-GitHubPR,Get-GitHubPR,Get-GitHubIssue,Publish-GitHubRelease +filter New-ChangelogItem +{ + param( + [Parameter(Mandatory, ValueFromPipeline, Position=0)] + [GitHubCommitInfo[]] + $Commit, + + [Parameter(Mandatory)] + [string] + $GitHubToken + ) + + foreach ($singleCommit in $Commit) + { + $changelogItem = [ChangelogItem]@{ + Commit = $singleCommit + BodyText = $singleCommit.Body + Labels = $singleCommit.CommitLabels + } + + if ($Commit.PRNumber -ge 0) + { + $getPrParams = @{ + Organization = $singleCommit.Organization + Repository = $singleCommit.Repository + PullNumber = $singleCommit.PRNumber + GitHubToken = $GitHubToken + } + $pr = Get-GitHubPR @getPrParams + + $changelogItem.PR = $pr + $changelogItem.PRNumber = $pr.Number + + $closedIssueInfos = $pr.GetClosedIssueInfos() + if ($closedIssueInfos) + { + $changelogItem.ClosedIssues = $closedIssueInfos | Get-GitHubIssue + $changelogItem.IssueNumber = $closedIssueInfos[0].Number + $changelogItem.Labels += ($closedIssueInfos | ForEach-Object { $_.Labels }) + } + } + + $changelogItem + } +} + +function New-ChangelogSection +{ + param( + [Parameter(Mandatory)] + [string] + $ReleaseName, + + [Parameter(Mandatory)] + [string] + $RepositoryUrl, + + [Parameter(ValueFromPipeline)] + [ChangelogItem[]] + $ChangelogItem, + + [Parameter()] + [string] + $DateFormat = 'dddd, dd MMMM yyyy', + + [Parameter()] + [datetime] + $Date = ([datetime]::Now) + ) + + begin + { + $repoDetails = GetHumanishRepositoryDetails -RemoteUrl $RepositoryUrl + $repository = $repoDetails.Repository + $organization = $repoDetails.Organization + + $clBuilder = [System.Text.StringBuilder]::new() + $null = $clBuilder.Append("##$ReleaseName`n") + $null = $clBuilder.Append("###$($Date.ToString($DateFormat))`n") + $null = $clBuilder.Append("####[$repository]($RepositoryUrl)`n`n") + } + + process + { + foreach ($clItem in $ChangelogItem) + { + if ($clItem.Labels -contains 'ignore') + { + continue + } + + if (-not $clItem.BodyText) + { + continue + } + + if ($clItem.IssueNumber -gt 0) + { + $issueNumber = $clItem.IssueNumber + } + elseif ($clItem.PRNumber -gt 0) + { + $issueNumber = $clItem.PRNumber + } + + if ($issueNumber) + { + $itemHeader = "$repository #$issueNumber" + } + else + { + $itemHeader = "$repository" + } + + $itemLink = "https://github.com/$organization/$repository" + if ($clItem.PRNumber -ge 0) + { + $prNum = $clItem.PRNumber + $itemLink += "/pull/$prNum" + } + + $indentedBody = ($clItem.BodyText.Split("`n") | Where-Object { $_ } | ForEach-Object { " $_" }) -join "`n" + + $itemText = "- [$itemHeader]($itemLink) -`n$indentedBody`n" + + $null = $clBuilder.Append($itemText) + } + } + + end + { + return $clBuilder.Append("`n").ToString() + } +} + +Export-ModuleMember -Function Copy-GitRepository,Submit-GitChanges,New-GitHubPR,Get-GitHubPR,Get-GitHubIssue,Publish-GitHubRelease,New-ChangelogItem,New-ChangelogSection From a8222d72da56484a8845246a2e1e348422d08b02 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Fri, 3 May 2019 12:00:41 +1000 Subject: [PATCH 27/52] Add thanks --- tools/ChangelogTools.psm1 | 167 ++++++++++++++++++++++++++++++++++++++ tools/GitHubTools.psm1 | 21 ++--- 2 files changed, 175 insertions(+), 13 deletions(-) create mode 100644 tools/ChangelogTools.psm1 diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 new file mode 100644 index 0000000000..50d08d4b88 --- /dev/null +++ b/tools/ChangelogTools.psm1 @@ -0,0 +1,167 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +using module ./GitHubTools.psm1 + +$script:NoThanks = @( + 'rjmholt' + 'TylerLeonhardt' + 'daxian-dbw' + 'SteveL-MSFT' + 'PaulHigin' +) + +class ChangelogItem +{ + [GitHubCommitInfo]$Commit + [GitHubPR]$PR + [GitHubIssue[]]$ClosedIssues + [int]$IssueNumber = -1 + [int]$PRNumber = -1 + [string]$ContributingUser +} + +filter Get-ChangelogItemFromCommit +{ + param( + [Parameter(Mandatory, ValueFromPipeline, Position=0)] + [GitHubCommitInfo[]] + $Commit, + + [Parameter(Mandatory)] + [string] + $GitHubToken, + + [Parameter()] + [hashtable] + $KnownUserEmails + ) + + foreach ($singleCommit in $Commit) + { + $changelogItem = [ChangelogItem]@{ + Commit = $singleCommit + BodyText = $singleCommit.Body + ChangeLabels = $singleCommit.CommitLabels + ContributingUser = $singleCommit.GitHubCommitData.author.login + } + + if ($Commit.PRNumber -ge 0) + { + $getPrParams = @{ + Organization = $singleCommit.Organization + Repository = $singleCommit.Repository + PullNumber = $singleCommit.PRNumber + GitHubToken = $GitHubToken + } + $pr = Get-GitHubPR @getPrParams + + $changelogItem.PR = $pr + $changelogItem.PRNumber = $pr.Number + + $closedIssueInfos = $pr.GetClosedIssueInfos() + if ($closedIssueInfos) + { + $changelogItem.ClosedIssues = $closedIssueInfos | Get-GitHubIssue + $changelogItem.IssueNumber = $closedIssueInfos[0].Number + $changelogItem.Labels += ($closedIssueInfos | ForEach-Object { $_.Labels }) + } + } + + $changelogItem + } +} + +function New-ChangelogSection +{ + param( + [Parameter(Mandatory)] + [string] + $ReleaseName, + + [Parameter(Mandatory)] + [string] + $RepositoryUrl, + + [Parameter(ValueFromPipeline)] + [ChangelogItem[]] + $ChangelogItem, + + [Parameter()] + [string] + $DateFormat = 'dddd, dd MMMM yyyy', + + [Parameter()] + [datetime] + $Date = ([datetime]::Now) + ) + + begin + { + $repoDetails = GetHumanishRepositoryDetails -RemoteUrl $RepositoryUrl + $repository = $repoDetails.Repository + $organization = $repoDetails.Organization + + $clBuilder = [System.Text.StringBuilder]::new() + $null = $clBuilder.Append("##$ReleaseName`n") + $null = $clBuilder.Append("###$($Date.ToString($DateFormat))`n") + $null = $clBuilder.Append("####[$repository]($RepositoryUrl)`n`n") + } + + process + { + foreach ($clItem in $ChangelogItem) + { + if ($clItem.Labels -contains 'ignore') + { + continue + } + + if (-not $clItem.BodyText) + { + continue + } + + if ($clItem.IssueNumber -gt 0) + { + $issueNumber = $clItem.IssueNumber + } + elseif ($clItem.PRNumber -gt 0) + { + $issueNumber = $clItem.PRNumber + } + + if ($issueNumber) + { + $itemHeader = "$repository #$issueNumber" + } + else + { + $itemHeader = "$repository" + } + + $itemLink = "https://github.com/$organization/$repository" + if ($clItem.PRNumber -ge 0) + { + $prNum = $clItem.PRNumber + $itemLink += "/pull/$prNum" + } + + $indentedBody = ($clItem.BodyText.Split("`n") | Where-Object { $_ } | ForEach-Object { " $_" }) -join "`n" + + if ($script:NoThanks -notcontains $clItem.ContributingUser) + { + $thanks = " (thanks @$($clItem.ContributingUser)!)" + } + + $itemText = "- [$itemHeader]($itemLink) -`n$indentedBody$thanks`n" + + $null = $clBuilder.Append($itemText) + } + } + + end + { + return $clBuilder.Append("`n").ToString() + } +} \ No newline at end of file diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index d16cf4cf98..7d6bc0fe94 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -17,6 +17,7 @@ class GitHubCommitInfo : GitCommitInfo { [string]$Organization [string]$Repository + [pscustomobject]$GitHubCommitData } class GitHubIssueInfo @@ -60,17 +61,6 @@ class GitHubPR : GitHubIssue } } -class ChangelogItem -{ - [GitHubCommitInfo]$Commit - [GitHubPR]$PR - [GitHubIssue[]]$ClosedIssues - [string[]]$Labels - [int]$IssueNumber = -1 - [int]$PRNumber = -1 - [string]$BodyText -} - $script:CloseKeywords = @( 'close' 'closes' @@ -379,6 +369,8 @@ function Get-GitCommit } $originDetails = GetHumanishRepositoryDetails -RemoteUrl (Exec { git remote get-url $Remote }) + $organization = $originDetails.Organization + $repository = $originDetails.Repository $format = '%H||%P||%aN||%aE||%s' $commits = Exec { git --no-pager log "$SinceRef..$UntilRef" --format=$format } @@ -394,10 +386,13 @@ function Get-GitCommit ContributorEmail = $email Subject = $subject Body = $body - Organization = $originDetails.Organization - Repository = $originDetails.Repository + Organization = $organization + Repository = $repository } + # Query the GitHub API for more commit information + $commitVal.GitHubCommitData = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/$organization/$repository/commits/$hash" + # Look for something like 'This is a commit message (#1224)' $pr = [regex]::Match($subject, '\(#(\d+)\)$').Groups[1].Value if ($pr) From 231642fffbb330490eef26e474bfa37d58797692 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 13 May 2019 16:57:08 -0700 Subject: [PATCH 28/52] WIP --- tools/ChangelogTools.psm1 | 100 +------------------ tools/GitHubTools.psm1 | 145 ++-------------------------- tools/changelog/updateChangelog.ps1 | 38 ++++++++ 3 files changed, 49 insertions(+), 234 deletions(-) create mode 100644 tools/changelog/updateChangelog.ps1 diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 index 50d08d4b88..90a6f99bec 100644 --- a/tools/ChangelogTools.psm1 +++ b/tools/ChangelogTools.psm1 @@ -30,11 +30,7 @@ filter Get-ChangelogItemFromCommit [Parameter(Mandatory)] [string] - $GitHubToken, - - [Parameter()] - [hashtable] - $KnownUserEmails + $GitHubToken ) foreach ($singleCommit in $Commit) @@ -72,96 +68,4 @@ filter Get-ChangelogItemFromCommit } } -function New-ChangelogSection -{ - param( - [Parameter(Mandatory)] - [string] - $ReleaseName, - - [Parameter(Mandatory)] - [string] - $RepositoryUrl, - - [Parameter(ValueFromPipeline)] - [ChangelogItem[]] - $ChangelogItem, - - [Parameter()] - [string] - $DateFormat = 'dddd, dd MMMM yyyy', - - [Parameter()] - [datetime] - $Date = ([datetime]::Now) - ) - - begin - { - $repoDetails = GetHumanishRepositoryDetails -RemoteUrl $RepositoryUrl - $repository = $repoDetails.Repository - $organization = $repoDetails.Organization - - $clBuilder = [System.Text.StringBuilder]::new() - $null = $clBuilder.Append("##$ReleaseName`n") - $null = $clBuilder.Append("###$($Date.ToString($DateFormat))`n") - $null = $clBuilder.Append("####[$repository]($RepositoryUrl)`n`n") - } - - process - { - foreach ($clItem in $ChangelogItem) - { - if ($clItem.Labels -contains 'ignore') - { - continue - } - - if (-not $clItem.BodyText) - { - continue - } - - if ($clItem.IssueNumber -gt 0) - { - $issueNumber = $clItem.IssueNumber - } - elseif ($clItem.PRNumber -gt 0) - { - $issueNumber = $clItem.PRNumber - } - - if ($issueNumber) - { - $itemHeader = "$repository #$issueNumber" - } - else - { - $itemHeader = "$repository" - } - - $itemLink = "https://github.com/$organization/$repository" - if ($clItem.PRNumber -ge 0) - { - $prNum = $clItem.PRNumber - $itemLink += "/pull/$prNum" - } - - $indentedBody = ($clItem.BodyText.Split("`n") | Where-Object { $_ } | ForEach-Object { " $_" }) -join "`n" - - if ($script:NoThanks -notcontains $clItem.ContributingUser) - { - $thanks = " (thanks @$($clItem.ContributingUser)!)" - } - - $itemText = "- [$itemHeader]($itemLink) -`n$indentedBody$thanks`n" - - $null = $clBuilder.Append($itemText) - } - } - - end - { - return $clBuilder.Append("`n").ToString() - } -} \ No newline at end of file +Export-ModuleMember -Function Get-ChangelogItemFromCommit \ No newline at end of file diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index 7d6bc0fe94..c2fa11b0f7 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -674,139 +674,12 @@ function Publish-GitHubRelease return $response } -filter New-ChangelogItem -{ - param( - [Parameter(Mandatory, ValueFromPipeline, Position=0)] - [GitHubCommitInfo[]] - $Commit, - - [Parameter(Mandatory)] - [string] - $GitHubToken - ) - - foreach ($singleCommit in $Commit) - { - $changelogItem = [ChangelogItem]@{ - Commit = $singleCommit - BodyText = $singleCommit.Body - Labels = $singleCommit.CommitLabels - } - - if ($Commit.PRNumber -ge 0) - { - $getPrParams = @{ - Organization = $singleCommit.Organization - Repository = $singleCommit.Repository - PullNumber = $singleCommit.PRNumber - GitHubToken = $GitHubToken - } - $pr = Get-GitHubPR @getPrParams - - $changelogItem.PR = $pr - $changelogItem.PRNumber = $pr.Number - - $closedIssueInfos = $pr.GetClosedIssueInfos() - if ($closedIssueInfos) - { - $changelogItem.ClosedIssues = $closedIssueInfos | Get-GitHubIssue - $changelogItem.IssueNumber = $closedIssueInfos[0].Number - $changelogItem.Labels += ($closedIssueInfos | ForEach-Object { $_.Labels }) - } - } - - $changelogItem - } -} - -function New-ChangelogSection -{ - param( - [Parameter(Mandatory)] - [string] - $ReleaseName, - - [Parameter(Mandatory)] - [string] - $RepositoryUrl, - - [Parameter(ValueFromPipeline)] - [ChangelogItem[]] - $ChangelogItem, - - [Parameter()] - [string] - $DateFormat = 'dddd, dd MMMM yyyy', - - [Parameter()] - [datetime] - $Date = ([datetime]::Now) - ) - - begin - { - $repoDetails = GetHumanishRepositoryDetails -RemoteUrl $RepositoryUrl - $repository = $repoDetails.Repository - $organization = $repoDetails.Organization - - $clBuilder = [System.Text.StringBuilder]::new() - $null = $clBuilder.Append("##$ReleaseName`n") - $null = $clBuilder.Append("###$($Date.ToString($DateFormat))`n") - $null = $clBuilder.Append("####[$repository]($RepositoryUrl)`n`n") - } - - process - { - foreach ($clItem in $ChangelogItem) - { - if ($clItem.Labels -contains 'ignore') - { - continue - } - - if (-not $clItem.BodyText) - { - continue - } - - if ($clItem.IssueNumber -gt 0) - { - $issueNumber = $clItem.IssueNumber - } - elseif ($clItem.PRNumber -gt 0) - { - $issueNumber = $clItem.PRNumber - } - - if ($issueNumber) - { - $itemHeader = "$repository #$issueNumber" - } - else - { - $itemHeader = "$repository" - } - - $itemLink = "https://github.com/$organization/$repository" - if ($clItem.PRNumber -ge 0) - { - $prNum = $clItem.PRNumber - $itemLink += "/pull/$prNum" - } - - $indentedBody = ($clItem.BodyText.Split("`n") | Where-Object { $_ } | ForEach-Object { " $_" }) -join "`n" - - $itemText = "- [$itemHeader]($itemLink) -`n$indentedBody`n" - - $null = $clBuilder.Append($itemText) - } - } - - end - { - return $clBuilder.Append("`n").ToString() - } -} - -Export-ModuleMember -Function Copy-GitRepository,Submit-GitChanges,New-GitHubPR,Get-GitHubPR,Get-GitHubIssue,Publish-GitHubRelease,New-ChangelogItem,New-ChangelogSection +Export-ModuleMember -Function @( + 'Copy-GitRepository', + 'Submit-GitChanges', + 'Get-GitCommit', + 'New-GitHubPR', + 'Get-GitHubPR', + 'Get-GitHubIssue', + 'Publish-GitHubRelease' +) diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 new file mode 100644 index 0000000000..cf4a3523f4 --- /dev/null +++ b/tools/changelog/updateChangelog.ps1 @@ -0,0 +1,38 @@ +using module ../ChangelogTools.psm1 +using module ../GitHubTools.psm1 + +param( + [Parameter()] + $RepositoryLocation = (Resolve-Path "$PSScriptRoot/../../") +) + +$script:ChangelogConfig = @{ + DefaultCategory = 'General' + Categories = @( + @{ + Name = 'Debugging' + Issue = 'Area-Debugging' + }, + @{ + Name = 'CodeLens' + Issue = 'Area-CodeLens' + }, + @{ + Name = 'Script Analysis' + Issue = 'Area-Script Analysis' + }, + @{ + Name = 'Formatting' + Issue = 'Area-Formatting' + }, + @{ + Name = 'Integrated Console' + Issue = 'Area-Integrated Console','Area-PSReadLine' + } + @{ + Name = Intellisense + Issue = 'Area-Intellisense' + } + ) +} + From fb00c39b884e09d2d60015cc9c50de9ff83db412 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 15 May 2019 19:00:00 -0700 Subject: [PATCH 29/52] Progress --- tools/ChangelogTools.psm1 | 10 +- tools/GitHubTools.psm1 | 68 ++++-- tools/changelog/updateChangelog.ps1 | 206 ++++++++++++++++-- .../updateAzureDataStudio.ps1 | 2 + .../updateExtensionVersions.ps1 | 2 + .../postReleaseScripts/updatePsesVersions.ps1 | 2 + 6 files changed, 239 insertions(+), 51 deletions(-) diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 index 90a6f99bec..d4469d69e5 100644 --- a/tools/ChangelogTools.psm1 +++ b/tools/ChangelogTools.psm1 @@ -1,15 +1,9 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -using module ./GitHubTools.psm1 +#requires -Version 6.0 -$script:NoThanks = @( - 'rjmholt' - 'TylerLeonhardt' - 'daxian-dbw' - 'SteveL-MSFT' - 'PaulHigin' -) +using module ./GitHubTools.psm1 class ChangelogItem { diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index c2fa11b0f7..e6f5746a3f 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -1,6 +1,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +#requires -Version 6.0 + class GitCommitInfo { [string]$Hash @@ -61,6 +63,33 @@ class GitHubPR : GitHubIssue } } +function GetGitHubHeaders +{ + param( + [Parameter()] + [string] + $GitHubToken, + + [Parameter()] + [string] + $Accept + ) + + $headers = @{} + + if ($GitHubToken) + { + $headers.Authorization = "token $GitHubToken" + } + + if ($Accept) + { + $headers.Accept = $Accept + } + + return $headers +} + $script:CloseKeywords = @( 'close' 'closes' @@ -352,7 +381,11 @@ function Get-GitCommit [Parameter()] [string] - $Remote + $Remote, + + [Parameter()] + [string] + $GitHubToken ) if (-not $Remote) @@ -375,6 +408,15 @@ function Get-GitCommit $format = '%H||%P||%aN||%aE||%s' $commits = Exec { git --no-pager log "$SinceRef..$UntilRef" --format=$format } + $irmParams = if ($GitHubToken) + { + @{ Headers = GetGitHubHeaders -GitHubToken $GitHubToken -Accept 'application/vnd.github.v3+json' } + } + else + { + @{ Headers = GetGitHubHeaders -Accept 'application/vnd.github.v3+json' } + } + return $commits | ForEach-Object { $hash,$parents,$name,$email,$subject = $_.Split('||') @@ -391,7 +433,7 @@ function Get-GitCommit } # Query the GitHub API for more commit information - $commitVal.GitHubCommitData = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/$organization/$repository/commits/$hash" + $commitVal.GitHubCommitData = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/$organization/$repository/commits/$hash" @irmParams # Look for something like 'This is a commit message (#1224)' $pr = [regex]::Match($subject, '\(#(\d+)\)$').Groups[1].Value @@ -461,10 +503,7 @@ function New-GitHubPR maintainer_can_modify = $true } | ConvertTo-Json - $headers = @{ - Accept = 'application/vnd.github.v3+json' - Authorization = "token $GitHubToken" - } + $headers = GetGitHubHeaders -GitHubToken $GitHubToken -Accept 'application/vnd.github.v3+json' Invoke-RestMethod -Method Post -Uri $uri -Body $body -Headers $headers } @@ -499,9 +538,7 @@ function Get-GitHubPR if ($GitHubToken) { - $params.Headers = @{ - Authorization = "token $GitHubToken" - } + $params.Headers = GetGitHubHeaders -GitHubToken $GitHubToken } $prResponse = Invoke-RestMethod @params @@ -559,9 +596,7 @@ filter Get-GitHubIssue if ($GitHubToken) { - $irmParams.Headers = @{ - Authorization = "token $GitHubToken" - } + $irmParams.Headers = GetGitHubHeaders -GitHubToken $GitHubToken } $issueResponse = Invoke-RestMethod @irmParams @@ -634,10 +669,7 @@ function Publish-GitHubRelease $restBody = ConvertTo-Json -InputObject $restParams $uri = "https://api.github.com/repos/$Organization/$Repository/releases" - $headers = @{ - Accept = 'application/vnd.github.v3+json' - Authorization = "token $GitHubToken" - } + $headers = GetGitHubHeaders -GitHubToken $GitHubToken -Accept 'application/vnd.github.v3+json' $response = Invoke-RestMethod -Method Post -Uri $uri -Body $restBody -Headers $headers @@ -664,9 +696,7 @@ function Publish-GitHubRelease } $assetUri = "${assetBaseUri}?name=$fileName" - $headers = @{ - Authorization = "token $GitHubToken" - } + $headers = GetGitHubHeaders -GitHubToken $GitHubToken # This can be very slow, but it does work $null = Invoke-RestMethod -Method Post -Uri $assetUri -InFile $asset -ContentType $contentType -Headers $headers } diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index cf4a3523f4..5eb6885319 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -1,38 +1,196 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +#requires -Version 6.0 + using module ../ChangelogTools.psm1 using module ../GitHubTools.psm1 param( + [Parameter(Mandatory)] + [string] + $GitHubToken, + + [Parameter(Mandatory)] + [string] + $SinceRef, + + [Parameter()] + [string] + $UntilRef = 'HEAD', + [Parameter()] + [string] $RepositoryLocation = (Resolve-Path "$PSScriptRoot/../../") ) +class ChangelogEntry +{ + [uri]$IssueLink + [uri]$PRLink + [string]$Category + [string[]]$Tags + [string]$Text + [string]$Thanks + [ChangelogItem]$CLItem +} + +class ChangeLog +{ + ChangeLog() + { + $this.Sections = [System.Collections.Generic.Dictionary[string, ChangelogEntry]]::new() + } + + [string]$ReleaseName + [datetime]$Date + [string]$Preamble + [System.Collections.Generic.Dictionary[string, ChangelogEntry]]$Sections +} + $script:ChangelogConfig = @{ - DefaultCategory = 'General' - Categories = @( - @{ - Name = 'Debugging' - Issue = 'Area-Debugging' - }, - @{ - Name = 'CodeLens' - Issue = 'Area-CodeLens' - }, - @{ - Name = 'Script Analysis' - Issue = 'Area-Script Analysis' - }, - @{ - Name = 'Formatting' - Issue = 'Area-Formatting' - }, - @{ - Name = 'Integrated Console' - Issue = 'Area-Integrated Console','Area-PSReadLine' + DateFormat = 'dddd, dd MMMM yyyy' + NoThanks = @( + 'rjmholt' + 'TylerLeonhardt' + 'daxian-dbw' + 'SteveL-MSFT' + 'PaulHigin' + ) + Ignore = @{ + Users = 'dependabot[bot]' + Labels = @{ + Commit = 'Ignore' + } + } + TagLabels = @{ + 'Issue-Enhancement' = 'Feature' + 'Issue-Bug' = 'BugFix' + } + ChangeCategories = @{ + Default = @{ + Name = 'General' + Issue = 'Area-General' } - @{ - Name = Intellisense - Issue = 'Area-Intellisense' + Categories = [ordered]@{ + Debugging = @{ + Issue = 'Area-Debugging' + } + CodeLens = @{ + Issue = 'Area-CodeLens' + } + 'Script Analysis' = @{ + Issue = 'Area-Script Analysis' + } + Formatting = @{ + Issue = 'Area-Formatting' + } + 'Integrated Console' = @{ + Issue = 'Area-Integrated Console','Area-PSReadLine' + } + 'Intellisense' = @{ + Issue = 'Area-Intellisense' + } + } + } +} + +filter FilterIgnoredCommits +{ + param( + [Parameter(Mandatory, ValueFromPipeline)] + [ChangelogItem] + $CLItem, + + [Parameter] + [string[]] + $IgnoreUser, + + [Parameter()] + [string[]] + $IgnoreCommitLabel + ) + + if ($CLItem.ContributingUser -in $IgnoreUser) + { + return + } + + foreach ($commitLabel in $CLItem.Commit.CommitLabels) + { + if ($commitLabel -in $IgnoreCommitLabel) + { + return } + } + + return $CLItem +} + +filter AssembleCLEntry +{ + param( + [Parameter(Mandatory, ValueFromPipeline)] + [ChangelogItem] + $CLItem, + + [Parameter()] + [string] + $Organization = 'PowerShell', + + [Parameter()] + [string] + $Repository = 'vscode-powershell' ) + + [string[]]$tags = @() + :labelLoop foreach ($issueLabel in $CLItem.ClosedIssues.Labels) + { + if (-not $entryCategory) + { + foreach ($category in $script:ChangelogConfig.ChangeCategories.Categories.GetEnumerator()) + { + if ($issueLabel -in $category.Value.Issue) + { + $entryCategory = $category.Key + continue :labelLoop + } + } + } + + $tag = $script:ChangelogConfig.TagLabels[$issueLabel] + if ($tag) + { + $tags += $tag + } + } + + if (-not $entryCategory) + { + $entryCategory = $script:ChangelogConfig.ChangeCategories.Default.Name + } + + return [ChangelogEntry]@{ + IssueLink = if ($CLItem.IssueNumber -ge 0) { "https://github.com/$Organization/$Repository/issues/$($CLItem.IssueNumber)" } + PRLink = if ($CLItem.PRNumber -ge 0) { "https://github.com/$Organization/$Repository/$($CLItem.PRNumber)" } + Thanks = if ($CLItem.ContributingUser -notin $script:NoThanks) { $CLItem.ContributingUser } + Category = $entryCategory + Tags = $tags + CLItem = $CLItem + } +} + +function AssembleCLObject +{ + +} + +function BuildChangelog +{ + } +$changeLog = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken | + Get-ChangelogItemFromCommit -GitHubToken $GitHubToken | + FilterIgnoredCommits -IgnoreUser $ignore.Users -IgnoreCommitLabel $ignore.Labels.Commit | + AssembleCLEntry \ No newline at end of file diff --git a/tools/postReleaseScripts/updateAzureDataStudio.ps1 b/tools/postReleaseScripts/updateAzureDataStudio.ps1 index 872800adef..b82fee6eed 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 48b99eb77e..974a6e43f7 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 49fca7efe3fa40f2221ddc588cab5ad78258dea7 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Thu, 16 May 2019 20:01:15 -0700 Subject: [PATCH 30/52] Add skeleton --- tools/ChangelogTools.psm1 | 271 +++++++++++++++++++++++++++- tools/GitHubTools.psm1 | 138 ++++++++------ tools/changelog/updateChangelog.ps1 | 253 +++++++++++--------------- 3 files changed, 450 insertions(+), 212 deletions(-) diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 index d4469d69e5..cb02c3ef01 100644 --- a/tools/ChangelogTools.psm1 +++ b/tools/ChangelogTools.psm1 @@ -3,9 +3,9 @@ #requires -Version 6.0 -using module ./GitHubTools.psm1 +using module .\GitHubTools.psm1 -class ChangelogItem +class ChangeInfo { [GitHubCommitInfo]$Commit [GitHubPR]$PR @@ -13,9 +13,37 @@ class ChangelogItem [int]$IssueNumber = -1 [int]$PRNumber = -1 [string]$ContributingUser + [string]$BodyText + [string]$Subject } -filter Get-ChangelogItemFromCommit +class ChangelogEntry +{ + [uri]$IssueLink + [uri]$PRLink + [string]$Category + [string[]]$Tags + [string]$BodyText + [string]$Subject + [string]$Thanks + [string]$RepositoryName + [ChangeInfo]$Change +} + +class ChangeLog +{ + ChangeLog() + { + $this.Sections = [System.Collections.Generic.Dictionary[string, ChangelogEntry]]::new() + } + + [string]$ReleaseName + [datetime]$Date + [string]$Preamble + [System.Collections.Generic.Dictionary[string, ChangelogEntry]]$Sections +} + +filter Get-ChangeInfoFromCommit { param( [Parameter(Mandatory, ValueFromPipeline, Position=0)] @@ -29,10 +57,10 @@ filter Get-ChangelogItemFromCommit foreach ($singleCommit in $Commit) { - $changelogItem = [ChangelogItem]@{ + $changelogItem = [ChangeInfo]@{ Commit = $singleCommit BodyText = $singleCommit.Body - ChangeLabels = $singleCommit.CommitLabels + Subject = $singleCommit.Subject ContributingUser = $singleCommit.GitHubCommitData.author.login } @@ -54,7 +82,6 @@ filter Get-ChangelogItemFromCommit { $changelogItem.ClosedIssues = $closedIssueInfos | Get-GitHubIssue $changelogItem.IssueNumber = $closedIssueInfos[0].Number - $changelogItem.Labels += ($closedIssueInfos | ForEach-Object { $_.Labels }) } } @@ -62,4 +89,234 @@ filter Get-ChangelogItemFromCommit } } -Export-ModuleMember -Function Get-ChangelogItemFromCommit \ No newline at end of file +filter New-ChangelogEntry +{ + param( + [Parameter(Mandatory, ValueFromPipeline)] + [ChangeInfo] + $Change, + + [Parameter(Mandatory)] + [System.Collections.Specialized.OrderedDictionary] + $EntryCategories, + + [Parameter(Mandatory)] + [hashtable] + $DefaultCategory, + + [Parameter(Mandatory)] + [hashtable] + $TagLabels, + + [Parameter()] + [string[]] + $NoThanks = @(), + + [Parameter()] + [string] + $Organization = 'PowerShell', + + [Parameter()] + [string] + $Repository = 'vscode-powershell' + ) + + [string[]]$tags = @() + :labelLoop foreach ($issueLabel in $Change.ClosedIssues.Labels) + { + if (-not $entryCategory) + { + foreach ($category in $EntryCategories.GetEnumerator()) + { + if ($issueLabel -in $category.Value.Issue) + { + $entryCategory = $category.Key + continue :labelLoop + } + } + } + + $tag = $TagLabels[$issueLabel] + if ($tag) + { + $tags += $tag + } + } + + if (-not $entryCategory) + { + $entryCategory = $DefaultCategory.Name + } + + $issueLink = if ($Change.IssueNumber -ge 0) { "https://github.com/$Organization/$Repository/issues/$($Change.IssueNumber)" } else { $null } + $prLink = if ($Change.PRNumber -ge 0) { "https://github.com/$Organization/$Repository/$($Change.PRNumber)" } else { $null } + $thanks = if ($Change.ContributingUser -notin $NoThanks) { $Change.ContributingUser } else { $null } + + $subject = $Change.Subject + if ($subject -match '(.*)\(#\d+\)$') + { + $subject = $Matches[1] + } + + return [ChangelogEntry]@{ + IssueLink = $issueLink + PRLink = $prLink + Thanks = $thanks + Category = $entryCategory + Tags = $tags + Change = $Change + RepositoryName = "$Organization/$Repository" + BodyText = $Change.BodyText + Subject = $subject + } +} + +filter Skip-IgnoredChanges +{ + param( + [Parameter(Mandatory, ValueFromPipeline)] + [ChangeInfo] + $Change, + + [Parameter()] + [string[]] + $IgnoreUser, + + [Parameter()] + [string[]] + $IgnoreCommitLabel + ) + + if ($Change.ContributingUser -in $IgnoreUser) + { + return + } + + foreach ($commitLabel in $Change.Commit.CommitLabels) + { + if ($commitLabel -in $IgnoreCommitLabel) + { + return + } + } + + return $Change +} + +function New-ChangeLogSection +{ + param( + [Parameter(Mandatory, ValueFromPipeline)] + [ChangelogEntry[]] + $ChangelogEntry, + + [Parameter(Mandatory)] + [string] + $ReleaseName, + + [Parameter(Mandatory)] + [string[]] + $Categories, + + [Parameter(Mandatory)] + [string] + $DefaultCategory, + + [Parameter()] + [string] + $Preamble, + + [Parameter()] + [string] + $Postamble, + + [Parameter()] + [datetime] + $Date = [datetime]::Now, + + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] + $DateFormat = 'dddd, dd MM yyyy', + + [Parameter()] + [string] + $Indent = ' ' + ) + + begin + { + $entries = [ordered]@{} + + foreach ($category in $Categories) + { + $entries[$category] = [System.Collections.Generic.List[ChangelogEntry]]::new() + } + } + + process + { + foreach ($entry in $ChangelogEntry) + { + $entries[$entry.Category].Add($entry) + } + } + + end + { + $dateStr = $Date.ToString($DateFormat) + $sb = [System.Text.StringBuilder]::new().AppendLine("## $ReleaseName").AppendLine("### $dateStr") + + if ($Preamble) + { + [void]$sb.AppendLine($Preamble) + } + + [void]$sb.AppendLine() + + foreach ($category in $entries.GetEnumerator()) + { + if (-not $category.Value) + { + continue + } + + if ($category.Key -ne $DefaultCategory) + { + [void]$sb.AppendLine("$($category.Key):") + } + + foreach ($item in $category.Value) + { + $project= $item.Change.Commit.Repository + $issueNumber = if ($item.Change.IssueNumber -ge 0) { $item.Change.IssueNumber } else { $null } + $link = if ($item.PRLink) { $item.PRLink } else { $org = $item.Change.Commit.Organization; "https://github.com/$org/$project" } + $thanks = $item.Thanks + + [void]$sb.Append("- [$project") + if ($issueNumber) + { + [void]$sb.Append(" #$issueNumber") + } + [void]$sb.AppendLine("]($link) -") + + [void]$sb.Append($Indent).Append($item.Subject) + if ($thanks) + { + [void]$sb.Append(" (Thanks @$thanks!)") + } + [void]$sb.AppendLine() + } + } + + if ($Postamble) + { + [void]$sb.AppendLine($Postamble).AppendLine() + } + + return $sb.ToString() + } +} + + +Export-ModuleMember -Function Get-ChangeInfoFromCommit,New-ChangelogEntry,Skip-IgnoredChanges,New-ChangeLogSection diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index e6f5746a3f..8de654f62b 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -61,6 +61,16 @@ class GitHubPR : GitHubIssue return $this.ClosedIssues } + + [uri]GetHtmlUri() + { + return [uri]"https://github.com/$($this.Organization)/$($this.Repository)/pull/$($this.Number)" + } + + [uri]GetApiUri() + { + return [uri]"https://api.github.com/repos/$($this.Organization)/$($this.Repository)/pulls/$($this.Number)" + } } function GetGitHubHeaders @@ -385,72 +395,90 @@ function Get-GitCommit [Parameter()] [string] - $GitHubToken - ) - - if (-not $Remote) - { - $Remote = 'upstream' - try - { - $null = Exec { git remote get-url $Remote } - } - catch - { - $Remote = 'origin' - } - } + $GitHubToken, - $originDetails = GetHumanishRepositoryDetails -RemoteUrl (Exec { git remote get-url $Remote }) - $organization = $originDetails.Organization - $repository = $originDetails.Repository - - $format = '%H||%P||%aN||%aE||%s' - $commits = Exec { git --no-pager log "$SinceRef..$UntilRef" --format=$format } + [Parameter()] + [string] + $RepositoryPath + ) - $irmParams = if ($GitHubToken) + if ($RepositoryPath) { - @{ Headers = GetGitHubHeaders -GitHubToken $GitHubToken -Accept 'application/vnd.github.v3+json' } + Push-Location $RepositoryPath } - else + try { - @{ Headers = GetGitHubHeaders -Accept 'application/vnd.github.v3+json' } - } - - return $commits | - ForEach-Object { - $hash,$parents,$name,$email,$subject = $_.Split('||') - $body = (Exec { git --no-pager show $hash -s --format=%b }) -join "`n" - $commitVal = [GitHubCommitInfo]@{ - Hash = $hash - ParentHashes = $parents - ContributorName = $name - ContributorEmail = $email - Subject = $subject - Body = $body - Organization = $organization - Repository = $repository - } - - # Query the GitHub API for more commit information - $commitVal.GitHubCommitData = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/$organization/$repository/commits/$hash" @irmParams - - # Look for something like 'This is a commit message (#1224)' - $pr = [regex]::Match($subject, '\(#(\d+)\)$').Groups[1].Value - if ($pr) + if (-not $Remote) + { + $Remote = 'upstream' + try { - $commitVal.PRNumber = $pr + $null = Exec { git remote get-url $Remote } } - - # Look for something like '[Ignore] [giraffe] Fix tests' - $commitLabels = [regex]::Matches($subject, '^(\[(.*?)\]\s*)*') - if ($commitLabels.Groups.Length -ge 3 -and $commitLabels.Groups[2].Captures.Value) + catch { - $commitVal.CommitLabels = $commitLabels.Groups[2].Captures.Value + $Remote = 'origin' } + } - $commitVal + $originDetails = GetHumanishRepositoryDetails -RemoteUrl (Exec { git remote get-url $Remote }) + $organization = $originDetails.Organization + $repository = $originDetails.Repository + + $format = '%H||%P||%aN||%aE||%s' + $commits = Exec { git --no-pager log "$SinceRef..$UntilRef" --format=$format } + + $irmParams = if ($GitHubToken) + { + @{ Headers = GetGitHubHeaders -GitHubToken $GitHubToken -Accept 'application/vnd.github.v3+json' } } + else + { + @{ Headers = GetGitHubHeaders -Accept 'application/vnd.github.v3+json' } + } + + return $commits | + ForEach-Object { + $hash,$parents,$name,$email,$subject = $_.Split('||') + $body = (Exec { git --no-pager show $hash -s --format=%b }) -join "`n" + $commitVal = [GitHubCommitInfo]@{ + Hash = $hash + ParentHashes = $parents + ContributorName = $name + ContributorEmail = $email + Subject = $subject + Body = $body + Organization = $organization + Repository = $repository + } + + # Query the GitHub API for more commit information + $commitVal.GitHubCommitData = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/$organization/$repository/commits/$hash" @irmParams + + # Look for something like 'This is a commit message (#1224)' + $pr = [regex]::Match($subject, '\(#(\d+)\)$').Groups[1].Value + if ($pr) + { + $commitVal.PRNumber = $pr + } + + # Look for something like '[Ignore] [giraffe] Fix tests' + $commitLabels = [regex]::Matches($subject, '^(\[(.*?)\]\s*)*') + if ($commitLabels.Groups.Length -ge 3 -and $commitLabels.Groups[2].Captures.Value) + { + $commitVal.CommitLabels = $commitLabels.Groups[2].Captures.Value + } + + $commitVal + } + } + finally + { + if ($RepositoryPath) + { + Pop-Location + } + } } function New-GitHubPR diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 5eb6885319..177fc21697 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -3,14 +3,18 @@ #requires -Version 6.0 -using module ../ChangelogTools.psm1 -using module ../GitHubTools.psm1 +using module ..\GitHubTools.psm1 +using module ..\ChangelogTools.psm1 param( [Parameter(Mandatory)] [string] $GitHubToken, + [Parameter(Mandatory)] + [string] + $ReleaseName, + [Parameter(Mandatory)] [string] $SinceRef, @@ -21,35 +25,80 @@ param( [Parameter()] [string] - $RepositoryLocation = (Resolve-Path "$PSScriptRoot/../../") + $Organization = 'PowerShell', + + [Parameter()] + [string] + $Repository = 'vscode-powershell', + + [Parameter()] + [string] + $TargetFork = $Organization, + + [Parameter()] + [string] + $FromForm = 'rjmholt', + + [Parameter()] + [string] + $Preamble = "#### [$Repository](https://github.com/$Organization/$Repository)", + + [Parameter()] + [string] + $Postamble, + + [Parameter()] + [string] + $RepositoryPath ) -class ChangelogEntry -{ - [uri]$IssueLink - [uri]$PRLink - [string]$Category - [string[]]$Tags - [string]$Text - [string]$Thanks - [ChangelogItem]$CLItem -} +$dateFormat = 'dddd, MMMM dd yyyy' -class ChangeLog -{ - ChangeLog() - { - $this.Sections = [System.Collections.Generic.Dictionary[string, ChangelogEntry]]::new() +$ignore = @{ + Users = 'dependabot[bot]' + Labels = @{ + Commit = 'Ignore' } +} - [string]$ReleaseName - [datetime]$Date - [string]$Preamble - [System.Collections.Generic.Dictionary[string, ChangelogEntry]]$Sections +$categories = [ordered]@{ + Debugging = @{ + Issue = 'Area-Debugging' + } + CodeLens = @{ + Issue = 'Area-CodeLens' + } + 'Script Analysis' = @{ + Issue = 'Area-Script Analysis' + } + Formatting = @{ + Issue = 'Area-Formatting' + } + 'Integrated Console' = @{ + Issue = 'Area-Integrated Console','Area-PSReadLine' + } + Intellisense = @{ + Issue = 'Area-Intellisense' + } + General = @{ + Issue = 'Area-General' + } } -$script:ChangelogConfig = @{ - DateFormat = 'dddd, dd MMMM yyyy' +$defaultCategory = 'General' + +$clEntryParams = @{ + Organization = $Organization + Repository = $Repository + EntryCategories = $categories + DefaultCategory = @{ + Name = $defaultCategory + Issue = $categories[$defaultCategory].Issue + } + TagLabels = @{ + 'Issue-Enhancement' = 'Feature' + 'Issue-Bug' = 'BugFix' + } NoThanks = @( 'rjmholt' 'TylerLeonhardt' @@ -57,140 +106,44 @@ $script:ChangelogConfig = @{ 'SteveL-MSFT' 'PaulHigin' ) - Ignore = @{ - Users = 'dependabot[bot]' - Labels = @{ - Commit = 'Ignore' - } - } - TagLabels = @{ - 'Issue-Enhancement' = 'Feature' - 'Issue-Bug' = 'BugFix' - } - ChangeCategories = @{ - Default = @{ - Name = 'General' - Issue = 'Area-General' - } - Categories = [ordered]@{ - Debugging = @{ - Issue = 'Area-Debugging' - } - CodeLens = @{ - Issue = 'Area-CodeLens' - } - 'Script Analysis' = @{ - Issue = 'Area-Script Analysis' - } - Formatting = @{ - Issue = 'Area-Formatting' - } - 'Integrated Console' = @{ - Issue = 'Area-Integrated Console','Area-PSReadLine' - } - 'Intellisense' = @{ - Issue = 'Area-Intellisense' - } - } - } } -filter FilterIgnoredCommits -{ - param( - [Parameter(Mandatory, ValueFromPipeline)] - [ChangelogItem] - $CLItem, - - [Parameter] - [string[]] - $IgnoreUser, - - [Parameter()] - [string[]] - $IgnoreCommitLabel - ) - - if ($CLItem.ContributingUser -in $IgnoreUser) - { - return - } - - foreach ($commitLabel in $CLItem.Commit.CommitLabels) - { - if ($commitLabel -in $IgnoreCommitLabel) - { - return - } - } - - return $CLItem +$clSectionParams = @{ + Categories = $categories.Keys + DefaultCategory = $defaultCategory + ReleaseName = $ReleaseName + Preamble = $Preamble + Postamble = $Postamble + DateFormat = $dateFormat } -filter AssembleCLEntry -{ - param( - [Parameter(Mandatory, ValueFromPipeline)] - [ChangelogItem] - $CLItem, - - [Parameter()] - [string] - $Organization = 'PowerShell', +$newChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $RepositoryPath | + Get-ChangeInfoFromCommit -GitHubToken $GitHubToken | + Skip-IgnoredChanges -IgnoreUser $ignore.Users -IgnoreCommitLabel $ignore.Labels.Commit | + New-ChangelogEntry @clEntryParams | + New-ChangelogSection @clSectionParams - [Parameter()] - [string] - $Repository = 'vscode-powershell' - ) +$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${Repository}_changelogupdate" +$branchName = "changelog-$ReleaseName" - [string[]]$tags = @() - :labelLoop foreach ($issueLabel in $CLItem.ClosedIssues.Labels) - { - if (-not $entryCategory) - { - foreach ($category in $script:ChangelogConfig.ChangeCategories.Categories.GetEnumerator()) - { - if ($issueLabel -in $category.Value.Issue) - { - $entryCategory = $category.Key - continue :labelLoop - } - } - } - - $tag = $script:ChangelogConfig.TagLabels[$issueLabel] - if ($tag) - { - $tags += $tag - } - } - - if (-not $entryCategory) - { - $entryCategory = $script:ChangelogConfig.ChangeCategories.Default.Name - } - - return [ChangelogEntry]@{ - IssueLink = if ($CLItem.IssueNumber -ge 0) { "https://github.com/$Organization/$Repository/issues/$($CLItem.IssueNumber)" } - PRLink = if ($CLItem.PRNumber -ge 0) { "https://github.com/$Organization/$Repository/$($CLItem.PRNumber)" } - Thanks = if ($CLItem.ContributingUser -notin $script:NoThanks) { $CLItem.ContributingUser } - Category = $entryCategory - Tags = $tags - CLItem = $CLItem - } +$cloneParams = @{ + OriginRemote = "https://github.com/$TargetFork/$Repository" + Destination = $repoLocation + CheckoutBranch = $branchName + Clobber = $true } +Copy-GitRepository @cloneParams -function AssembleCLObject -{ +#UpdateGalleryFile -ExtensionVersion $ExtensionVersion -GalleryFilePath "$repoLocation/$GalleryFileName" -} - -function BuildChangelog -{ +Submit-GitChanges -RepositoryLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update PS extension to v$ExtensionVersion" +$prParams = @{ + Organization = $TargetFork + Repository = $Repository + Branch = $branchName + Title = "Update CHANGELOG for $ReleaseName" + GitHubToken = $GitHubToken + FromOrg = 'rjmholt' } - -$changeLog = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken | - Get-ChangelogItemFromCommit -GitHubToken $GitHubToken | - FilterIgnoredCommits -IgnoreUser $ignore.Users -IgnoreCommitLabel $ignore.Labels.Commit | - AssembleCLEntry \ No newline at end of file +New-GitHubPR @prParams From 382a47e24030fe6c8ff1c9c20d4c757cbc97e06f Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Sat, 18 May 2019 15:51:12 -0700 Subject: [PATCH 31/52] Current --- tools/ChangelogTools.psm1 | 101 ++++++++++++++++++++++++---- tools/GitHubTools.psm1 | 21 +++--- tools/changelog/updateChangelog.ps1 | 33 +++++++-- 3 files changed, 128 insertions(+), 27 deletions(-) diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 index cb02c3ef01..1e5b57d8a0 100644 --- a/tools/ChangelogTools.psm1 +++ b/tools/ChangelogTools.psm1 @@ -5,6 +5,14 @@ using module .\GitHubTools.psm1 +class IgnoreConfiguration +{ + [string[]]$User + [string[]]$IssueLabel + [string[]]$PRLabel + [string[]]$CommitLabel +} + class ChangeInfo { [GitHubCommitInfo]$Commit @@ -180,26 +188,48 @@ filter Skip-IgnoredChanges [Parameter()] [string[]] - $IgnoreUser, + $User, [Parameter()] [string[]] - $IgnoreCommitLabel + $CommitLabel, + + [Parameter()] + [string[]] + $IssueLabel, + + [Parameter()] + [string[]] + $PRLabel ) - if ($Change.ContributingUser -in $IgnoreUser) + if ($Change.ContributingUser -in $User) { return } - foreach ($commitLabel in $Change.Commit.CommitLabels) + foreach ($changeCommitLabel in $Change.Commit.CommitLabels) { - if ($commitLabel -in $IgnoreCommitLabel) + if ($changeCommitLabel -in $CommitLabel) { return } } + foreach ($changeIssueLabel in $Change.Commit.IssueLabels) + { + if ($changeIssueLabel -in $IssueLabel) + { + return + } + } + + foreach ($changePRLabel in $Change.Commit.PRLabels) + { + if () + } + + return $Change } @@ -288,19 +318,40 @@ function New-ChangeLogSection foreach ($item in $category.Value) { - $project= $item.Change.Commit.Repository - $issueNumber = if ($item.Change.IssueNumber -ge 0) { $item.Change.IssueNumber } else { $null } + # Set up the pieces needed for a changelog entry + $project = $item.Change.Commit.Repository $link = if ($item.PRLink) { $item.PRLink } else { $org = $item.Change.Commit.Organization; "https://github.com/$org/$project" } $thanks = $item.Thanks - [void]$sb.Append("- [$project") + $issueNumber = if ($item.Change.IssueNumber -ge 0) + { + $item.Change.IssueNumber + } + elseif ($item.Change.PRNumber -ge 0) + { + $item.Change.PRNumber + } + else + { + $null + } + + # Add the list bullet + [void]$sb.Append('- ') + + # Start with the tags + if ($item.Tags) + { + [void]$sb.Append(($item.Tags -join ' ')).Append(' ') + } + + # Create a header for the change if there is an issue number if ($issueNumber) { - [void]$sb.Append(" #$issueNumber") + [void]$sb.AppendLine("[$project #$issueNumber]($link) -").Append($Indent) } - [void]$sb.AppendLine("]($link) -") - [void]$sb.Append($Indent).Append($item.Subject) + [void]$sb.Append($item.Subject) if ($thanks) { [void]$sb.Append(" (Thanks @$thanks!)") @@ -311,12 +362,38 @@ function New-ChangeLogSection if ($Postamble) { - [void]$sb.AppendLine($Postamble).AppendLine() + [void]$sb.AppendLine().AppendLine($Postamble) } + [void]$sb.AppendLine() + return $sb.ToString() } } +function New-ChangelogRelease +{ + param( + [Parameter(Mandatory)] + [string] + $GitHubToken, + + [Parameter(Mandatory)] + [string] + $RepositoryPath, + + [Parameter(Mandatory)] + [string] + $SinceRef, + + [Parameter()] + [string] + $UntilRef = 'HEAD', + + [Parameter()] + [IgnoreConfiguration] + $Ignore + ) +} Export-ModuleMember -Function Get-ChangeInfoFromCommit,New-ChangelogEntry,Skip-IgnoredChanges,New-ChangeLogSection diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index 8de654f62b..b3063c9dcd 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -295,18 +295,21 @@ function Copy-GitRepository { Exec { git config core.autocrlf true } - foreach ($remote in $Remotes.get_Keys()) + if ($Remotes) { - Exec { git remote add $remote $Remotes[$remote] } - } - - if ($PullUpstream -and $remote['upstream']) - { - Exec { git pull upstream $CloneBranch } + foreach ($remote in $Remotes.get_Keys()) + { + Exec { git remote add $remote $Remotes[$remote] } + } - if ($UpdateOrigin) + if ($PullUpstream -and $Remotes['upstream']) { - Exec { git push origin "+$CloneBranch"} + Exec { git pull upstream $CloneBranch } + + if ($UpdateOrigin) + { + Exec { git push origin "+$CloneBranch"} + } } } diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 177fc21697..b0fc1e9609 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -37,7 +37,11 @@ param( [Parameter()] [string] - $FromForm = 'rjmholt', + $FromFork = 'rjmholt', + + [Parameter()] + [string] + $ChangelogName = 'CHANGELOG.md', [Parameter()] [string] @@ -96,8 +100,8 @@ $clEntryParams = @{ Issue = $categories[$defaultCategory].Issue } TagLabels = @{ - 'Issue-Enhancement' = 'Feature' - 'Issue-Bug' = 'BugFix' + 'Issue-Enhancement' = '✨' + 'Issue-Bug' = '🐛' } NoThanks = @( 'rjmholt' @@ -108,6 +112,23 @@ $clEntryParams = @{ ) } +function UpdateChangelogFile +{ + param( + [Parameter(Mandatory)] + [string] + $NewSection, + + [Parameter(Mandatory)] + [string] + $Path + ) + + $changelogLines = Get-Content -Path $Path + $newContent = ($changelogLines[0..1] -join "`n`n") + $NewSection + ($changelogLines[2..$changelogLines.Length] -join "`n") + Set-Content -Encoding utf8NoBOM -Value $newContent -Path $Path +} + $clSectionParams = @{ Categories = $categories.Keys DefaultCategory = $defaultCategory @@ -134,9 +155,9 @@ $cloneParams = @{ } Copy-GitRepository @cloneParams -#UpdateGalleryFile -ExtensionVersion $ExtensionVersion -GalleryFilePath "$repoLocation/$GalleryFileName" +UpdateChangelogFile -NewSection $newChangelogSection -Path "$repoLocation/$ChangelogName" -Submit-GitChanges -RepositoryLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update PS extension to v$ExtensionVersion" +Submit-GitChanges -RepositoryLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" $prParams = @{ Organization = $TargetFork @@ -144,6 +165,6 @@ $prParams = @{ Branch = $branchName Title = "Update CHANGELOG for $ReleaseName" GitHubToken = $GitHubToken - FromOrg = 'rjmholt' + FromOrg = $FromFork } New-GitHubPR @prParams From 2de74e1dcbe9181a181782e55f20b48adc07f0d6 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Sun, 19 May 2019 15:51:33 -0700 Subject: [PATCH 32/52] Update to open both changelogs --- tools/ChangelogTools.psm1 | 142 +++++++++++-------------- tools/GitHubTools.psm1 | 1 + tools/changelog/updateChangelog.ps1 | 155 ++++++++++++++++++---------- 3 files changed, 161 insertions(+), 137 deletions(-) diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 index 1e5b57d8a0..a8e2e6a17b 100644 --- a/tools/ChangelogTools.psm1 +++ b/tools/ChangelogTools.psm1 @@ -53,6 +53,7 @@ class ChangeLog filter Get-ChangeInfoFromCommit { + [OutputType([ChangeInfo])] param( [Parameter(Mandatory, ValueFromPipeline, Position=0)] [GitHubCommitInfo[]] @@ -99,6 +100,7 @@ filter Get-ChangeInfoFromCommit filter New-ChangelogEntry { + [OutputType([ChangelogEntry])] param( [Parameter(Mandatory, ValueFromPipeline)] [ChangeInfo] @@ -109,7 +111,7 @@ filter New-ChangelogEntry $EntryCategories, [Parameter(Mandatory)] - [hashtable] + [string] $DefaultCategory, [Parameter(Mandatory)] @@ -118,15 +120,7 @@ filter New-ChangelogEntry [Parameter()] [string[]] - $NoThanks = @(), - - [Parameter()] - [string] - $Organization = 'PowerShell', - - [Parameter()] - [string] - $Repository = 'vscode-powershell' + $NoThanks = @() ) [string[]]$tags = @() @@ -153,11 +147,14 @@ filter New-ChangelogEntry if (-not $entryCategory) { - $entryCategory = $DefaultCategory.Name + $entryCategory = $DefaultCategory } - $issueLink = if ($Change.IssueNumber -ge 0) { "https://github.com/$Organization/$Repository/issues/$($Change.IssueNumber)" } else { $null } - $prLink = if ($Change.PRNumber -ge 0) { "https://github.com/$Organization/$Repository/$($Change.PRNumber)" } else { $null } + $organization = $Change.Commit.Organization + $repository = $Change.Commit.Repository + + $issueLink = if ($Change.IssueNumber -ge 0) { $Change.ClosedIssues[0].GetHtmlUri() } else { $null } + $prLink = if ($Change.PRNumber -ge 0) { "https://github.com/$organization/$repository/$($Change.PRNumber)" } else { $null } $thanks = if ($Change.ContributingUser -notin $NoThanks) { $Change.ContributingUser } else { $null } $subject = $Change.Subject @@ -173,68 +170,15 @@ filter New-ChangelogEntry Category = $entryCategory Tags = $tags Change = $Change - RepositoryName = "$Organization/$Repository" + RepositoryName = "$organization/$repository" BodyText = $Change.BodyText Subject = $subject } } -filter Skip-IgnoredChanges -{ - param( - [Parameter(Mandatory, ValueFromPipeline)] - [ChangeInfo] - $Change, - - [Parameter()] - [string[]] - $User, - - [Parameter()] - [string[]] - $CommitLabel, - - [Parameter()] - [string[]] - $IssueLabel, - - [Parameter()] - [string[]] - $PRLabel - ) - - if ($Change.ContributingUser -in $User) - { - return - } - - foreach ($changeCommitLabel in $Change.Commit.CommitLabels) - { - if ($changeCommitLabel -in $CommitLabel) - { - return - } - } - - foreach ($changeIssueLabel in $Change.Commit.IssueLabels) - { - if ($changeIssueLabel -in $IssueLabel) - { - return - } - } - - foreach ($changePRLabel in $Change.Commit.PRLabels) - { - if () - } - - - return $Change -} - function New-ChangeLogSection { + [OutputType([string])] param( [Parameter(Mandatory, ValueFromPipeline)] [ChangelogEntry[]] @@ -371,29 +315,65 @@ function New-ChangeLogSection } } -function New-ChangelogRelease +filter Skip-IgnoredChange { param( - [Parameter(Mandatory)] - [string] - $GitHubToken, + [Parameter(Mandatory, ValueFromPipeline)] + [ChangeInfo[]] + $Change, - [Parameter(Mandatory)] + [Parameter()] [string] - $RepositoryPath, + $User, - [Parameter(Mandatory)] + [Parameter()] [string] - $SinceRef, + $CommitLabel, [Parameter()] - [string] - $UntilRef = 'HEAD', + [string[]] + $IssueLabel, [Parameter()] - [IgnoreConfiguration] - $Ignore + [string[]] + $PRLabel ) + + :outer foreach ($chg in $Change) + { + if ($chg.ContributingUser -in $User) + { + continue + } + + foreach ($chgCommitLabel in $chg.Commit.CommitLabels) + { + if ($chgCommitLabel -in $CommitLabel) + { + continue :outer + } + } + + foreach ($chgIssueLabel in $chg.ClosedIssues.Labels) + { + if ($chgIssueLabel -in $IssueLabel) + { + continue :outer + } + } + + foreach ($chgPRLabel in $chg.PR.Labels) + { + if ($chgPRLabel -in $PRLabel) + { + continue :outer + } + } + + # Yield the change + $chg + } } -Export-ModuleMember -Function Get-ChangeInfoFromCommit,New-ChangelogEntry,Skip-IgnoredChanges,New-ChangeLogSection + +Export-ModuleMember -Function Get-ChangeInfoFromCommit,New-ChangelogEntry,New-ChangelogSection,Skip-IgnoredChange diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index b3063c9dcd..c099cfe47f 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -380,6 +380,7 @@ function Submit-GitChanges function Get-GitCommit { + [OutputType([GitHubCommitInfo])] [CmdletBinding(DefaultParameterSetName='SinceRef')] param( [Parameter(Mandatory, ParameterSetName='SinceRef')] diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index b0fc1e9609..9754560818 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -27,10 +27,6 @@ param( [string] $Organization = 'PowerShell', - [Parameter()] - [string] - $Repository = 'vscode-powershell', - [Parameter()] [string] $TargetFork = $Organization, @@ -45,26 +41,50 @@ param( [Parameter()] [string] - $Preamble = "#### [$Repository](https://github.com/$Organization/$Repository)", - - [Parameter()] - [string] - $Postamble, + $PSExtensionRepositoryPath = (Resolve-Path "$PSScriptRoot/../../"), [Parameter()] [string] - $RepositoryPath + $PsesRepositoryPath = (Resolve-Path "$PSExtensionRepositoryPath/../PowerShellEditorServices") ) +function UpdateChangelogFile +{ + param( + [Parameter(Mandatory)] + [string] + $NewSection, + + [Parameter(Mandatory)] + [string] + $Path + ) + + $changelogLines = Get-Content -Path $Path + $newContent = ($changelogLines[0..1] -join "`n`n") + $NewSection + ($changelogLines[2..$changelogLines.Length] -join "`n") + Set-Content -Encoding utf8NoBOM -Value $newContent -Path $Path +} + +#region Configuration + +$vscodeRepoName = 'vscode-PowerShell' +$psesRepoName = 'PowerShellEditorServices' + $dateFormat = 'dddd, MMMM dd yyyy' $ignore = @{ - Users = 'dependabot[bot]' - Labels = @{ - Commit = 'Ignore' - } + User = 'dependabot[bot]' + CommitLabel = 'Ignore' } +$noThanks = @( + 'rjmholt' + 'TylerLeonhardt' + 'daxian-dbw' + 'SteveL-MSFT' + 'PaulHigin' +) + $categories = [ordered]@{ Debugging = @{ Issue = 'Area-Debugging' @@ -91,80 +111,103 @@ $categories = [ordered]@{ $defaultCategory = 'General' +$branchName = "changelog-$ReleaseName" + +#endregion Configuration + +#region PSES Changelog + $clEntryParams = @{ - Organization = $Organization - Repository = $Repository EntryCategories = $categories - DefaultCategory = @{ - Name = $defaultCategory - Issue = $categories[$defaultCategory].Issue - } + DefaultCategory = $defaultCategory TagLabels = @{ 'Issue-Enhancement' = '✨' 'Issue-Bug' = '🐛' } - NoThanks = @( - 'rjmholt' - 'TylerLeonhardt' - 'daxian-dbw' - 'SteveL-MSFT' - 'PaulHigin' - ) -} - -function UpdateChangelogFile -{ - param( - [Parameter(Mandatory)] - [string] - $NewSection, - - [Parameter(Mandatory)] - [string] - $Path - ) - - $changelogLines = Get-Content -Path $Path - $newContent = ($changelogLines[0..1] -join "`n`n") + $NewSection + ($changelogLines[2..$changelogLines.Length] -join "`n") - Set-Content -Encoding utf8NoBOM -Value $newContent -Path $Path + NoThanks = $noThanks } $clSectionParams = @{ Categories = $categories.Keys DefaultCategory = $defaultCategory ReleaseName = $ReleaseName - Preamble = $Preamble - Postamble = $Postamble DateFormat = $dateFormat } -$newChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $RepositoryPath | +$psesChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PsesRepositoryPath | Get-ChangeInfoFromCommit -GitHubToken $GitHubToken | - Skip-IgnoredChanges -IgnoreUser $ignore.Users -IgnoreCommitLabel $ignore.Labels.Commit | + Skip-IgnoredChange @ignore | New-ChangelogEntry @clEntryParams | - New-ChangelogSection @clSectionParams + New-ChangelogSection @clSectionParams -Preamble "#### [$psesRepoName](https://github.com/$Organization/$psesRepoName)" -$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${Repository}_changelogupdate" -$branchName = "changelog-$ReleaseName" +$cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${psesRepoName}_changelogupdate" + +$cloneParams = @{ + OriginRemote = "https://github.com/$TargetFork/$psesRepoName" + Destination = $cloneLocation + CheckoutBranch = $branchName + Clobber = $true +} +Copy-GitRepository @cloneParams + +UpdateChangelogFile -NewSection $psesChangelogSection -Path "$cloneLocation/$ChangelogName" + +Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" + +#endregion + +#region vscode-PowerShell Changelog + +Wait-Debugger + +$psesChangelogPostamble = ($psesChangelogSection -split "`n") +$psesChangelogPostamble = $psesChangelogPostamble[2..$psesChangelogPostamble.Length] +$psesChangelogPostamble = $psesChangelogPostamble -join "`n" + +$psextChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PSExtensionRepositoryPath | + Get-ChangeInfoFromCommit -GitHubToken $GitHubToken | + Skip-IgnoredChange @ignore | + New-ChangelogEntry @clEntryParams | + New-ChangelogSection @clSectionParams -Preamble "#### [$vscodeRepoName](https://github.com/$Organization/$vscodeRepoName)" -Postamble $psesChangelogPostamble + +$cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${vscodeRepoName}_changelogupdate" $cloneParams = @{ - OriginRemote = "https://github.com/$TargetFork/$Repository" - Destination = $repoLocation + OriginRemote = "https://github.com/$TargetFork/$vscodeRepoName" + Destination = $cloneLocation CheckoutBranch = $branchName Clobber = $true } Copy-GitRepository @cloneParams -UpdateChangelogFile -NewSection $newChangelogSection -Path "$repoLocation/$ChangelogName" +UpdateChangelogFile -NewSection $psextChangelogSection -Path "$cloneLocation/$ChangelogName" + +Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" + +#endregion vscode-PowerShell Changelog -Submit-GitChanges -RepositoryLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" +#region PRs +# PSES PR $prParams = @{ Organization = $TargetFork - Repository = $Repository + Repository = $psesRepoName Branch = $branchName Title = "Update CHANGELOG for $ReleaseName" GitHubToken = $GitHubToken FromOrg = $FromFork } New-GitHubPR @prParams + +# vscode-PowerShell PR +$prParams = @{ + Organization = $TargetFork + Repository = $vscodeRepoName + Branch = $branchName + Title = "Update CHANGELOG for $ReleaseName" + GitHubToken = $GitHubToken + FromOrg = $FromFork +} +New-GitHubPR @prParams + +#endregion PRs From 29756e0599b6ed85dd41b63e78b438ac3b13bc0d Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Sun, 19 May 2019 23:09:57 -0700 Subject: [PATCH 33/52] Fix label bug --- tools/ChangelogTools.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 index a8e2e6a17b..a21340d3d5 100644 --- a/tools/ChangelogTools.psm1 +++ b/tools/ChangelogTools.psm1 @@ -350,7 +350,7 @@ filter Skip-IgnoredChange { if ($chgCommitLabel -in $CommitLabel) { - continue :outer + continue outer } } @@ -358,7 +358,7 @@ filter Skip-IgnoredChange { if ($chgIssueLabel -in $IssueLabel) { - continue :outer + continue outer } } @@ -366,7 +366,7 @@ filter Skip-IgnoredChange { if ($chgPRLabel -in $PRLabel) { - continue :outer + continue outer } } From 34c3658354c15cd3af5276375c93d3708b7d1244 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Sun, 19 May 2019 23:41:38 -0700 Subject: [PATCH 34/52] Minor fixes -- but still there --- tools/ChangelogTools.psm1 | 13 +++++-------- tools/GitHubTools.psm1 | 6 +++--- tools/changelog/updateChangelog.ps1 | 2 -- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 index a21340d3d5..2628f527eb 100644 --- a/tools/ChangelogTools.psm1 +++ b/tools/ChangelogTools.psm1 @@ -263,21 +263,18 @@ function New-ChangeLogSection foreach ($item in $category.Value) { # Set up the pieces needed for a changelog entry - $project = $item.Change.Commit.Repository $link = if ($item.PRLink) { $item.PRLink } else { $org = $item.Change.Commit.Organization; "https://github.com/$org/$project" } $thanks = $item.Thanks - $issueNumber = if ($item.Change.IssueNumber -ge 0) + if ($item.Change.IssueNumber -ge 0) { - $item.Change.IssueNumber + $project = $item.Change.ClosedIssues[0].Repository + $issueNumber = $item.Change.IssueNumber } elseif ($item.Change.PRNumber -ge 0) { - $item.Change.PRNumber - } - else - { - $null + $project = $item.PR.Repository + $issueNumber = $item.Change.PRNumber } # Add the list bullet diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index c099cfe47f..ad66d38592 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -634,9 +634,9 @@ filter Get-GitHubIssue $issueResponse = Invoke-RestMethod @irmParams return [GitHubIssue]@{ - Organization = $Organization - Repository = $Repository - Number = $Number + Organization = $IssueInfo.Organization + Repository = $IssueInfo.Repository + Number = $IssueInfo.Number RawResponse = $issueResponse Body = $issueResponse.body Labels = $issueResponse.labels.name diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 9754560818..9c0afa721c 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -158,8 +158,6 @@ Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Bra #region vscode-PowerShell Changelog -Wait-Debugger - $psesChangelogPostamble = ($psesChangelogSection -split "`n") $psesChangelogPostamble = $psesChangelogPostamble[2..$psesChangelogPostamble.Length] $psesChangelogPostamble = $psesChangelogPostamble -join "`n" From 86737870d2fd7d86a8d22d47176ccbea908f4b7c Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 20 May 2019 09:01:08 -0700 Subject: [PATCH 35/52] Fix bad project name assignment --- tools/ChangelogTools.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 index 2628f527eb..0746bcb57e 100644 --- a/tools/ChangelogTools.psm1 +++ b/tools/ChangelogTools.psm1 @@ -273,7 +273,7 @@ function New-ChangeLogSection } elseif ($item.Change.PRNumber -ge 0) { - $project = $item.PR.Repository + $project = $item.Change.PR.Repository $issueNumber = $item.Change.PRNumber } From f7f03cba2703093810127e0dc6b10d6f49511fc0 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 20 May 2019 09:16:45 -0700 Subject: [PATCH 36/52] Fix documentation loss --- tools/postReleaseScripts/publishGHRelease.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/postReleaseScripts/publishGHRelease.ps1 b/tools/postReleaseScripts/publishGHRelease.ps1 index 55ecf24625..db467d3190 100644 --- a/tools/postReleaseScripts/publishGHRelease.ps1 +++ b/tools/postReleaseScripts/publishGHRelease.ps1 @@ -31,6 +31,14 @@ 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 +48,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]) From caa3bb4f43dc405866426bafd993021ac0bb36a0 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 21 May 2019 14:36:31 -0700 Subject: [PATCH 37/52] Fix bugs --- tools/ChangelogTools.psm1 | 3 +-- tools/changelog/updateChangelog.ps1 | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 index 0746bcb57e..a3e5814576 100644 --- a/tools/ChangelogTools.psm1 +++ b/tools/ChangelogTools.psm1 @@ -154,7 +154,7 @@ filter New-ChangelogEntry $repository = $Change.Commit.Repository $issueLink = if ($Change.IssueNumber -ge 0) { $Change.ClosedIssues[0].GetHtmlUri() } else { $null } - $prLink = if ($Change.PRNumber -ge 0) { "https://github.com/$organization/$repository/$($Change.PRNumber)" } else { $null } + $prLink = if ($Change.PRNumber -ge 0) { "https://github.com/$organization/$repository/pull/$($Change.PRNumber)" } else { $null } $thanks = if ($Change.ContributingUser -notin $NoThanks) { $Change.ContributingUser } else { $null } $subject = $Change.Subject @@ -372,5 +372,4 @@ filter Skip-IgnoredChange } } - Export-ModuleMember -Function Get-ChangeInfoFromCommit,New-ChangelogEntry,New-ChangelogSection,Skip-IgnoredChange diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 9c0afa721c..de26ae73d3 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -138,7 +138,7 @@ $psesChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -G Get-ChangeInfoFromCommit -GitHubToken $GitHubToken | Skip-IgnoredChange @ignore | New-ChangelogEntry @clEntryParams | - New-ChangelogSection @clSectionParams -Preamble "#### [$psesRepoName](https://github.com/$Organization/$psesRepoName)" + New-ChangelogSection @clSectionParams $cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${psesRepoName}_changelogupdate" @@ -157,9 +157,8 @@ Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Bra #endregion #region vscode-PowerShell Changelog - -$psesChangelogPostamble = ($psesChangelogSection -split "`n") -$psesChangelogPostamble = $psesChangelogPostamble[2..$psesChangelogPostamble.Length] +$psesChangelogPostamble = $psesChangelogSection -split "`n" +$psesChangelogPostamble = @("#### [$psesRepoName](https://github.com/$Organization/$psesRepoName)") + $psesChangelogPostamble[2..$psesChangelogPostamble.Length-1] $psesChangelogPostamble = $psesChangelogPostamble -join "`n" $psextChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PSExtensionRepositoryPath | From 6a676e4c6eec58f97e13f38dfbe7c47019199d40 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 21 May 2019 17:02:39 -0700 Subject: [PATCH 38/52] Add verbosity, fix whitespace bugs --- tools/ChangelogTools.psm1 | 10 +++++ tools/GitHubTools.psm1 | 70 ++++++++++++++++++----------- tools/changelog/updateChangelog.ps1 | 45 ++++++++++++------- 3 files changed, 83 insertions(+), 42 deletions(-) diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 index a3e5814576..839af2031f 100644 --- a/tools/ChangelogTools.psm1 +++ b/tools/ChangelogTools.psm1 @@ -66,6 +66,8 @@ filter Get-ChangeInfoFromCommit foreach ($singleCommit in $Commit) { + Write-Verbose "Getting change information for commit $($Commit.Hash)" + $changelogItem = [ChangeInfo]@{ Commit = $singleCommit BodyText = $singleCommit.Body @@ -163,6 +165,8 @@ filter New-ChangelogEntry $subject = $Matches[1] } + Write-Verbose "Assembled changelog entry for commit $($Change.Commit.Hash)" + return [ChangelogEntry]@{ IssueLink = $issueLink PRLink = $prLink @@ -338,8 +342,11 @@ filter Skip-IgnoredChange :outer foreach ($chg in $Change) { + $msg = $chg.Subject if ($chg.ContributingUser -in $User) { + $u = $chg.ContributingUser + Write-Verbose "Skipping change from user '$u': '$msg'" continue } @@ -347,6 +354,7 @@ filter Skip-IgnoredChange { if ($chgCommitLabel -in $CommitLabel) { + Write-Verbose "Skipping change with commit label '$chgCommitLabel': '$msg'" continue outer } } @@ -355,6 +363,7 @@ filter Skip-IgnoredChange { if ($chgIssueLabel -in $IssueLabel) { + Write-Verbose "Skipping change with issue label '$chgIssueLabel': '$msg'" continue outer } } @@ -363,6 +372,7 @@ filter Skip-IgnoredChange { if ($chgPRLabel -in $PRLabel) { + Write-Verbose "Skipping change with PR label '$chgPRLabel': '$msg'" continue outer } } diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index ad66d38592..cd416f11b7 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -288,6 +288,8 @@ function Copy-GitRepository New-Item -Path $containingDir -ItemType Directory -ErrorAction Stop } + Write-Verbose "Cloning git repository '$OriginRemote' to path '$Destination'" + Exec { git clone --single-branch --branch $CloneBranch $OriginRemote $Destination } Push-Location $Destination @@ -335,9 +337,9 @@ function Submit-GitChanges [string] $Branch, - [Parameter(Mandatory)] + [Parameter()] [string] - $RepositoryLocation, + $RepositoryLocation = (Get-Location), [Parameter()] [string[]] @@ -369,6 +371,9 @@ function Submit-GitChanges { Exec { git add -A } } + + Write-Verbose "Commiting and pushing changes in '$RepositoryLocation' to '$Remote/$Branch'" + Exec { git commit -m $Message } Exec { git push $Remote $Branch } } @@ -429,6 +434,8 @@ function Get-GitCommit $organization = $originDetails.Organization $repository = $originDetails.Repository + Write-Verbose "Getting local git commit data" + $format = '%H||%P||%aN||%aE||%s' $commits = Exec { git --no-pager log "$SinceRef..$UntilRef" --format=$format } @@ -457,6 +464,7 @@ function Get-GitCommit } # Query the GitHub API for more commit information + Write-Verbose "Querying GitHub api for data on commit $hash" $commitVal.GitHubCommitData = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/$organization/$repository/commits/$hash" @irmParams # Look for something like 'This is a commit message (#1224)' @@ -537,6 +545,7 @@ function New-GitHubPR $headers = GetGitHubHeaders -GitHubToken $GitHubToken -Accept 'application/vnd.github.v3+json' + Write-Verbose "Opening new GitHub pull request on '$Organization/$Repository' with title '$Title'" Invoke-RestMethod -Method Post -Uri $uri -Body $body -Headers $headers } @@ -573,6 +582,8 @@ function Get-GitHubPR $params.Headers = GetGitHubHeaders -GitHubToken $GitHubToken } + Write-Verbose "Retrieving GitHub pull request #$_" + $prResponse = Invoke-RestMethod @params [GitHubPR]@{ @@ -591,7 +602,7 @@ filter Get-GitHubIssue [CmdletBinding(DefaultParameterSetName='IssueInfo')] param( [Parameter(Mandatory, ValueFromPipeline, Position=0, ParameterSetName='IssueInfo')] - [GitHubIssueInfo] + [GitHubIssueInfo[]] $IssueInfo, [Parameter(Mandatory, ParameterSetName='Params')] @@ -612,34 +623,38 @@ filter Get-GitHubIssue $GitHubToken ) - if (-not $IssueInfo) + foreach ($issue in $IssueInfo) { - $IssueInfo = [GitHubIssueInfo]@{ - Organization = $Organization - Repository = $Repository - Number = $Number + if (-not $issue) + { + $issue = [GitHubIssueInfo]@{ + Organization = $Organization + Repository = $Repository + Number = $Number + } } - } - $irmParams = @{ - Method = 'Get' - Uri = $IssueInfo.GetApiUri() - } + $irmParams = @{ + Method = 'Get' + Uri = $IssueInfo.GetApiUri() + } - if ($GitHubToken) - { - $irmParams.Headers = GetGitHubHeaders -GitHubToken $GitHubToken - } + if ($GitHubToken) + { + $irmParams.Headers = GetGitHubHeaders -GitHubToken $GitHubToken + } - $issueResponse = Invoke-RestMethod @irmParams + Write-Verbose "Retrieving GitHub issue #$($issue.Number)" + $issueResponse = Invoke-RestMethod @irmParams - return [GitHubIssue]@{ - Organization = $IssueInfo.Organization - Repository = $IssueInfo.Repository - Number = $IssueInfo.Number - RawResponse = $issueResponse - Body = $issueResponse.body - Labels = $issueResponse.labels.name + return [GitHubIssue]@{ + Organization = $issue.Organization + Repository = $issue.Repository + Number = $issue.Number + RawResponse = $issueResponse + Body = $issueResponse.body + Labels = $issueResponse.labels.name + } } } @@ -703,6 +718,8 @@ function Publish-GitHubRelease $uri = "https://api.github.com/repos/$Organization/$Repository/releases" $headers = GetGitHubHeaders -GitHubToken $GitHubToken -Accept 'application/vnd.github.v3+json' + Write-Verbose "Publishing GitHub release '$ReleaseName' to $Organization/$Repository" + $response = Invoke-RestMethod -Method Post -Uri $uri -Body $restBody -Headers $headers $releaseId = $response.id @@ -729,6 +746,9 @@ function Publish-GitHubRelease $assetUri = "${assetBaseUri}?name=$fileName" $headers = GetGitHubHeaders -GitHubToken $GitHubToken + + Write-Verbose "Uploading release asset '$fileName' to release '$ReleaseName' in $Organization/$Repository" + # This can be very slow, but it does work $null = Invoke-RestMethod -Method Post -Uri $assetUri -InFile $asset -ContentType $contentType -Headers $headers } diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index de26ae73d3..1c2673cf0a 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -6,6 +6,7 @@ using module ..\GitHubTools.psm1 using module ..\ChangelogTools.psm1 +[CmdletBinding()] param( [Parameter(Mandatory)] [string] @@ -60,6 +61,8 @@ function UpdateChangelogFile $Path ) + Write-Verbose "Writing new changelog section to '$Path'" + $changelogLines = Get-Content -Path $Path $newContent = ($changelogLines[0..1] -join "`n`n") + $NewSection + ($changelogLines[2..$changelogLines.Length] -join "`n") Set-Content -Encoding utf8NoBOM -Value $newContent -Path $Path @@ -67,6 +70,8 @@ function UpdateChangelogFile #region Configuration +Write-Verbose "Configuring settings" + $vscodeRepoName = 'vscode-PowerShell' $psesRepoName = 'PowerShellEditorServices' @@ -134,11 +139,15 @@ $clSectionParams = @{ DateFormat = $dateFormat } -$psesChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PsesRepositoryPath | - Get-ChangeInfoFromCommit -GitHubToken $GitHubToken | - Skip-IgnoredChange @ignore | - New-ChangelogEntry @clEntryParams | - New-ChangelogSection @clSectionParams +Write-Verbose "Creating PSES changelog" + +$psesChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PsesRepositoryPath -Verbose:$VerbosePreference | + Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference | + Skip-IgnoredChange @ignore -Verbose:$VerbosePreference | + New-ChangelogEntry @clEntryParams -Verbose:$VerbosePreference | + New-ChangelogSection @clSectionParams -Verbose:$VerbosePreference + +Write-Host "PSES CHANGELOG:`n`n$psesChangelogSection`n`n" $cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${psesRepoName}_changelogupdate" @@ -148,24 +157,26 @@ $cloneParams = @{ CheckoutBranch = $branchName Clobber = $true } -Copy-GitRepository @cloneParams +Copy-GitRepository @cloneParams -Verbose:$VerbosePreference UpdateChangelogFile -NewSection $psesChangelogSection -Path "$cloneLocation/$ChangelogName" -Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" +Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" -Verbose:$VerbosePreference #endregion #region vscode-PowerShell Changelog $psesChangelogPostamble = $psesChangelogSection -split "`n" -$psesChangelogPostamble = @("#### [$psesRepoName](https://github.com/$Organization/$psesRepoName)") + $psesChangelogPostamble[2..$psesChangelogPostamble.Length-1] +$psesChangelogPostamble = @("#### [$psesRepoName](https://github.com/$Organization/$psesRepoName)") + $psesChangelogPostamble[2..($psesChangelogPostamble.Length-3)] $psesChangelogPostamble = $psesChangelogPostamble -join "`n" -$psextChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PSExtensionRepositoryPath | - Get-ChangeInfoFromCommit -GitHubToken $GitHubToken | - Skip-IgnoredChange @ignore | - New-ChangelogEntry @clEntryParams | - New-ChangelogSection @clSectionParams -Preamble "#### [$vscodeRepoName](https://github.com/$Organization/$vscodeRepoName)" -Postamble $psesChangelogPostamble +$psextChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PSExtensionRepositoryPath -Verbose:$VerbosePreference | + Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference | + Skip-IgnoredChange @ignore -Verbose:$VerbosePreference | + New-ChangelogEntry @clEntryParams -Verbose:$VerbosePreference | + New-ChangelogSection @clSectionParams -Preamble "#### [$vscodeRepoName](https://github.com/$Organization/$vscodeRepoName)" -Postamble $psesChangelogPostamble -Verbose:$VerbosePreference + +Write-Host "vscode-PowerShell CHANGELOG:`n`n$psextChangelogSection`n`n" $cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${vscodeRepoName}_changelogupdate" @@ -175,11 +186,11 @@ $cloneParams = @{ CheckoutBranch = $branchName Clobber = $true } -Copy-GitRepository @cloneParams +Copy-GitRepository @cloneParams -Verbose:$VerbosePreference UpdateChangelogFile -NewSection $psextChangelogSection -Path "$cloneLocation/$ChangelogName" -Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" +Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" -Verbose:$VerbosePreference #endregion vscode-PowerShell Changelog @@ -194,7 +205,7 @@ $prParams = @{ GitHubToken = $GitHubToken FromOrg = $FromFork } -New-GitHubPR @prParams +New-GitHubPR @prParams -Verbose:$VerbosePreference # vscode-PowerShell PR $prParams = @{ @@ -205,6 +216,6 @@ $prParams = @{ GitHubToken = $GitHubToken FromOrg = $FromFork } -New-GitHubPR @prParams +New-GitHubPR @prParams -Verbose:$VerbosePreference #endregion PRs From c9cb4e5e8066de21ccfa88adb6db8e6bfbd68f9c Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 22 May 2019 12:05:18 -0700 Subject: [PATCH 39/52] Fix upstream issues --- tools/changelog/updateChangelog.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 1c2673cf0a..df6d9cd07f 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -49,6 +49,9 @@ param( $PsesRepositoryPath = (Resolve-Path "$PSExtensionRepositoryPath/../PowerShellEditorServices") ) +$PSExtensionRepositoryPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PSExtensionRepositoryPath) +$PsesRepositoryPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PsesRepositoryPath) + function UpdateChangelogFile { param( @@ -152,10 +155,11 @@ Write-Host "PSES CHANGELOG:`n`n$psesChangelogSection`n`n" $cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${psesRepoName}_changelogupdate" $cloneParams = @{ - OriginRemote = "https://github.com/$TargetFork/$psesRepoName" + OriginRemote = "https://github.com/$FromFork/$psesRepoName" Destination = $cloneLocation CheckoutBranch = $branchName Clobber = $true + Remotes = @{ 'upstream' = "https://github.com/$TargetFork/$vscodeRepoName" } } Copy-GitRepository @cloneParams -Verbose:$VerbosePreference @@ -181,10 +185,12 @@ Write-Host "vscode-PowerShell CHANGELOG:`n`n$psextChangelogSection`n`n" $cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${vscodeRepoName}_changelogupdate" $cloneParams = @{ - OriginRemote = "https://github.com/$TargetFork/$vscodeRepoName" + OriginRemote = "https://github.com/$FromFork/$vscodeRepoName" Destination = $cloneLocation CheckoutBranch = $branchName Clobber = $true + Remotes = @{ 'upstream' = "https://github.com/$TargetFork/$vscodeRepoName" } + PullUpstream = $true } Copy-GitRepository @cloneParams -Verbose:$VerbosePreference From 29847a4558f412cbd71ee9ee178d55c528eb5d5e Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 22 May 2019 13:56:47 -0700 Subject: [PATCH 40/52] Add subject polishing, fix date format --- tools/ChangelogTools.psm1 | 18 +++++++++++++++++- tools/changelog/updateChangelog.ps1 | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 index 839af2031f..d6bcadab4f 100644 --- a/tools/ChangelogTools.psm1 +++ b/tools/ChangelogTools.psm1 @@ -51,6 +51,22 @@ class ChangeLog [System.Collections.Generic.Dictionary[string, ChangelogEntry]]$Sections } +function NormalizeSubject +{ + [OutputType([string])] + param( + [Parameter(Mandatory)] + [string] + $Subject + ) + + $Subject = $Subject.Trim() + if ([char]::IsLower($Subject[0])) { $Subject = [char]::ToUpper($Subject[0]) + $Subject.Substring(1) } + if ($Subject[$Subject.Length] -ne '.') { $Subject += '.' } + + return $Subject +} + filter Get-ChangeInfoFromCommit { [OutputType([ChangeInfo])] @@ -296,7 +312,7 @@ function New-ChangeLogSection [void]$sb.AppendLine("[$project #$issueNumber]($link) -").Append($Indent) } - [void]$sb.Append($item.Subject) + [void]$sb.Append((NormalizeSubject -Subject $item.Subject)) if ($thanks) { [void]$sb.Append(" (Thanks @$thanks!)") diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index df6d9cd07f..6451e8b5f7 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -78,7 +78,7 @@ Write-Verbose "Configuring settings" $vscodeRepoName = 'vscode-PowerShell' $psesRepoName = 'PowerShellEditorServices' -$dateFormat = 'dddd, MMMM dd yyyy' +$dateFormat = 'dddd, MMMM dd, yyyy' $ignore = @{ User = 'dependabot[bot]' From 0631794cb3ff657931f7cc3f4140878ff8bd745c Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 22 May 2019 16:24:37 -0700 Subject: [PATCH 41/52] Add auto release name --- tools/changelog/updateChangelog.ps1 | 42 ++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 6451e8b5f7..34268366f5 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -14,11 +14,23 @@ param( [Parameter(Mandatory)] [string] - $ReleaseName, + $SinceRef, - [Parameter(Mandatory)] + [Parameter()] + [version] + $PSExtensionVersion, + + [Parameter()] + [semver] + $PsesVersion, + + [Parameter()] [string] - $SinceRef, + $PSExtensionReleaseName, + + [Parameter()] + [string] + $PsesReleaseName, [Parameter()] [string] @@ -52,6 +64,30 @@ param( $PSExtensionRepositoryPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PSExtensionRepositoryPath) $PsesRepositoryPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PsesRepositoryPath) +if (-not $PSExtensionVersion) +{ + $PSExtensionVersion = (Get-Content -Raw "$PSExtensionRepositoryPath/package.json" | ConvertFrom-Json).version +} + +if (-not $PsesVersion) +{ + $psesProps = [xml](Get-Content -Raw "$PsesRepositoryPath/PowerShellEditorServices.Common.props") + $psesVersionPrefix = $psesProps.Project.PropertyData.VersionPrefix + $psesVersionSuffix = $psesProps.Project.PropertyData.VersionSuffix + + $PsesVersion = [semver]"$psesVersionPrefix-$psesVersionSuffix" +} + +if (-not $PSExtensionReleaseName) +{ + $PSExtensionReleaseName = "v$PSExtensionVersion" +} + +if (-not $PsesReleaseName) +{ + $PsesReleaseName = "v$PsesVersion" +} + function UpdateChangelogFile { param( From 3ac02f8c0bb8f30a863d7ab3d6492717b1cf26e4 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 22 May 2019 16:35:07 -0700 Subject: [PATCH 42/52] Add extension name to PR title --- tools/changelog/updateChangelog.ps1 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 34268366f5..f1c03efa34 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -18,19 +18,19 @@ param( [Parameter()] [version] - $PSExtensionVersion, + $PSExtensionVersion, # Default from package.json [Parameter()] [semver] - $PsesVersion, + $PsesVersion, # Default from PowerShellEditorServices.Common.props [Parameter()] [string] - $PSExtensionReleaseName, + $PSExtensionReleaseName, # Default from $PSExtensionVersion [Parameter()] [string] - $PsesReleaseName, + $PsesReleaseName, # Default from $PsesVersion [Parameter()] [string] @@ -64,9 +64,11 @@ param( $PSExtensionRepositoryPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PSExtensionRepositoryPath) $PsesRepositoryPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PsesRepositoryPath) +$packageJson = Get-Content -Raw "$PSExtensionRepositoryPath/package.json" | ConvertFrom-Json +$extensionName = $packageJson.name if (-not $PSExtensionVersion) { - $PSExtensionVersion = (Get-Content -Raw "$PSExtensionRepositoryPath/package.json" | ConvertFrom-Json).version + $PSExtensionVersion = $packageJson.version } if (-not $PsesVersion) @@ -254,7 +256,7 @@ $prParams = @{ Organization = $TargetFork Repository = $vscodeRepoName Branch = $branchName - Title = "Update CHANGELOG for $ReleaseName" + Title = "Update $extensionName CHANGELOG for $ReleaseName" GitHubToken = $GitHubToken FromOrg = $FromFork } From eba4cb08a277c29c052772478ea718a7a093e467 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Thu, 23 May 2019 16:33:50 -0700 Subject: [PATCH 43/52] Fix release name bug --- tools/changelog/updateChangelog.ps1 | 39 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index f1c03efa34..00b4f09f8c 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -14,7 +14,11 @@ param( [Parameter(Mandatory)] [string] - $SinceRef, + $PSExtensionSinceRef, + + [Parameter(Mandatory)] + [string] + $PsesSinceRef, [Parameter()] [version] @@ -34,7 +38,11 @@ param( [Parameter()] [string] - $UntilRef = 'HEAD', + $PSExtensionUntilRef = 'HEAD', + + [Parameter()] + [string] + $PsesUntilRef = 'HEAD', [Parameter()] [string] @@ -163,6 +171,14 @@ $branchName = "changelog-$ReleaseName" #region PSES Changelog +$psesGetCommitParams = @{ + SinceRef = $PsesSinceRef + UntilRef = $PsesUntilRef + GitHubToken = $GitHubToken + RepositoryPath = $PsesRepositoryPath + Verbose = $VerbosePreference +} + $clEntryParams = @{ EntryCategories = $categories DefaultCategory = $defaultCategory @@ -171,22 +187,23 @@ $clEntryParams = @{ 'Issue-Bug' = '🐛' } NoThanks = $noThanks + Verbose = $VerbosePreference } $clSectionParams = @{ Categories = $categories.Keys DefaultCategory = $defaultCategory - ReleaseName = $ReleaseName DateFormat = $dateFormat + Verbose = $VerbosePreference } Write-Verbose "Creating PSES changelog" -$psesChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PsesRepositoryPath -Verbose:$VerbosePreference | +$psesChangelogSection = Get-GitCommit @psesGetCommitParams | Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference | Skip-IgnoredChange @ignore -Verbose:$VerbosePreference | - New-ChangelogEntry @clEntryParams -Verbose:$VerbosePreference | - New-ChangelogSection @clSectionParams -Verbose:$VerbosePreference + New-ChangelogEntry @clEntryParams | + New-ChangelogSection @clSectionParams -ReleaseName $PsesReleaseName Write-Host "PSES CHANGELOG:`n`n$psesChangelogSection`n`n" @@ -212,7 +229,15 @@ $psesChangelogPostamble = $psesChangelogSection -split "`n" $psesChangelogPostamble = @("#### [$psesRepoName](https://github.com/$Organization/$psesRepoName)") + $psesChangelogPostamble[2..($psesChangelogPostamble.Length-3)] $psesChangelogPostamble = $psesChangelogPostamble -join "`n" -$psextChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PSExtensionRepositoryPath -Verbose:$VerbosePreference | +$psExtGetCommitParams = @{ + SinceRef = $PSExtensionSinceRef + UntilRef = $PSExtensionUntilRef + GitHubToken = $GitHubToken + RepositoryPath = $PSExtensionRepositoryPath + Verbose = $VerbosePreference +} + +$psextChangelogSection = Get-GitCommit @psExtGetCommitParams | Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference | Skip-IgnoredChange @ignore -Verbose:$VerbosePreference | New-ChangelogEntry @clEntryParams -Verbose:$VerbosePreference | From a5a2f353dae1e2c464c8d956c40d5a1b8ed06938 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Thu, 23 May 2019 16:45:03 -0700 Subject: [PATCH 44/52] Update ReleaseName usage --- tools/changelog/updateChangelog.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 00b4f09f8c..723900a44a 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -165,7 +165,7 @@ $categories = [ordered]@{ $defaultCategory = 'General' -$branchName = "changelog-$ReleaseName" +$branchName = "changelog-$PSExtensionReleaseName" #endregion Configuration @@ -270,7 +270,7 @@ $prParams = @{ Organization = $TargetFork Repository = $psesRepoName Branch = $branchName - Title = "Update CHANGELOG for $ReleaseName" + Title = "Update CHANGELOG for $PsesReleaseName" GitHubToken = $GitHubToken FromOrg = $FromFork } @@ -281,7 +281,7 @@ $prParams = @{ Organization = $TargetFork Repository = $vscodeRepoName Branch = $branchName - Title = "Update $extensionName CHANGELOG for $ReleaseName" + Title = "Update $extensionName CHANGELOG for $PSExtensionReleaseName" GitHubToken = $GitHubToken FromOrg = $FromFork } From c5ff0217878a1e6acc4bf3176f142d05d7dd5464 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Thu, 23 May 2019 16:47:19 -0700 Subject: [PATCH 45/52] Fix verbose parameter --- tools/changelog/updateChangelog.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 723900a44a..bd9cb0cfa9 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -241,7 +241,7 @@ $psextChangelogSection = Get-GitCommit @psExtGetCommitParams | Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference | Skip-IgnoredChange @ignore -Verbose:$VerbosePreference | New-ChangelogEntry @clEntryParams -Verbose:$VerbosePreference | - New-ChangelogSection @clSectionParams -Preamble "#### [$vscodeRepoName](https://github.com/$Organization/$vscodeRepoName)" -Postamble $psesChangelogPostamble -Verbose:$VerbosePreference + New-ChangelogSection @clSectionParams -Preamble "#### [$vscodeRepoName](https://github.com/$Organization/$vscodeRepoName)" -Postamble $psesChangelogPostamble Write-Host "vscode-PowerShell CHANGELOG:`n`n$psextChangelogSection`n`n" From 5f9266743eab3ea237c5b447bf654f88cd9765a3 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Thu, 23 May 2019 16:48:30 -0700 Subject: [PATCH 46/52] Fix verbose --- tools/changelog/updateChangelog.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index bd9cb0cfa9..04dd1da9e2 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -240,7 +240,7 @@ $psExtGetCommitParams = @{ $psextChangelogSection = Get-GitCommit @psExtGetCommitParams | Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference | Skip-IgnoredChange @ignore -Verbose:$VerbosePreference | - New-ChangelogEntry @clEntryParams -Verbose:$VerbosePreference | + New-ChangelogEntry @clEntryParams | New-ChangelogSection @clSectionParams -Preamble "#### [$vscodeRepoName](https://github.com/$Organization/$vscodeRepoName)" -Postamble $psesChangelogPostamble Write-Host "vscode-PowerShell CHANGELOG:`n`n$psextChangelogSection`n`n" From 19d95092a4ba8a51e60877dfd892b941e6e08cea Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Thu, 23 May 2019 17:41:56 -0700 Subject: [PATCH 47/52] Fix branch usage --- tools/GitHubTools.psm1 | 7 ++++- tools/changelog/updateChangelog.ps1 | 42 ++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index cd416f11b7..6e450c8f18 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -290,7 +290,12 @@ function Copy-GitRepository Write-Verbose "Cloning git repository '$OriginRemote' to path '$Destination'" - Exec { git clone --single-branch --branch $CloneBranch $OriginRemote $Destination } + if ($CloneBranch) + { + Write-Verbose "Cloned branch: $CloneBranch" + } + + Exec { git clone $OriginRemote --branch $CloneBranch --single-branch $Destination } Push-Location $Destination try diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 04dd1da9e2..e60b71d046 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -6,6 +6,10 @@ using module ..\GitHubTools.psm1 using module ..\ChangelogTools.psm1 +<# +.EXAMPLE +.\updateChangelog.ps1 -GitHubToken $ghTok -PSExtensionSinceRef v2.0.0-preview.3 -PsesSinceRef v2.0.0-preview.3 -PSExtensionVersion 2019.5.0 -PsesVersion 1.12.2 -PSExtensionUntilRef legacy/1.x -PsesUntilRef legacy/1.x -Verbose +#> [CmdletBinding()] param( [Parameter(Mandatory)] @@ -44,6 +48,14 @@ param( [string] $PsesUntilRef = 'HEAD', + [Parameter()] + [string] + $PSExtensionBaseBranch, # Default is master if HEAD, otherwise $PSExtensionSinceRef + + [Parameter()] + [string] + $PsesBaseBranch, # Default is master if HEAD, otherwise $PsesSinceRef + [Parameter()] [string] $Organization = 'PowerShell', @@ -98,6 +110,30 @@ if (-not $PsesReleaseName) $PsesReleaseName = "v$PsesVersion" } +if (-not $PSExtensionBaseBranch) +{ + $PSExtensionBaseBranch = if ($PSExtensionUntilRef -eq 'HEAD') + { + 'master' + } + else + { + $PSExtensionUntilRef + } +} + +if (-not $PsesBaseBranch) +{ + $PsesBaseBranch = if ($PsesUntilRef -eq 'HEAD') + { + 'master' + } + else + { + $PsesUntilRef + } +} + function UpdateChangelogFile { param( @@ -213,6 +249,7 @@ $cloneParams = @{ OriginRemote = "https://github.com/$FromFork/$psesRepoName" Destination = $cloneLocation CheckoutBranch = $branchName + CloneBranch = $PsesBaseBranch Clobber = $true Remotes = @{ 'upstream' = "https://github.com/$TargetFork/$vscodeRepoName" } } @@ -241,7 +278,7 @@ $psextChangelogSection = Get-GitCommit @psExtGetCommitParams | Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference | Skip-IgnoredChange @ignore -Verbose:$VerbosePreference | New-ChangelogEntry @clEntryParams | - New-ChangelogSection @clSectionParams -Preamble "#### [$vscodeRepoName](https://github.com/$Organization/$vscodeRepoName)" -Postamble $psesChangelogPostamble + New-ChangelogSection @clSectionParams -Preamble "#### [$vscodeRepoName](https://github.com/$Organization/$vscodeRepoName)" -Postamble $psesChangelogPostamble -ReleaseName $PSExtensionReleaseName Write-Host "vscode-PowerShell CHANGELOG:`n`n$psextChangelogSection`n`n" @@ -251,6 +288,7 @@ $cloneParams = @{ OriginRemote = "https://github.com/$FromFork/$vscodeRepoName" Destination = $cloneLocation CheckoutBranch = $branchName + CloneBranch = $PSExtensionBaseBranch Clobber = $true Remotes = @{ 'upstream' = "https://github.com/$TargetFork/$vscodeRepoName" } PullUpstream = $true @@ -273,6 +311,7 @@ $prParams = @{ Title = "Update CHANGELOG for $PsesReleaseName" GitHubToken = $GitHubToken FromOrg = $FromFork + TargetBranch = $PsesBaseBranch } New-GitHubPR @prParams -Verbose:$VerbosePreference @@ -284,6 +323,7 @@ $prParams = @{ Title = "Update $extensionName CHANGELOG for $PSExtensionReleaseName" GitHubToken = $GitHubToken FromOrg = $FromFork + TargetBranch = $PSExtensionBaseBranch } New-GitHubPR @prParams -Verbose:$VerbosePreference From 62c70cf612798bc7b5a42e56e3c16ee334d24968 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Fri, 24 May 2019 14:41:48 -0700 Subject: [PATCH 48/52] Updates --- tools/GitHubTools.psm1 | 8 +++- tools/changelog/updateChangelog.ps1 | 59 +++++++++++++++-------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index 6e450c8f18..d322a6a3ce 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -439,10 +439,16 @@ function Get-GitCommit $organization = $originDetails.Organization $repository = $originDetails.Repository + Wait-Debugger + Write-Verbose "Getting local git commit data" + $null = Exec { git fetch --all } + + $lastCommonCommit = Exec { git merge-base $SinceRef $UntilRef } + $format = '%H||%P||%aN||%aE||%s' - $commits = Exec { git --no-pager log "$SinceRef..$UntilRef" --format=$format } + $commits = Exec { git --no-pager log "$lastCommonCommit..$UntilRef" --format=$format } $irmParams = if ($GitHubToken) { diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index e60b71d046..d00ff3ea80 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -243,23 +243,7 @@ $psesChangelogSection = Get-GitCommit @psesGetCommitParams | Write-Host "PSES CHANGELOG:`n`n$psesChangelogSection`n`n" -$cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${psesRepoName}_changelogupdate" - -$cloneParams = @{ - OriginRemote = "https://github.com/$FromFork/$psesRepoName" - Destination = $cloneLocation - CheckoutBranch = $branchName - CloneBranch = $PsesBaseBranch - Clobber = $true - Remotes = @{ 'upstream' = "https://github.com/$TargetFork/$vscodeRepoName" } -} -Copy-GitRepository @cloneParams -Verbose:$VerbosePreference - -UpdateChangelogFile -NewSection $psesChangelogSection -Path "$cloneLocation/$ChangelogName" - -Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" -Verbose:$VerbosePreference - -#endregion +#endregion PSES Changelog #region vscode-PowerShell Changelog $psesChangelogPostamble = $psesChangelogSection -split "`n" @@ -273,7 +257,6 @@ $psExtGetCommitParams = @{ RepositoryPath = $PSExtensionRepositoryPath Verbose = $VerbosePreference } - $psextChangelogSection = Get-GitCommit @psExtGetCommitParams | Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference | Skip-IgnoredChange @ignore -Verbose:$VerbosePreference | @@ -282,28 +265,29 @@ $psextChangelogSection = Get-GitCommit @psExtGetCommitParams | Write-Host "vscode-PowerShell CHANGELOG:`n`n$psextChangelogSection`n`n" -$cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${vscodeRepoName}_changelogupdate" +#endregion vscode-PowerShell Changelog + +#region PRs + +return + +# PSES PR +$cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${psesRepoName}_changelogupdate" $cloneParams = @{ - OriginRemote = "https://github.com/$FromFork/$vscodeRepoName" + OriginRemote = "https://github.com/$FromFork/$psesRepoName" Destination = $cloneLocation CheckoutBranch = $branchName - CloneBranch = $PSExtensionBaseBranch + CloneBranch = $PsesBaseBranch Clobber = $true Remotes = @{ 'upstream' = "https://github.com/$TargetFork/$vscodeRepoName" } - PullUpstream = $true } Copy-GitRepository @cloneParams -Verbose:$VerbosePreference -UpdateChangelogFile -NewSection $psextChangelogSection -Path "$cloneLocation/$ChangelogName" - -Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" -Verbose:$VerbosePreference - -#endregion vscode-PowerShell Changelog +UpdateChangelogFile -NewSection $psesChangelogSection -Path "$cloneLocation/$ChangelogName" -#region PRs +Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $PsesReleaseName" -Verbose:$VerbosePreference -# PSES PR $prParams = @{ Organization = $TargetFork Repository = $psesRepoName @@ -316,6 +300,23 @@ $prParams = @{ New-GitHubPR @prParams -Verbose:$VerbosePreference # vscode-PowerShell PR +$cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${vscodeRepoName}_changelogupdate" + +$cloneParams = @{ + OriginRemote = "https://github.com/$FromFork/$vscodeRepoName" + Destination = $cloneLocation + CheckoutBranch = $branchName + CloneBranch = $PSExtensionBaseBranch + Clobber = $true + Remotes = @{ 'upstream' = "https://github.com/$TargetFork/$vscodeRepoName" } + PullUpstream = $true +} +Copy-GitRepository @cloneParams -Verbose:$VerbosePreference + +UpdateChangelogFile -NewSection $psextChangelogSection -Path "$cloneLocation/$ChangelogName" + +Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $PSExtensionReleaseName" -Verbose:$VerbosePreference + $prParams = @{ Organization = $TargetFork Repository = $vscodeRepoName From f317722e28e3e7ec06a4a7badf15226fe8317610 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Fri, 24 May 2019 14:52:40 -0700 Subject: [PATCH 49/52] Fix silliness --- tools/GitHubTools.psm1 | 2 -- tools/changelog/updateChangelog.ps1 | 2 -- 2 files changed, 4 deletions(-) diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index d322a6a3ce..03ea86b120 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -439,8 +439,6 @@ function Get-GitCommit $organization = $originDetails.Organization $repository = $originDetails.Repository - Wait-Debugger - Write-Verbose "Getting local git commit data" $null = Exec { git fetch --all } diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index d00ff3ea80..59a6196c68 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -269,8 +269,6 @@ Write-Host "vscode-PowerShell CHANGELOG:`n`n$psextChangelogSection`n`n" #region PRs -return - # PSES PR $cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${psesRepoName}_changelogupdate" From 367225627b93cab3067a760a955b5918bdaf22ab Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Fri, 24 May 2019 16:26:04 -0700 Subject: [PATCH 50/52] Add changelog emoji --- tools/changelog/updateChangelog.ps1 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 59a6196c68..2e30d24f94 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -221,6 +221,27 @@ $clEntryParams = @{ TagLabels = @{ 'Issue-Enhancement' = '✨' 'Issue-Bug' = '🐛' + 'Issue-Performance' = '⚡️' + 'Area-Build & Release' = '👷' + 'Area-Code Formatting' = '📝' + 'Area-Configuration' = '🔧' + 'Area-Debugging' = '🔍' + 'Area-Documentation' = '📖' + 'Area-Engine' = '🚂' + 'Area-Folding' = '📚' + 'Area-Integrated Console' = '📟' + 'Area-IntelliSense' = '🧠' + 'Area-Logging' = '💭' + 'Area-Pester' = '🐢' + 'Area-Script Analysis' = '👮‍' + 'Area-Snippets' = '✂️' + 'Area-Startup' = '🛫' + 'Area-Symbols & References' = '🔗' + 'Area-Tasks' = '✅' + 'Area-Test' = '🚨' + 'Area-Threading' = '⏱️' + 'Area-UI' = '📺' + 'Area-Workspaces' = '📁' } NoThanks = $noThanks Verbose = $VerbosePreference From f5e6c8bb78107cad726226250d1ae35f1a99c095 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Fri, 24 May 2019 16:28:23 -0700 Subject: [PATCH 51/52] Update emoji --- tools/changelog/updateChangelog.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 2e30d24f94..460ae40354 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -223,7 +223,7 @@ $clEntryParams = @{ 'Issue-Bug' = '🐛' 'Issue-Performance' = '⚡️' 'Area-Build & Release' = '👷' - 'Area-Code Formatting' = '📝' + 'Area-Code Formatting' = '💎' 'Area-Configuration' = '🔧' 'Area-Debugging' = '🔍' 'Area-Documentation' = '📖' From ac31eb645b1030652ffbbc8e8a77c2adb0a57ad1 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 16 Sep 2019 10:32:40 -0700 Subject: [PATCH 52/52] Address @TylerLeonhardt's feedback --- tools/GitHubTools.psm1 | 4 ++-- tools/changelog/updateChangelog.ps1 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/GitHubTools.psm1 b/tools/GitHubTools.psm1 index 03ea86b120..75db3e5110 100644 --- a/tools/GitHubTools.psm1 +++ b/tools/GitHubTools.psm1 @@ -290,13 +290,13 @@ function Copy-GitRepository Write-Verbose "Cloning git repository '$OriginRemote' to path '$Destination'" + Exec { git clone $OriginRemote --branch $CloneBranch --single-branch $Destination } + if ($CloneBranch) { Write-Verbose "Cloned branch: $CloneBranch" } - Exec { git clone $OriginRemote --branch $CloneBranch --single-branch $Destination } - Push-Location $Destination try { diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 index 460ae40354..daf0fefd9f 100644 --- a/tools/changelog/updateChangelog.ps1 +++ b/tools/changelog/updateChangelog.ps1 @@ -8,7 +8,7 @@ using module ..\ChangelogTools.psm1 <# .EXAMPLE -.\updateChangelog.ps1 -GitHubToken $ghTok -PSExtensionSinceRef v2.0.0-preview.3 -PsesSinceRef v2.0.0-preview.3 -PSExtensionVersion 2019.5.0 -PsesVersion 1.12.2 -PSExtensionUntilRef legacy/1.x -PsesUntilRef legacy/1.x -Verbose +.\updateChangelog.ps1 -GitHubToken $ghTok -PSExtensionSinceRef v2019.5.0 -PsesSinceRef v2.0.0-preview.4 -PSExtensionVersion 2019.9.0 -PsesVersion 2.0.0-preview.5 -PSExtensionUntilRef master -PsesUntilRef master -Verbose #> [CmdletBinding()] param(