-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInstall-Debug.ps1
More file actions
109 lines (94 loc) · 3.4 KB
/
Install-Debug.ps1
File metadata and controls
109 lines (94 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Builds and installs pr-copilot locally for development/testing.
.DESCRIPTION
Publishes a Release build, then renames the running PrCopilot binary to
a backup name (which gets cleaned up on next startup) and copies
the new build in place. Just restart your Copilot CLI session afterward.
#>
param(
)
$ErrorActionPreference = "Stop"
$RepoRoot = $PSScriptRoot
if ($IsWindows) {
$InstallDir = Join-Path $env:USERPROFILE ".copilot" "mcp-servers" "pr-copilot"
} else {
$InstallDir = Join-Path $env:HOME ".copilot" "mcp-servers" "pr-copilot"
}
$StagingDir = Join-Path ([System.IO.Path]::GetTempPath()) "pr-copilot-staging"
# Detect platform RID
if ($IsWindows) {
$rid = "win-x64"
$exeName = "PrCopilot.exe"
$ext = ".exe"
} elseif ($IsMacOS) {
$arch = uname -m
$rid = if ($arch -eq "arm64") { "osx-arm64" } else { "osx-x64" }
$exeName = "PrCopilot"
$ext = ""
} else {
Write-Error "Unsupported platform. pr-copilot currently supports Windows and macOS."
exit 1
}
$ExePath = Join-Path $InstallDir $exeName
# Compute dev version from latest git tag
git -C $RepoRoot fetch --tags --quiet 2>$null
$latestTag = git -C $RepoRoot tag --list 'v*' --sort=-v:refname | Select-Object -First 1
if ($latestTag) {
$ver = $latestTag -replace '^v', ''
$parts = $ver -split '\.'
$nextPatch = [int]$parts[2] + 1
$prefix = "$($parts[0]).$($parts[1]).$nextPatch"
} else {
$prefix = "0.1.0"
}
$seconds = [int]([datetime]::Now - [datetime]::Today).TotalSeconds
$devVersion = "$prefix-dev.$([datetime]::Now.ToString('yyyyMMdd')).$seconds"
Write-Host "📋 Version: $devVersion" -ForegroundColor DarkGray
Write-Host "🔨 Building Release..." -ForegroundColor Cyan
$csprojPath = Join-Path $RepoRoot "PrCopilot" "src" "PrCopilot" "PrCopilot.csproj"
dotnet publish $csprojPath `
-c Release -r $rid --self-contained `
-p:PublishSingleFile=true `
-p:IncludeNativeLibrariesForSelfExtract=true `
-p:Version=$devVersion `
-o $StagingDir --nologo -v quiet
if ($LASTEXITCODE -ne 0) {
Write-Error "Build failed."
exit 1
}
Write-Host "📂 Installing to $InstallDir..." -ForegroundColor Cyan
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
# Rename running binary with next available .old.N suffix
if (Test-Path $ExePath) {
$n = 0
do {
$bakTarget = if ($n -eq 0) {
Join-Path $InstallDir "PrCopilot.old$ext"
} else {
Join-Path $InstallDir "PrCopilot.old.$n$ext"
}
$n++
} while (Test-Path $bakTarget)
try {
Rename-Item $ExePath $bakTarget -Force
Write-Host " Renamed $exeName → $(Split-Path $bakTarget -Leaf)" -ForegroundColor DarkGray
} catch {
Write-Warning "Could not rename existing binary. Close any running instances and retry."
exit 1
}
}
Copy-Item -Path (Join-Path $StagingDir "*") -Destination $InstallDir -Force -Recurse
Remove-Item $StagingDir -Recurse -Force -ErrorAction SilentlyContinue
# Write version sidecar for viewer update detection
Set-Content -Path (Join-Path $InstallDir "version.txt") -Value $devVersion -NoNewline
# Make binary executable on Unix
if (-not $IsWindows) {
chmod +x $ExePath
}
Write-Host ""
Write-Host "⚙️ Running setup..." -ForegroundColor Cyan
& $ExePath --setup
Write-Host ""
Write-Host "✅ Installed! Restart your Copilot CLI session to pick up the new build." -ForegroundColor Green