From 62729e6c31190eda7bac7d278990d641b4378150 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 16 Mar 2021 20:03:49 -0700 Subject: [PATCH 1/9] Add winget release script --- tools/releaseToWinget.ps1 | 146 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 tools/releaseToWinget.ps1 diff --git a/tools/releaseToWinget.ps1 b/tools/releaseToWinget.ps1 new file mode 100644 index 00000000000..4e33fa7fcb4 --- /dev/null +++ b/tools/releaseToWinget.ps1 @@ -0,0 +1,146 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +param( + [Parameter(Mandatory)] + [semver] + $ReleaseVersion, + + [Parameter()] + [string] + $WingetRepoPath = "$PSScriptRoot/../../winget-pkgs", + + [Parameter()] + [string] + $FromRepository = 'rjmholt', + + [Parameter()] + [string] + $GitHubToken +) + +function GetMsiHash +{ + param( + [Parameter(Mandatory)] + [string] + $ReleaseVersion, + + [Parameter(Mandatory)] + $MsiName + ) + + $releaseParams = @{ + Tag = "v$ReleaseVersion" + OwnerName = 'PowerShell' + RepositoryName = 'PowerShell' + } + + if ($GitHubToken) { $releaseParams.AccessToken = $GitHubToken } + + $releaseDescription = (Get-GitHubRelease @releaseParams).body + + $regex = [regex]::new("powershell-$ReleaseVersion-win-x64.msi.*?([0-9A-F]{64})", 'SingleLine,IgnoreCase') + + return $regex.Match($releaseDescription).Groups[1].Value +} + +function GetThisScriptRepoUrl +{ + # Find the root of the repo + $prefix = $PSScriptRoot + while ($prefix) + { + if (Test-Path "$prefix/LICENSE.txt") + { + break + } + + $prefix = Split-Path $prefix + } + + $stem = $PSCommandPath.Substring($prefix.Length + 1).Replace('\', '/') + + return "https://github.com/PowerShell/PowerShell/blob/master/$stem" +} + +$ErrorActionPreference = 'Stop' + +$wingetPath = (Resolve-Path $WingetRepoPath).Path + +# Ensure we have PowerShellForGitHub installed +Import-Module -Name PowerShellForGitHub + +# Get the MSI hash from the release body +$msiName = "PowerShell-$ReleaseVersion-win-x64.msi" +$msiHash = GetMsiHash -ReleaseVersion $ReleaseVersion -MsiName $msiName + +# Create the manifest +$productName = if ($ReleaseVersion.PreReleaseLabel) +{ + "PowerShell-Preview" +} +else +{ + "PowerShell" +} + +$manifestPath = Join-Path $wingetPath "manifests" "Microsoft" $productName "$ReleaseVersion.yaml" + +$manifestContent = @" +Id: Microsoft.$productName +Version: $ReleaseVersion +Name: $productName +Publisher: Microsoft +License: MIT +LicenseUrl: https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt +AppMoniker: $($productName.ToLower()) +Tags: powershell, pwsh +Description: PowerShell is a cross-platform (Windows, Linux, and macOS) automation and configuration tool/framework that works well with your existing tools and is optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. It includes a command-line shell, an associated scripting language and a framework for processing cmdlets. +Homepage: https://github.com/PowerShell/PowerShell +Installers: + - Arch: x64 + Url: https://github.com/PowerShell/PowerShell/releases/download/v$ReleaseVersion/$msiName + Sha256: $msiHash + InstallerType: msi + +"@ + +# Get the path to this script in the PS repo so we can put a link in the PR body +$scriptPath = $MyInvocation.MyCommand.Source + + +Push-Location $wingetPath +try +{ + $branch = "pwsh-$ReleaseVersion" + + git checkout master + git checkout -b $branch + + Set-Content -Path $manifestPath -Value $manifestContent -Encoding utf8NoBOM + + git add $manifestPath + git commit -m "Add $productName $ReleaseVersion" + git push origin $branch + + $prParams = @{ + Title = "Add $productName $ReleaseVersion" + Body = "This pull request is automatically generated. See $(GetThisScriptRepoUrl)." + Head = $branch + HeadOwner = $FromRepository + Base = 'master' + Owner = 'Microsoft' + RepositoryName = 'winget-pkgs' + MaintainerCanModify = $true + } + + if ($GitHubToken) { $prParams.AccessToken = $GitHubToken } + + New-GitHubPullRequest @prParams +} +finally +{ + git checkout master + Pop-Location +} From 30e6e1d77131319d2288770acd0fa848e5e9c9ce Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 16 Mar 2021 20:35:07 -0700 Subject: [PATCH 2/9] Remove redundant newline --- tools/releaseToWinget.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/releaseToWinget.ps1 b/tools/releaseToWinget.ps1 index 4e33fa7fcb4..6c1399e5bad 100644 --- a/tools/releaseToWinget.ps1 +++ b/tools/releaseToWinget.ps1 @@ -109,7 +109,6 @@ Installers: # Get the path to this script in the PS repo so we can put a link in the PR body $scriptPath = $MyInvocation.MyCommand.Source - Push-Location $wingetPath try { From a1830915aab84a3e8f816cdecada6704e1867d63 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 16 Mar 2021 20:45:44 -0700 Subject: [PATCH 3/9] Check for git early --- tools/releaseToWinget.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/releaseToWinget.ps1 b/tools/releaseToWinget.ps1 index 6c1399e5bad..24b3aaf1fff 100644 --- a/tools/releaseToWinget.ps1 +++ b/tools/releaseToWinget.ps1 @@ -68,8 +68,9 @@ $ErrorActionPreference = 'Stop' $wingetPath = (Resolve-Path $WingetRepoPath).Path -# Ensure we have PowerShellForGitHub installed +# Ensure we have git and PowerShellForGitHub installed Import-Module -Name PowerShellForGitHub +$null = Get-Command git # Get the MSI hash from the release body $msiName = "PowerShell-$ReleaseVersion-win-x64.msi" From 867ae4888a9089d25a7be2679699257e6b377a59 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Fri, 2 Apr 2021 12:30:56 -0700 Subject: [PATCH 4/9] Update winget YAML to new format --- tools/releaseToWinget.ps1 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/releaseToWinget.ps1 b/tools/releaseToWinget.ps1 index 24b3aaf1fff..4e8186c0d4c 100644 --- a/tools/releaseToWinget.ps1 +++ b/tools/releaseToWinget.ps1 @@ -89,21 +89,26 @@ else $manifestPath = Join-Path $wingetPath "manifests" "Microsoft" $productName "$ReleaseVersion.yaml" $manifestContent = @" -Id: Microsoft.$productName -Version: $ReleaseVersion -Name: $productName +PackageIdentifier: Microsoft.$productName +PackageVersion: $ReleaseVersion +PackageName: $productName Publisher: Microsoft +PackageUrl: https://microsoft.com/PowerShell License: MIT LicenseUrl: https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt -AppMoniker: $($productName.ToLower()) -Tags: powershell, pwsh +Moniker: $($productName.ToLower()) +ShortDescription: Microsoft.$productName Description: PowerShell is a cross-platform (Windows, Linux, and macOS) automation and configuration tool/framework that works well with your existing tools and is optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. It includes a command-line shell, an associated scripting language and a framework for processing cmdlets. +Tags: powershell, pwsh Homepage: https://github.com/PowerShell/PowerShell Installers: - - Arch: x64 - Url: https://github.com/PowerShell/PowerShell/releases/download/v$ReleaseVersion/$msiName - Sha256: $msiHash + - Architecture: x64 + InstallerUrl: https://github.com/PowerShell/PowerShell/releases/download/v$ReleaseVersion/$msiName + InstallerSha256: $msiHash InstallerType: msi +PackageLocale: en-US +ManifestType: singleton +ManifestVersion: 1.0.0 "@ From a5ec404b650de5b8c9f618097aeb5dfb813e107d Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 14 Apr 2021 19:34:45 -0700 Subject: [PATCH 5/9] Add alphabetized path component --- tools/releaseToWinget.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/releaseToWinget.ps1 b/tools/releaseToWinget.ps1 index 4e8186c0d4c..81a40d8458f 100644 --- a/tools/releaseToWinget.ps1 +++ b/tools/releaseToWinget.ps1 @@ -86,7 +86,7 @@ else "PowerShell" } -$manifestPath = Join-Path $wingetPath "manifests" "Microsoft" $productName "$ReleaseVersion.yaml" +$manifestPath = Join-Path $wingetPath "manifests" "m" "Microsoft" $productName "$ReleaseVersion.yaml" $manifestContent = @" PackageIdentifier: Microsoft.$productName From ca4d363a188eb3496891fd10121b3de85f42f0f1 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 14 Apr 2021 19:42:37 -0700 Subject: [PATCH 6/9] Fix directory structure --- tools/releaseToWinget.ps1 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/releaseToWinget.ps1 b/tools/releaseToWinget.ps1 index 81a40d8458f..6b8c38c4334 100644 --- a/tools/releaseToWinget.ps1 +++ b/tools/releaseToWinget.ps1 @@ -76,28 +76,30 @@ $null = Get-Command git $msiName = "PowerShell-$ReleaseVersion-win-x64.msi" $msiHash = GetMsiHash -ReleaseVersion $ReleaseVersion -MsiName $msiName +$publisherName = 'Microsoft' + # Create the manifest $productName = if ($ReleaseVersion.PreReleaseLabel) { - "PowerShell-Preview" + 'PowerShell-Preview' } else { - "PowerShell" + 'PowerShell' } -$manifestPath = Join-Path $wingetPath "manifests" "m" "Microsoft" $productName "$ReleaseVersion.yaml" +$manifestPath = Join-Path $wingetPath 'manifests' 'm' $publisherName $productName $ReleaseVersion "$publisherName.$productName.yaml" $manifestContent = @" -PackageIdentifier: Microsoft.$productName +PackageIdentifier: $publisherName.$productName PackageVersion: $ReleaseVersion PackageName: $productName -Publisher: Microsoft +Publisher: $publisherName PackageUrl: https://microsoft.com/PowerShell License: MIT LicenseUrl: https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt Moniker: $($productName.ToLower()) -ShortDescription: Microsoft.$productName +ShortDescription: $publisherName.$productName Description: PowerShell is a cross-platform (Windows, Linux, and macOS) automation and configuration tool/framework that works well with your existing tools and is optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. It includes a command-line shell, an associated scripting language and a framework for processing cmdlets. Tags: powershell, pwsh Homepage: https://github.com/PowerShell/PowerShell From a8660857b7a7b4a96e8b1f1053e3119f736fef1b Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 14 Apr 2021 19:45:19 -0700 Subject: [PATCH 7/9] Fix tags --- tools/releaseToWinget.ps1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/releaseToWinget.ps1 b/tools/releaseToWinget.ps1 index 6b8c38c4334..77620cefcd8 100644 --- a/tools/releaseToWinget.ps1 +++ b/tools/releaseToWinget.ps1 @@ -101,13 +101,15 @@ LicenseUrl: https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt Moniker: $($productName.ToLower()) ShortDescription: $publisherName.$productName Description: PowerShell is a cross-platform (Windows, Linux, and macOS) automation and configuration tool/framework that works well with your existing tools and is optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. It includes a command-line shell, an associated scripting language and a framework for processing cmdlets. -Tags: powershell, pwsh +Tags: +- powershell +- pwsh Homepage: https://github.com/PowerShell/PowerShell Installers: - - Architecture: x64 - InstallerUrl: https://github.com/PowerShell/PowerShell/releases/download/v$ReleaseVersion/$msiName - InstallerSha256: $msiHash - InstallerType: msi +- Architecture: x64 +InstallerUrl: https://github.com/PowerShell/PowerShell/releases/download/v$ReleaseVersion/$msiName +InstallerSha256: $msiHash +InstallerType: msi PackageLocale: en-US ManifestType: singleton ManifestVersion: 1.0.0 From c30e1229ddcf28a035100b87f9681c4f64fadf17 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 14 Apr 2021 19:53:18 -0700 Subject: [PATCH 8/9] Ensure git failures stop the script --- tools/releaseToWinget.ps1 | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tools/releaseToWinget.ps1 b/tools/releaseToWinget.ps1 index 77620cefcd8..d5fe3209768 100644 --- a/tools/releaseToWinget.ps1 +++ b/tools/releaseToWinget.ps1 @@ -64,6 +64,18 @@ function GetThisScriptRepoUrl return "https://github.com/PowerShell/PowerShell/blob/master/$stem" } +function Exec +{ + param([scriptblock]$sb) + + & $sb + + if ($LASTEXITCODE -ne 0) + { + throw "Invocation failed for '$sb'. See above errors for details" + } +} + $ErrorActionPreference = 'Stop' $wingetPath = (Resolve-Path $WingetRepoPath).Path @@ -88,7 +100,8 @@ else 'PowerShell' } -$manifestPath = Join-Path $wingetPath 'manifests' 'm' $publisherName $productName $ReleaseVersion "$publisherName.$productName.yaml" +$manifestDir = Join-Path $wingetPath 'manifests' 'm' $publisherName $productName $ReleaseVersion +$manifestPath = Join-Path $manifestDir "$publisherName.$productName.yaml" $manifestContent = @" PackageIdentifier: $publisherName.$productName @@ -124,14 +137,15 @@ try { $branch = "pwsh-$ReleaseVersion" - git checkout master - git checkout -b $branch + Exec { git checkout master } + Exec { git checkout -b $branch } + New-Item -Path $manifestDir -ItemType Directory Set-Content -Path $manifestPath -Value $manifestContent -Encoding utf8NoBOM - git add $manifestPath - git commit -m "Add $productName $ReleaseVersion" - git push origin $branch + Exec { git add $manifestPath } + Exec { git commit -m "Add $productName $ReleaseVersion" } + Exec { git push origin $branch } $prParams = @{ Title = "Add $productName $ReleaseVersion" From 9b1075bf725ae4c605d05b0dd663c10fc7789ecb Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 14 Apr 2021 19:58:20 -0700 Subject: [PATCH 9/9] Fix installer entry --- tools/releaseToWinget.ps1 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tools/releaseToWinget.ps1 b/tools/releaseToWinget.ps1 index d5fe3209768..e3c1af080e3 100644 --- a/tools/releaseToWinget.ps1 +++ b/tools/releaseToWinget.ps1 @@ -120,18 +120,15 @@ Tags: Homepage: https://github.com/PowerShell/PowerShell Installers: - Architecture: x64 -InstallerUrl: https://github.com/PowerShell/PowerShell/releases/download/v$ReleaseVersion/$msiName -InstallerSha256: $msiHash -InstallerType: msi + InstallerUrl: https://github.com/PowerShell/PowerShell/releases/download/v$ReleaseVersion/$msiName + InstallerSha256: $msiHash + InstallerType: msi PackageLocale: en-US ManifestType: singleton ManifestVersion: 1.0.0 "@ -# Get the path to this script in the PS repo so we can put a link in the PR body -$scriptPath = $MyInvocation.MyCommand.Source - Push-Location $wingetPath try {