feat: scoop support

This commit is contained in:
Jan De Dobbeleer 2020-10-27 04:10:22 -07:00
parent 05b0f3be34
commit 0f9ef8b9b6
4 changed files with 203 additions and 1 deletions

View file

@ -55,6 +55,10 @@ jobs:
- os: windows-latest
ARTIFACT: posh-windows-amd64.exe
runs-on: ${{ matrix.os }}
outputs:
hash_linux: ${{ steps.hash.outputs.hash_ubuntu-latest }}
hash_macos: ${{ steps.hash.outputs.hash_macos-latest }}
hash_windows: ${{ steps.hash.outputs.hash_windows-latest }}
steps:
- name: Install Go
uses: actions/setup-go@v2
@ -67,6 +71,13 @@ jobs:
run: go build -o ${{ matrix.ARTIFACT }}
env:
GOARCH: "amd64"
- name: Hash
id: hash
run: |
hash=${{ hashFiles(matrix.ARTIFACT) }}
echo $hash > ${{ matrix.ARTIFACT }}.sha256
echo "::set-output name=hash_${{ matrix.os }}::${hash}"
shell: bash
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
@ -76,7 +87,17 @@ jobs:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ matrix.ARTIFACT }}
asset_name: ${{ matrix.ARTIFACT }}
asset_content_type: application/octet-stream
asset_content_type: application/octet-stream
- name: Upload Hash Asset
id: upload-hash-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ matrix.ARTIFACT }}.sha256
asset_name: ${{ matrix.ARTIFACT }}.sha256
asset_content_type: text/plain
powershell:
needs: [release, artifacts]
if: ${{ needs.release.outputs.skipped == 'false' }}
@ -92,3 +113,36 @@ jobs:
uses: actions/checkout@v2
- name: Pack and push
run: ./deploy.ps1 -BinVersion ${{ needs.release.outputs.version }} -ModuleVersion ${{ needs.release.outputs.version }} -Repository PSGallery -RepositoryAPIKey $env:PSGALLERY_KEY
scoop:
needs: [release, artifacts]
if: ${{ needs.release.outputs.skipped == 'false' }}
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
working-directory: ${{ github.workspace }}/packages/scoop
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Update Template
run: ./build.ps1 -Version ${{ needs.release.outputs.version }} -LinuxSHA ${{ needs.artifacts.outputs.hash_linux }} -WindowsSHA ${{ needs.artifacts.outputs.hash_windows }}
- name: Upload Scoop JSON
id: upload-scoop-json
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: oh-my-posh.json
asset_name: oh-my-posh.json
asset_content_type: text/plain
- name: Upload Scoop Post Install
id: upload-scoop-post-install
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: post-install.ps1
asset_name: post-install.ps1
asset_content_type: text/plain

20
packages/scoop/build.ps1 Normal file
View file

@ -0,0 +1,20 @@
Param
(
[parameter(Mandatory=$true)]
[string]
$Version,
[parameter(Mandatory=$true)]
[string]
$LinuxSHA,
[parameter(Mandatory=$true)]
[string]
$WindowsSHA
)
$content = Get-Content '.\oh-my-posh.json' -Raw
$content = $content.Replace('<VERSION>', $Version)
$content = $content.Replace('<HASH_LINUX>', $LinuxSHA)
$content = $content.Replace('<HASH_WINDOWS>', $WindowsSHA)
$fileHash = Get-FileHash post-install.ps1 -Algorithm SHA256
$content = $content.Replace('<HASH_INSTALL_SCRIPT>', $fileHash.Hash)
$content | Out-File -Encoding 'UTF8' '.\oh-my-posh.json'

View file

@ -0,0 +1,21 @@
{
"version": "<VERSION>",
"description": "A prompt theme engine for any shell",
"homepage": "https://ohmyposh.dev",
"license": {
"identifier": "GPL-3.0-only",
"url": "https://github.com/JanDeDobbeleer/oh-my-posh3/blob/main/COPYING"
},
"url": [
"https://github.com/JanDeDobbeleer/oh-my-posh3/releases/download/v<VERSION>/posh-linux-amd64",
"https://github.com/JanDeDobbeleer/oh-my-posh3/releases/download/v<VERSION>/posh-windows-amd64.exe",
"https://github.com/JanDeDobbeleer/oh-my-posh3/releases/download/v<VERSION>/post-install.ps1"
],
"hash": [
"<HASH_LINUX>",
"<HASH_WINDOWS>",
"<HASH_INSTALL_SCRIPT>"
],
"bin": ["posh-linux-amd64", "posh-windows-amd64.exe"],
"post_install": "./post-install.ps1"
}

