feat(scripts): added --ref flag for installing specific git refs

- Added --ref flag to install specific tags, branches, or commits from source or binary releases.
- Enabled source installation from git refs by cloning and checking out the specified reference.
- Added git availability check for source installations with --ref flag.
- Updated README with usage examples for --ref flag on both shell and PowerShell installers.
This commit is contained in:
can1357
2026-01-06 22:01:24 +00:00
parent 3536e2aaaa
commit 5ec30e19f4
3 changed files with 182 additions and 18 deletions
+75 -6
View File
@@ -4,10 +4,14 @@
# Or with options:
# & ([scriptblock]::Create((irm https://raw.githubusercontent.com/can1357/oh-my-pi/main/scripts/install.ps1))) -Source
# & ([scriptblock]::Create((irm https://raw.githubusercontent.com/can1357/oh-my-pi/main/scripts/install.ps1))) -Binary
# & ([scriptblock]::Create((irm https://raw.githubusercontent.com/can1357/oh-my-pi/main/scripts/install.ps1))) -Source -Ref v3.20.1
# & ([scriptblock]::Create((irm https://raw.githubusercontent.com/can1357/oh-my-pi/main/scripts/install.ps1))) -Source -Ref main
# & ([scriptblock]::Create((irm https://raw.githubusercontent.com/can1357/oh-my-pi/main/scripts/install.ps1))) -Binary -Ref v3.20.1
param(
[switch]$Source,
[switch]$Binary
[switch]$Binary,
[string]$Ref
)
$ErrorActionPreference = "Stop"
@@ -26,6 +30,15 @@ function Test-BunInstalled {
}
}
function Test-GitInstalled {
try {
$null = Get-Command git -ErrorAction Stop
return $true
} catch {
return $false
}
}
function Install-Bun {
Write-Host "Installing bun..."
irm bun.sh/install.ps1 | iex
@@ -35,18 +48,70 @@ function Install-Bun {
function Install-ViaBun {
Write-Host "Installing via bun..."
bun install -g $Package
if ($Ref) {
if (-not (Test-GitInstalled)) {
throw "git is required for -Ref when installing from source"
}
$tmpRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("omp-install-" + [System.Guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Force -Path $tmpRoot | Out-Null
try {
$repoUrl = "https://github.com/$Repo.git"
$cloneOk = $false
try {
git clone --depth 1 --branch $Ref $repoUrl $tmpRoot | Out-Null
$cloneOk = $true
} catch {
$cloneOk = $false
}
if (-not $cloneOk) {
git clone $repoUrl $tmpRoot | Out-Null
Push-Location $tmpRoot
try {
git checkout $Ref | Out-Null
} finally {
Pop-Location
}
}
$packagePath = Join-Path $tmpRoot "packages\coding-agent"
if (-not (Test-Path $packagePath)) {
throw "Expected package at $packagePath"
}
bun install -g $packagePath
} finally {
Remove-Item -Recurse -Force $tmpRoot -ErrorAction SilentlyContinue
}
} else {
bun install -g $Package
}
Write-Host ""
Write-Host "✓ Installed omp via bun" -ForegroundColor Green
Write-Host "Run 'omp' to get started!"
}
function Install-Binary {
# Get latest release
Write-Host "Fetching latest release..."
$Release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
if ($Ref) {
Write-Host "Fetching release $Ref..."
try {
$Release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/tags/$Ref"
} catch {
throw "Release tag not found: $Ref`nFor branch/commit installs, use -Source with -Ref."
}
} else {
Write-Host "Fetching latest release..."
$Release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
}
$Latest = $Release.tag_name
Write-Host "Latest version: $Latest"
if (-not $Latest) {
throw "Failed to fetch release tag"
}
Write-Host "Using version: $Latest"
# Download binary
$Url = "https://github.com/$Repo/releases/download/$Latest/$BinaryName"
@@ -71,6 +136,10 @@ function Install-Binary {
}
# Main logic
if ($Ref -and -not $Source -and -not $Binary) {
$Source = $true
}
if ($Source) {
if (-not (Test-BunInstalled)) {
Install-Bun