From df37e8d40c7b3556f8428ce29c53f2882af2ce25 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Fri, 25 Nov 2022 17:19:03 +0100 Subject: [PATCH] feat(release): add chocolatey publishing (#4637) * feat(release): add chocolatey publishing * change variable forwarding --- .github/workflows/release.yml | 15 ++++++ .github/workflows/workflow.yml | 14 +++++ install/windows/choco/chocolateyInstall.ps1 | 22 ++++++++ install/windows/choco/starship.nuspec | 27 ++++++++++ install/windows/choco/update.ps1 | 57 +++++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 install/windows/choco/chocolateyInstall.ps1 create mode 100644 install/windows/choco/starship.nuspec create mode 100644 install/windows/choco/update.ps1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 351d16c7..f404866d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -323,6 +323,21 @@ jobs: iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe ./wingetcreate.exe update Starship.Starship -s -v $version -u $env:URL_64 $env:URL_32 -t ${{ secrets.GH_PAT }} + choco_update: + name: Update Chocolatey Package + runs-on: windows-latest + needs: [release_please, github_build, upload_artifacts] + if: ${{ needs.release_please.outputs.release_created == 'true' }} + steps: + - name: Setup | Checkout + uses: actions/checkout@v3 + - name: Setup | Artifacts + uses: actions/download-artifact@v3 + - run: pwsh ./install/windows/choco/update.ps1 + env: + STARSHIP_VERSION: ${{ needs.release_please.outputs.tag_name }} + PUSH_TOKEN: ${{ secrets.CHOCO_TOKEN }} + merge_crowdin_pr: name: Merge Crowdin PR runs-on: ubuntu-latest diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 2d965a76..23464847 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -227,6 +227,20 @@ jobs: command: wix args: --dbg-build -v --nocapture -I install/windows/main.wxs + - name: Build | Chocolatey Package [Windows] + continue-on-error: true + 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 + # Build package + pwsh ./install/windows/choco/update.ps1 + env: + STARSHIP_VERSION: v1.2.3 + - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 if: github.repository == 'starship/starship' diff --git a/install/windows/choco/chocolateyInstall.ps1 b/install/windows/choco/chocolateyInstall.ps1 new file mode 100644 index 00000000..a20e4deb --- /dev/null +++ b/install/windows/choco/chocolateyInstall.ps1 @@ -0,0 +1,22 @@ +$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 new file mode 100644 index 00000000..ddbb2694 --- /dev/null +++ b/install/windows/choco/starship.nuspec @@ -0,0 +1,27 @@ + + + + starship + Starship + 0.0.0.1 + Starship Contributors + davidkna,saanuregh + The cross-shell prompt for astronauts + + Starship is the minimal, blazing fast, and extremely customizable prompt for any shell! + Shows the information you need, while staying sleek and minimal. + + https://github.com/starship/starship/tree/master/install/windows/choco + https://starship.rs + https://github.com/starship/starship + https://starship.rs/icon.png + powershell prompt starship pwsh + © 2022 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 new file mode 100644 index 00000000..53922855 --- /dev/null +++ b/install/windows/choco/update.ps1 @@ -0,0 +1,57 @@ +#!/usr/bin/env pwsh + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version 3.0 + +if ($null -eq $ENV:STARSHIP_VERSION) { + Write-Host "Version is required" + exit 1 +} + +$version = "$ENV:STARSHIP_VERSION" +$versionNumber = $version.TrimStart("v") + +[xml]$nuspec_file = Get-Content -Path ./install/windows/choco/starship.nuspec +$nuspec_file.package.metadata.version = $versionNumber + +$changelog = (Get-Content -Path ./CHANGELOG.md | Out-String) +$nuspec_file.package.metadata.releaseNotes = $changelog + +$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" + +$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 + +if (!(Test-Path "./tools")) { + 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 + +choco pack ./starship.nuspec + +if ($null -ne $Env:PUSH_TOKEN) { + choco push starship.$versionNumber.nupkg --key $ENV:PUSH_TOKEN +} +else { + Write-Host "No API key provided, skipping push" +}