View file

@ -0,0 +1,107 @@
if (!(Test-Path $PROFILE)) {
$profileDir = Split-Path $PROFILE
if (!(Test-Path $profileDir)) {
New-Item -Path $profileDir -ItemType Directory | Out-Null
}
'' > $PROFILE
}
function Write-ExitIfNeeded {
param (
[parameter(Mandatory = $true)]
[int]
$Decision
)
if ($Decision -ne 0) {
Write-Host 'Thanks for installing Oh my Posh.'
Write-Host 'Have a look at https://ohmyposh.dev/docs/installation for instructions.'
exit 0
}
}
function Set-Prompt {
param (
[parameter(Mandatory = $true)]
[string]
$ProfilePath
)
$promptOverride = @'
function Get-PoshCommand {
$poshCommand = "posh-windows-amd64.exe"
if ($IsLinux) {
$poshCommand = "posh-linux-amd64"
}
return $poshCommand
}
[ScriptBlock]$Prompt = {
$realLASTEXITCODE = $global:LASTEXITCODE
if ($realLASTEXITCODE -isnot [int]) {
$realLASTEXITCODE = 0
}
$startInfo = New-Object System.Diagnostics.ProcessStartInfo
$startInfo.FileName = Get-PoshCommand
$startInfo.Arguments = "-pwd ""$PWD"" -error $realLASTEXITCODE"
$startInfo.Environment["TERM"] = "xterm-256color"
$startInfo.CreateNoWindow = $true
$startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
$startInfo.RedirectStandardOutput = $true
$startInfo.UseShellExecute = $false
if ($PWD.Provider.Name -eq "FileSystem") {
$startInfo.WorkingDirectory = "$PWD"
}
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $startInfo
Set-PoshContext
$process.Start() | Out-Null
$standardOut = $process.StandardOutput.ReadToEnd()
$process.WaitForExit()
$standardOut
$global:LASTEXITCODE = $realLASTEXITCODE
Remove-Variable realLASTEXITCODE -Confirm:$false
}
Set-Item -Path Function:prompt -Value $Prompt -Force
'@
Add-Content -Path $ProfilePath -Value $promptOverride
Write-Host 'Thanks for installing Oh my Posh.'
Write-Host 'Have a look at the configuration posibilities at https://ohmyposh.dev'
}
if (-not (Test-Path $PROFILE)) {
Write-Host "The Powershell profile can't be found, have a look at https://ohmyposh.dev/docs/installation for instructions"
exit 0
}
$title = @'
__ _____ _ ___ ___ ______ _ __
/ / | _ | | | \/ | | ___ \ | | \ \
/ / | | | | |__ | . . |_ _ | |_/ /__ ___| |__ \ \
< < | | | | '_ \ | |\/| | | | | | __/ _ \/ __| '_ \ > >
\ \ \ \_/ / | | | | | | | |_| | | | | (_) \__ \ | | | / /
\_\ \___/|_| |_| \_| |_/\__, | \_| \___/|___/_| |_| /_/
__/ |
|___/
'@
$choices = '&Yes', '&No'
$question = "Do you want to add Oh my Posh to $PROFILE ?"
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
Write-ExitIfNeeded -Decision $decision
if (!(Get-Content $PROFILE)) {
Set-Prompt -ProfilePath $PROFILE
exit 0
}
$profileContent = (Get-Content $PROFILE).ToLower()
if ($profileContent -match 'function:prompt' -or $profileContent -match 'function prompt') {
$title = "$ProfilePath already contains a prompt function override."
$question = "Do you want to override it with Oh my Posh?"
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
Write-ExitIfNeeded -Decision $decision
}
elseif ($profileContent -match 'oh-my-posh') {
$title = "$ProfilePath already contains an Oh my Posh import statement."
$question = "Do you want to override it?"
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
Write-ExitIfNeeded -Decision $decision
}
Set-Prompt -ProfilePath $PROFILE