"Fossies" - the Fresh Open Source Software Archive

Member "PowerShell-7.2.6/tools/releaseToWinget.ps1" (11 Aug 2022, 4222 Bytes) of package /linux/misc/PowerShell-7.2.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Microsoft PowerShell source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.


    1 # Copyright (c) Microsoft Corporation.
    2 # Licensed under the MIT License.
    3 
    4 param(
    5     [Parameter(Mandatory)]
    6     [semver]
    7     $ReleaseVersion,
    8 
    9     [Parameter()]
   10     [string]
   11     $WingetRepoPath = "$PSScriptRoot/../../winget-pkgs",
   12 
   13     [Parameter()]
   14     [string]
   15     $FromRepository = 'rjmholt',
   16 
   17     [Parameter()]
   18     [string]
   19     $GitHubToken
   20 )
   21 
   22 function GetMsiHash
   23 {
   24     param(
   25         [Parameter(Mandatory)]
   26         [string]
   27         $ReleaseVersion,
   28 
   29         [Parameter(Mandatory)]
   30         $MsiName
   31     )
   32 
   33     $releaseParams = @{
   34         Tag = "v$ReleaseVersion"
   35         OwnerName = 'PowerShell'
   36         RepositoryName = 'PowerShell'
   37     }
   38 
   39     if ($GitHubToken) { $releaseParams.AccessToken = $GitHubToken }
   40 
   41     $releaseDescription = (Get-GitHubRelease @releaseParams).body
   42 
   43     $regex = [regex]::new("powershell-$ReleaseVersion-win-x64.msi.*?([0-9A-F]{64})", 'SingleLine,IgnoreCase')
   44 
   45     return $regex.Match($releaseDescription).Groups[1].Value
   46 }
   47 
   48 function GetThisScriptRepoUrl
   49 {
   50     # Find the root of the repo
   51     $prefix = $PSScriptRoot
   52     while ($prefix)
   53     {
   54         if (Test-Path "$prefix/LICENSE.txt")
   55         {
   56             break
   57         }
   58 
   59         $prefix = Split-Path $prefix
   60     }
   61 
   62     $stem = $PSCommandPath.Substring($prefix.Length + 1).Replace('\', '/')
   63 
   64     return "https://github.com/PowerShell/PowerShell/blob/master/$stem"
   65 }
   66 
   67 function Exec
   68 {
   69     param([scriptblock]$sb)
   70 
   71     & $sb
   72 
   73     if ($LASTEXITCODE -ne 0)
   74     {
   75         throw "Invocation failed for '$sb'. See above errors for details"
   76     }
   77 }
   78 
   79 $ErrorActionPreference = 'Stop'
   80 
   81 $wingetPath = (Resolve-Path $WingetRepoPath).Path
   82 
   83 # Ensure we have git and PowerShellForGitHub installed
   84 Import-Module -Name PowerShellForGitHub
   85 $null = Get-Command git
   86 
   87 # Get the MSI hash from the release body
   88 $msiName = "PowerShell-$ReleaseVersion-win-x64.msi"
   89 $msiHash = GetMsiHash -ReleaseVersion $ReleaseVersion -MsiName $msiName
   90 
   91 $publisherName = 'Microsoft'
   92 
   93 # Create the manifest
   94 $productName = if ($ReleaseVersion.PreReleaseLabel)
   95 {
   96     'PowerShell-Preview'
   97 }
   98 else
   99 {
  100     'PowerShell'
  101 }
  102 
  103 $manifestDir = Join-Path $wingetPath 'manifests' 'm' $publisherName $productName $ReleaseVersion
  104 $manifestPath = Join-Path $manifestDir "$publisherName.$productName.yaml"
  105 
  106 $manifestContent = @"
  107 PackageIdentifier: $publisherName.$productName
  108 PackageVersion: $ReleaseVersion
  109 PackageName: $productName
  110 Publisher: $publisherName
  111 PackageUrl: https://microsoft.com/PowerShell
  112 License: MIT
  113 LicenseUrl: https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt
  114 Moniker: $($productName.ToLower())
  115 ShortDescription: $publisherName.$productName
  116 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.
  117 Tags:
  118 - powershell
  119 - pwsh
  120 Homepage: https://github.com/PowerShell/PowerShell
  121 Installers:
  122 - Architecture: x64
  123   InstallerUrl: https://github.com/PowerShell/PowerShell/releases/download/v$ReleaseVersion/$msiName
  124   InstallerSha256: $msiHash
  125   InstallerType: msi
  126 PackageLocale: en-US
  127 ManifestType: singleton
  128 ManifestVersion: 1.0.0
  129 
  130 "@
  131 
  132 Push-Location $wingetPath
  133 try
  134 {
  135     $branch = "pwsh-$ReleaseVersion"
  136 
  137     Exec { git checkout master }
  138     Exec { git checkout -b $branch }
  139 
  140     New-Item -Path $manifestDir -ItemType Directory
  141     Set-Content -Path $manifestPath -Value $manifestContent -Encoding utf8NoBOM
  142 
  143     Exec { git add $manifestPath }
  144     Exec { git commit -m "Add $productName $ReleaseVersion" }
  145     Exec { git push origin $branch }
  146 
  147     $prParams = @{
  148         Title = "Add $productName $ReleaseVersion"
  149         Body = "This pull request is automatically generated. See $(GetThisScriptRepoUrl)."
  150         Head = $branch
  151         HeadOwner = $FromRepository
  152         Base = 'master'
  153         Owner = 'Microsoft'
  154         RepositoryName = 'winget-pkgs'
  155         MaintainerCanModify = $true
  156     }
  157 
  158     if ($GitHubToken) { $prParams.AccessToken = $GitHubToken }
  159 
  160     New-GitHubPullRequest @prParams
  161 }
  162 finally
  163 {
  164     git checkout master
  165     Pop-Location
  166 }