feat(release): handle chocolatey starship.portable and starship.install pkg publishing (#4723)

Handles starship.install (MSI installer) and starship.portable and makes starship an 
empty meta-package that only depends on starship.install. MSI/installer packages 
seem to be preferred over zip-based installers on chocolatey. Proper virtual packages 
that allow choosing either a portable or install variant aren't implemented in chocolatey yet.
This commit is contained in:
David Knaack 2023-02-28 06:03:32 +01:00 committed by GitHub
parent e51f25572a
commit b55774d3a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 120 additions and 51 deletions

View File

@ -230,10 +230,12 @@ jobs:
if: matrix.os == 'windows-latest' && matrix.rust == 'stable'
run: |
# Setup dummy release artifacts
New-Item -ItemType Directory -Path ./starship-x86_64-pc-windows-msvc
New-Item -ItemType Directory -Path ./starship-i686-pc-windows-msvc
New-Item -ItemType File -Path ./starship-x86_64-pc-windows-msvc/starship-x86_64-pc-windows-msvc.zip
New-Item -ItemType File -Path ./starship-i686-pc-windows-msvc/starship-i686-pc-windows-msvc.zip
foreach ($arch in @("aarch64", "i686", "x86_64")) {
foreach ($ext in @("zip", "msi")) {
New-Item -ItemType Directory -Path ./starship-$arch-pc-windows-msvc.$ext
New-Item -ItemType File -Path ./starship-$arch-pc-windows-msvc.$ext/starship-$arch-pc-windows-msvc.$ext
}
}
# Build package
pwsh ./install/windows/choco/update.ps1
env:

View File

@ -0,0 +1,25 @@
$ErrorActionPreference = 'Stop'
$packageName = $env:ChocolateyPackageName
$url_x86_64_msi = ''
$url_i686_msi = ''
$checksum_x86_64_msi = ''
$checksum_i686_msi = ''
$packageArgs = @{
packageName = $packageName
fileType = 'msi'
url = $url_i686_msi
url64bit = $url_x86_64_msi
checksum = $checksum_i686_msi
checksum64 = $checksum_x86_64_msi
checksumType = 'sha256'
softwareName = 'starship*'
silentArgs = "/qn /norestart /l*v `"$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`""
validExitCodes = @(0, 3010, 1641)
}
Install-ChocolateyPackage @packageArgs
# Add to Profile
Write-Host "Add the following to the end of ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 'Invoke-Expression (&starship init powershell)'"

View File

@ -0,0 +1,24 @@
$ErrorActionPreference = 'Stop'
$packageName = $env:ChocolateyPackageName
$url_x86_64_zip = ''
$url_i686_zip = ''
$checksum_x86_64_zip = ''
$checksum_i686_zip = ''
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$packageArgs = @{
packageName = $packageName
fileType = 'zip'
url = $url_i686_zip
url64bit = $url_x86_64_zip
checksum = $checksum_i686_zip
checksum64 = $checksum_x86_64_zip
checksumType = 'sha256'
unzipLocation = $toolsDir
}
Install-ChocolateyZipPackage @packageArgs
# Add to Profile
Write-Host "Add the following to the end of ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 'Invoke-Expression (&starship init powershell)'"

View File

@ -1,22 +0,0 @@
$ErrorActionPreference = 'Stop'
$packageName = 'starship'
$url_x86_64_zip = ''
$url_i686_zip = ''
$checksum_x86_64_zip = ''
$checksum_i686_zip = ''
$checksumType = 'sha256'
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
Install-ChocolateyZipPackage -PackageName "$packageName" `
-Url "$url_i686_zip" `
-Url64 "$url_x86_64_zip" `
-UnzipLocation "$toolsDir" `
-Checksum "$checksum_i686_zip" `
-Checksum64 "$checksum_x86_64_zip" `
-ChecksumType "$checksumType"
# Add to Profile
Write-Host "Add the following to the end of ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 'Invoke-Expression (&starship init powershell)'"

View File

@ -16,10 +16,13 @@
<projectSourceUrl>https://github.com/starship/starship</projectSourceUrl>
<iconUrl>https://starship.rs/icon.png</iconUrl>
<tags>powershell prompt starship pwsh</tags>
<copyright>© 2022 Starship Contributors</copyright>
<copyright>© 2023 Starship Contributors</copyright>
<licenseUrl>https://github.com/starship/starship/blob/master/LICENSE</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes></releaseNotes>
<dependencies>
<dependency id="chocolatey" version="0.9.9" />
</dependencies>
</metadata>
<files>
<file src="tools\**" target="tools" />

View File

@ -17,39 +17,76 @@ $nuspec_file.package.metadata.version = $versionNumber
$changelog = (Get-Content -Path ./CHANGELOG.md | Out-String)
$nuspec_file.package.metadata.releaseNotes = $changelog
# Create variant nuspec files
$nuspec_file.package.metadata.id = "starship.portable"
$nuspec_file.Save("./starship.portable.nuspec")
$nuspec_file.package.metadata.id = "starship.install"
$nuspec_file.Save("./starship.install.nuspec")
# Have metapackage depend on starship.install
$nuspec_file.package.metadata.id = "starship"
$dep = $nuspec_file.createelement("dependency")
$dep.SetAttribute("id", "starship.install")
$dep.SetAttribute("version", "[$versionNumber]")
$nuspec_file.package.metadata.dependencies.AppendChild($dep)
$nuspec_file.Save("./starship.nuspec")
$url_x86_64_zip = "https://github.com/starship/starship/releases/download/$version/starship-x86_64-pc-windows-msvc.zip"
$url_i686_zip = "https://github.com/starship/starship/releases/download/$version/starship-i686-pc-windows-msvc.zip"
$url_x86_64_msi = "https://github.com/starship/starship/releases/download/$version/starship-x86_64-pc-windows-msvc.msi"
$url_i686_msi = "https://github.com/starship/starship/releases/download/$version/starship-i686-pc-windows-msvc.msi"
$checksum_x86_64_zip = Get-FileHash -Algorithm SHA256 -Path "./starship-x86_64-pc-windows-msvc/starship-x86_64-pc-windows-msvc.zip" | Select-Object -ExpandProperty Hash
$checksum_i686_zip = Get-FileHash -Algorithm SHA256 -Path "./starship-i686-pc-windows-msvc/starship-i686-pc-windows-msvc.zip" | Select-Object -ExpandProperty Hash
$checksum_x86_64_zip = Get-FileHash -Algorithm SHA256 -Path "./starship-x86_64-pc-windows-msvc.zip/starship-x86_64-pc-windows-msvc.zip" | Select-Object -ExpandProperty Hash
$checksum_i686_zip = Get-FileHash -Algorithm SHA256 -Path "./starship-i686-pc-windows-msvc.zip/starship-i686-pc-windows-msvc.zip" | Select-Object -ExpandProperty Hash
$checksum_x86_64_msi = Get-FileHash -Algorithm SHA256 -Path "./starship-x86_64-pc-windows-msvc.msi/starship-x86_64-pc-windows-msvc.msi" | Select-Object -ExpandProperty Hash
$checksum_i686_msi = Get-FileHash -Algorithm SHA256 -Path "./starship-i686-pc-windows-msvc.msi/starship-i686-pc-windows-msvc.msi" | Select-Object -ExpandProperty Hash
if (!(Test-Path "./tools")) {
New-Item -ItemType Directory -Path "./tools"
if (Test-Path "./tools") {
Remove-Item -Path "./tools" -Recurse -Force
}
New-Item -ItemType Directory -Path "./tools"
Get-Content ./install/windows/choco/chocolateyInstall.ps1 | ForEach-Object {
# Pack the metapackage as-is without install script
choco pack ./starship.nuspec
foreach ($install_type in @('portable', 'install')) {
Get-Content ./install/windows/choco/chocolateyInstall.$install_type.ps1 | ForEach-Object {
if ($_ -match '^\$url_x86_64_zip = (.*)') {
"`$url_x86_64_zip = '$url_x86_64_zip'"
}
elseif ($_ -match '^\$url_i686_zip = (.*)') {
"`$url_i686_zip = '$url_i686_zip'"
}
elseif ($_ -match '^\$url_x86_64_msi = (.*)') {
"`$url_x86_64_msi = '$url_x86_64_msi'"
}
elseif ($_ -match '^\$url_i686_msi = (.*)') {
"`$url_i686_msi = '$url_i686_msi'"
}
elseif ($_ -match '^\$checksum_x86_64_zip = (.*)') {
"`$checksum_x86_64_zip = '$checksum_x86_64_zip'"
}
elseif ($_ -match '^\$checksum_i686_zip = (.*)') {
"`$checksum_i686_zip = '$checksum_i686_zip'"
}
elseif ($_ -match '^\$checksum_x86_64_msi = (.*)') {
"`$checksum_x86_64_msi = '$checksum_x86_64_msi'"
}
elseif ($_ -match '^\$checksum_i686_msi = (.*)') {
"`$checksum_i686_msi = '$checksum_i686_msi'"
}
else {
$_
}
} | Set-Content ./tools/chocolateyInstall.ps1
} | Set-Content ./tools/chocolateyInstall.ps1
choco pack ./starship.nuspec
choco pack ./starship.$install_type.nuspec
}
if ($null -ne $Env:PUSH_TOKEN) {
if ($null -ne $ENV:PUSH_TOKEN) {
choco push starship.portable.$versionNumber.nupkg --key $ENV:PUSH_TOKEN
choco push starship.install.$versionNumber.nupkg --key $ENV:PUSH_TOKEN
choco push starship.$versionNumber.nupkg --key $ENV:PUSH_TOKEN
}
else {