150 lines
6.3 KiB
PowerShell
150 lines
6.3 KiB
PowerShell
#Requires -Version 5.1
|
|
<#
|
|
.SYNOPSIS
|
|
Installs Alibaba Open Code Review (ocr) for Windows.
|
|
|
|
.DESCRIPTION
|
|
GitHub Releases에서 제공하는 Windows용 네이티브 바이너리(.exe)를
|
|
자동 감지된 아키텍처(AMD64 또는 ARM64)에 따라 다운로드하고
|
|
$env:USERPROFILE\.local\bin\ocr.exe 경로에 설치합니다.
|
|
공식 레포지토리: https://github.com/alibaba/open-code-review
|
|
|
|
.EXAMPLE
|
|
.\install-ocr.ps1
|
|
#>
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
# HTTPS 다운로드를 위해 TLS 1.2+ 강제 설정
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
|
|
# ────────────────────────────────────────────
|
|
# 상수 정의
|
|
# ────────────────────────────────────────────
|
|
$REPO = "alibaba/open-code-review"
|
|
$API_URL = "https://api.github.com/repos/$REPO/releases/latest"
|
|
$INSTALL_DIR = Join-Path $env:USERPROFILE ".local\bin"
|
|
$FALLBACK_VERSION = "v1.3.19"
|
|
|
|
# ────────────────────────────────────────────
|
|
# 유틸리티 함수 (영문 메시지 출력, 에러 방지용)
|
|
# ────────────────────────────────────────────
|
|
function Info { Write-Host "[INFO] $args" -ForegroundColor Cyan }
|
|
function Warn { Write-Host "[WARN] $args" -ForegroundColor Yellow }
|
|
function Success { Write-Host "[OK] $args" -ForegroundColor Green }
|
|
function ErrExit { Write-Host "[ERROR] $args" -ForegroundColor Red; exit 1 }
|
|
|
|
# ────────────────────────────────────────────
|
|
# 아키텍처 감지
|
|
# ────────────────────────────────────────────
|
|
$arch = $env:PROCESSOR_ARCHITECTURE
|
|
Info "Detected CPU Architecture: $arch"
|
|
|
|
$assetName = $null
|
|
if ($arch -eq "AMD64") {
|
|
$assetName = "opencodereview-windows-amd64.exe"
|
|
} elseif ($arch -eq "ARM64") {
|
|
$assetName = "opencodereview-windows-arm64.exe"
|
|
} else {
|
|
Warn "Unsupported architecture '$arch'. Falling back to AMD64."
|
|
$assetName = "opencodereview-windows-amd64.exe"
|
|
}
|
|
|
|
# ────────────────────────────────────────────
|
|
# 최신 릴리즈 태그 가져오기
|
|
# ────────────────────────────────────────────
|
|
$tag = $null
|
|
try {
|
|
Info "Fetching latest release tag from GitHub API..."
|
|
$response = Invoke-RestMethod -Uri $API_URL -TimeoutSec 10
|
|
$tag = $response.tag_name
|
|
} catch {
|
|
Warn "Failed to retrieve the latest version from GitHub API. Using fallback version: $FALLBACK_VERSION"
|
|
$tag = $FALLBACK_VERSION
|
|
}
|
|
|
|
if (-not $tag) {
|
|
$tag = $FALLBACK_VERSION
|
|
}
|
|
|
|
$downloadUrl = "https://github.com/$REPO/releases/download/$tag/$assetName"
|
|
Info "Resolved download URL: $downloadUrl"
|
|
|
|
# ────────────────────────────────────────────
|
|
# 다운로드 및 설치
|
|
# ────────────────────────────────────────────
|
|
# 설치 폴더 생성
|
|
if (-not (Test-Path $INSTALL_DIR)) {
|
|
New-Item -ItemType Directory -Path $INSTALL_DIR | Out-Null
|
|
Info "Created installation directory: $INSTALL_DIR"
|
|
}
|
|
|
|
$tempFile = Join-Path $env:TEMP "ocr_temp.exe"
|
|
$destFile = Join-Path $INSTALL_DIR "ocr.exe"
|
|
|
|
try {
|
|
Info "Downloading binary..."
|
|
# Invoke-WebRequest를 사용해 다운로드 진행
|
|
Invoke-WebRequest -Uri $downloadUrl -OutFile $tempFile -UseBasicParsing
|
|
|
|
# 다운로드 완료 후 복사
|
|
if (Test-Path $destFile) {
|
|
Remove-Item $destFile -Force
|
|
}
|
|
Move-Item -Path $tempFile -Destination $destFile -Force
|
|
Success "Binary installed to $destFile"
|
|
} catch {
|
|
if (Test-Path $tempFile) { Remove-Item $tempFile -ErrorAction SilentlyContinue }
|
|
ErrExit "Failed to download or install the binary: $_"
|
|
}
|
|
|
|
# ────────────────────────────────────────────
|
|
# PATH 환경 변수 설정
|
|
# ────────────────────────────────────────────
|
|
$userPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')
|
|
$normalizedInstallDir = $INSTALL_DIR.TrimEnd('\')
|
|
|
|
# 현재 세션 PATH 확인 및 반영
|
|
if ($env:Path -notlike "*$normalizedInstallDir*") {
|
|
$env:Path = "$normalizedInstallDir;$env:Path"
|
|
Info "Added $normalizedInstallDir to current session PATH."
|
|
}
|
|
|
|
# 사용자 PATH 레지스트리 영구 등록 확인
|
|
$pathList = $userPath -split ';'
|
|
$alreadyInPath = $false
|
|
foreach ($p in $pathList) {
|
|
if ($p.Trim().TrimEnd('\') -eq $normalizedInstallDir) {
|
|
$alreadyInPath = $true
|
|
break
|
|
}
|
|
}
|
|
|
|
if (-not $alreadyInPath) {
|
|
$newUserPath = "$normalizedInstallDir;$userPath"
|
|
[System.Environment]::SetEnvironmentVariable('Path', $newUserPath, 'User')
|
|
Success "Added $normalizedInstallDir to User PATH environment variable permanently."
|
|
Info "Note: You need to restart your terminal/IDE to apply PATH changes."
|
|
} else {
|
|
Info "$normalizedInstallDir is already in User PATH."
|
|
}
|
|
|
|
# ────────────────────────────────────────────
|
|
# 설치 완료 정보 출력
|
|
# ────────────────────────────────────────────
|
|
Info ""
|
|
Info "=================================================="
|
|
Success "Open Code Review (ocr) installation complete!"
|
|
Info "=================================================="
|
|
Info ""
|
|
Info "How to run:"
|
|
Info " ocr review --from <base-branch> --to <head-branch>"
|
|
Info ""
|
|
Info "To configure LLM (e.g. OpenAI):"
|
|
Info ' ocr config set llm.url "https://api.openai.com/v1"'
|
|
Info ' ocr config set llm.auth_token "YOUR_API_KEY"'
|
|
Info ' ocr config set llm.model "gpt-4o"'
|
|
Info ""
|
|
Info "For more information, visit: https://github.com/alibaba/open-code-review"
|