Skip to content

Commit 6208cae

Browse files
Add PowerShell install script for Windows
- Add install.ps1.template that downloads, verifies, and installs the CLI on Windows - Script installs to $LOCALAPPDATA\DeepSource\bin and adds it to user PATH - Update build-and-deploy workflow to render and upload the PowerShell script
1 parent e2a7abb commit 6208cae

2 files changed

Lines changed: 90 additions & 1 deletion

File tree

.github/workflows/build-and-deploy.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ jobs:
277277
-e 's|__DEFAULT_INSTALL_DIR__|./bin|g' \
278278
scripts/install.sh.template > artifacts/install-legacy
279279
280+
# PowerShell install script (Windows)
281+
sed -e "s|__BASE_URL__|${{ needs.resolve-env.outputs.base_url }}|g" \
282+
-e "s|__BINARY_NAME__|${{ needs.resolve-env.outputs.binary_name }}|g" \
283+
scripts/install.ps1.template > artifacts/install.ps1
284+
280285
- name: Upload to R2
281286
env:
282287
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
@@ -300,7 +305,7 @@ jobs:
300305
done
301306
302307
# Upload manifest and install scripts (short cache)
303-
for f in artifacts/manifest.json artifacts/install artifacts/install-legacy; do
308+
for f in artifacts/manifest.json artifacts/install artifacts/install-legacy artifacts/install.ps1; do
304309
aws s3 cp "$f" "s3://${BUCKET}/${PREFIX}$(basename "$f")" \
305310
--endpoint-url "$ENDPOINT" \
306311
--cache-control "public, max-age=60"

scripts/install.ps1.template

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# DeepSource CLI installer for Windows
2+
3+
$ErrorActionPreference = "Stop"
4+
5+
$BaseUrl = "__BASE_URL__"
6+
$BinaryName = "__BINARY_NAME__"
7+
8+
function Pass($msg) { Write-Host "✓ $msg" -ForegroundColor Green }
9+
function Fail($msg) { Write-Host "✗ $msg" -ForegroundColor Red; exit 1 }
10+
function Info($msg) { Write-Host "→ $msg" -ForegroundColor Cyan }
11+
12+
$PlatformKey = "windows_amd64"
13+
14+
# Fetch manifest
15+
try {
16+
$Manifest = Invoke-RestMethod -Uri "$BaseUrl/manifest.json"
17+
} catch {
18+
Fail "Failed to fetch manifest: $_"
19+
}
20+
21+
$Version = $Manifest.version
22+
if (-not $Version) {
23+
Fail "Failed to determine latest version from manifest"
24+
}
25+
Pass "Version: v$Version"
26+
27+
$Platform = $Manifest.platforms.$PlatformKey
28+
if (-not $Platform) {
29+
Fail "No build available for $PlatformKey"
30+
}
31+
32+
$Archive = $Platform.archive
33+
$ExpectedSha = $Platform.sha256
34+
$ArchiveUrl = "$BaseUrl/build/$Archive"
35+
36+
# Download archive
37+
$TmpFile = Join-Path ([System.IO.Path]::GetTempPath()) $Archive
38+
try {
39+
Invoke-WebRequest -Uri $ArchiveUrl -OutFile $TmpFile -UseBasicParsing
40+
} catch {
41+
Fail "Failed to download archive: $_"
42+
}
43+
Pass "Downloaded"
44+
45+
# Verify SHA256
46+
$ActualSha = (Get-FileHash -Path $TmpFile -Algorithm SHA256).Hash.ToLower()
47+
if ($ActualSha -ne $ExpectedSha) {
48+
Remove-Item -Path $TmpFile -Force
49+
Fail "Checksum mismatch: expected $ExpectedSha, got $ActualSha"
50+
}
51+
Pass "Checksum verified"
52+
53+
# Extract binary
54+
$InstallDir = Join-Path $env:LOCALAPPDATA "DeepSource\bin"
55+
if (-not (Test-Path $InstallDir)) {
56+
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
57+
}
58+
59+
$TmpExtract = Join-Path ([System.IO.Path]::GetTempPath()) "deepsource_extract"
60+
if (Test-Path $TmpExtract) {
61+
Remove-Item -Path $TmpExtract -Recurse -Force
62+
}
63+
64+
Expand-Archive -Path $TmpFile -DestinationPath $TmpExtract -Force
65+
Copy-Item -Path (Join-Path $TmpExtract "$BinaryName.exe") -Destination (Join-Path $InstallDir "$BinaryName.exe") -Force
66+
67+
# Cleanup
68+
Remove-Item -Path $TmpFile -Force
69+
Remove-Item -Path $TmpExtract -Recurse -Force
70+
71+
Pass "Installed to $InstallDir\$BinaryName.exe"
72+
73+
# Add to user PATH if not already present
74+
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
75+
if ($UserPath -notlike "*$InstallDir*") {
76+
[Environment]::SetEnvironmentVariable("Path", "$InstallDir;$UserPath", "User")
77+
Pass "Added $InstallDir to user PATH"
78+
Info "Restart your terminal for PATH changes to take effect"
79+
} else {
80+
Pass "$InstallDir is already in PATH"
81+
}
82+
83+
Write-Host ""
84+
Info "Run '$BinaryName' to get started"

0 commit comments

Comments
 (0)