From 30f44f46d2dc2242bf2f7aafe632041f77d42a27 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Wed, 19 Oct 2022 12:49:26 +0200 Subject: [PATCH] feat(scoop): use installer instead of raw binaries --- .github/workflows/inno.yml | 12 ++++++++ .github/workflows/scoop.yml | 23 ++++++++-------- packages/scoop/build.ps1 | 37 ++++++++++++------------- packages/scoop/oh-my-posh.json | 50 +++++++++++++++++++++------------- 4 files changed, 71 insertions(+), 51 deletions(-) diff --git a/.github/workflows/inno.yml b/.github/workflows/inno.yml index 09367a83..ca2390a3 100644 --- a/.github/workflows/inno.yml +++ b/.github/workflows/inno.yml @@ -79,4 +79,16 @@ jobs: ref: 'main', inputs: {"version": process.env.GITHUB_REF.replace('refs/tags/v', '')} }) + - name: Notify Scoop Build 🤙 + uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0 + with: + github-token: ${{ secrets.GH_PAT }} + script: | + await github.request('POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches', { + owner: 'jandedobbeleer', + repo: '${{ github.event.repository.name }}', + workflow_id: 'scoop.yml', + ref: 'main', + inputs: {"version": process.env.GITHUB_REF.replace('refs/tags/v', '')} + }) diff --git a/.github/workflows/scoop.yml b/.github/workflows/scoop.yml index f8018964..a9f216fb 100644 --- a/.github/workflows/scoop.yml +++ b/.github/workflows/scoop.yml @@ -1,7 +1,10 @@ name: Scoop on: - release: - types: [published] + workflow_dispatch: + inputs: + version: + description: 'The latest version' + required: true jobs: publish: @@ -34,13 +37,9 @@ jobs: const { repo: { owner, repo }, sha } = context; console.log({ owner, repo, sha }); - for (let file of await fs.readdir('./packages/scoop/dist')) { - console.log('uploading', file); - - await github.rest.repos.uploadReleaseAsset({ - owner, repo, - release_id: ${{ steps.get_release.outputs.id }}, - name: file, - data: await fs.readFile(`./packages/scoop/dist/${file}`) - }); - } + await github.rest.repos.uploadReleaseAsset({ + owner, repo, + release_id: ${{ steps.get_release.outputs.id }}, + name: "oh-my-posh.json", + data: await fs.readFile('./packages/scoop/dist/oh-my-posh.json') + }); diff --git a/packages/scoop/build.ps1 b/packages/scoop/build.ps1 index 73271682..da4922d7 100644 --- a/packages/scoop/build.ps1 +++ b/packages/scoop/build.ps1 @@ -5,29 +5,26 @@ Param $Version ) -New-Item -Path "." -Name "package/bin" -ItemType Directory +function Get-HashForArchitecture { + param ( + [parameter(Mandatory = $true)] + [string] + $Architecture, + [parameter(Mandatory = $true)] + [string] + $Version + ) + $hash = (new-object Net.WebClient).DownloadString("https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v$Version/install-$Architecture.exe.sha256") + return $hash.Trim() +} + New-Item -Path "." -Name "dist" -ItemType "directory" -Copy-Item -Path "../../themes" -Destination "./package" -Recurse -# Download the files and pack them -@{name = 'posh-windows-amd64.exe'; outName = 'oh-my-posh.exe' } | ForEach-Object -Process { - $download = "https://github.com/jandedobbeleer/oh-my-posh/releases/download/v$Version/$($_.name)" - Invoke-WebRequest $download -Out "./package/bin/$($_.outName)" -} +$HashAmd64 = Get-HashForArchitecture -Architecture 'amd64' -Version $Version +$Hash386 = Get-HashForArchitecture -Architecture '386' -Version $Version -$zipDestination = "./dist/posh-windows-amd64.7z" - -$compress = @{ - Path = "./package/*" - CompressionLevel = "Fastest" - DestinationPath = $zipDestination -} -Compress-Archive @compress -$zipHash = Get-FileHash $zipDestination -Algorithm SHA256 $content = Get-Content '.\oh-my-posh.json' -Raw $content = $content.Replace('', $Version) -$content = $content.Replace('', $zipHash.Hash) +$content = $content.Replace('', $HashAmd64) +$content = $content.Replace('', $Hash386) $content | Out-File -Encoding 'UTF8' './dist/oh-my-posh.json' -$zipHash.Hash | Out-File -Encoding 'UTF8' './dist/posh-windows-amd64.7z.sha256' - -Remove-Item ./package/ -Recurse diff --git a/packages/scoop/oh-my-posh.json b/packages/scoop/oh-my-posh.json index f33a601a..f6362f1e 100644 --- a/packages/scoop/oh-my-posh.json +++ b/packages/scoop/oh-my-posh.json @@ -3,34 +3,46 @@ "description": "A prompt theme engine for any shell", "homepage": "https://ohmyposh.dev", "license": { - "identifier": "MIT", - "url": "https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/COPYING" + "identifier": "MIT", + "url": "https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/COPYING" }, "architecture": { - "64bit": { - "url": "https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v/posh-windows-amd64.7z", - "hash": "" - } + "64bit": { + "url": "https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v/install-amd64.exe", + "hash": "" + }, + "32bit": { + "url": "https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v/install-386.exe", + "hash": "" + } }, - "env_add_path": "bin", - "env_set": { - "POSH_THEMES_PATH": "$dir\\themes" + "installer": { + "args": [ + "/CURRENTUSER", + "/VERYSILENT" + ] }, "checkver": { - "github": "https://github.com/JanDeDobbeleer/oh-my-posh" + "github": "https://github.com/JanDeDobbeleer/oh-my-posh" }, "post_install": [ - "Write-Host 'Thanks for installing Oh My Posh.'", - "Write-Host 'Have a look at https://ohmyposh.dev for detailed instructions for your shell.'" + "Write-Host 'Thanks for installing Oh My Posh.'", + "Write-Host 'Have a look at https://ohmyposh.dev for detailed instructions for your shell.'" ], "autoupdate": { - "architecture": { - "64bit": { - "url": "https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v$version/posh-windows-amd64.7z", - "hash": { - "url": "$url.sha256" - } - } + "architecture": { + "64bit": { + "url": "https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v/install-amd64.exe", + "hash": { + "url": "$url.sha256" + } + }, + "32bit": { + "url": "https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v/install-386.exe", + "hash": { + "url": "$url.sha256" + } } + } } }