diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 0f27774f..8894faba 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -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: diff --git a/install/windows/choco/chocolateyInstall.install.ps1 b/install/windows/choco/chocolateyInstall.install.ps1 new file mode 100644 index 00000000..01dfb775 --- /dev/null +++ b/install/windows/choco/chocolateyInstall.install.ps1 @@ -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)'" diff --git a/install/windows/choco/chocolateyInstall.portable.ps1 b/install/windows/choco/chocolateyInstall.portable.ps1 new file mode 100644 index 00000000..21f0d9d5 --- /dev/null +++ b/install/windows/choco/chocolateyInstall.portable.ps1 @@ -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)'" diff --git a/install/windows/choco/chocolateyInstall.ps1 b/install/windows/choco/chocolateyInstall.ps1 deleted file mode 100644 index a20e4deb..00000000 --- a/install/windows/choco/chocolateyInstall.ps1 +++ /dev/null @@ -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)'" diff --git a/install/windows/choco/starship.nuspec b/install/windows/choco/starship.nuspec index ddbb2694..b9473cf8 100644 --- a/install/windows/choco/starship.nuspec +++ b/install/windows/choco/starship.nuspec @@ -16,10 +16,13 @@ https://github.com/starship/starship https://starship.rs/icon.png powershell prompt starship pwsh - © 2022 Starship Contributors + © 2023 Starship Contributors https://github.com/starship/starship/blob/master/LICENSE false + + + diff --git a/install/windows/choco/update.ps1 b/install/windows/choco/update.ps1 index 53922855..66c2862f 100644 --- a/install/windows/choco/update.ps1 +++ b/install/windows/choco/update.ps1 @@ -17,40 +17,77 @@ $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 { - 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 '^\$checksum_x86_64_zip = (.*)') { - "`$checksum_x86_64_zip = '$checksum_x86_64_zip'" - } - elseif ($_ -match '^\$checksum_i686_zip = (.*)') { - "`$checksum_i686_zip = '$checksum_i686_zip'" - } - else { - $_ - } -} | Set-Content ./tools/chocolateyInstall.ps1 - +# Pack the metapackage as-is without install script choco pack ./starship.nuspec -if ($null -ne $Env:PUSH_TOKEN) { - choco push starship.$versionNumber.nupkg --key $ENV:PUSH_TOKEN +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 + + choco pack ./starship.$install_type.nuspec +} + +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 { Write-Host "No API key provided, skipping push"