-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall-windows.ps1
More file actions
84 lines (72 loc) · 3.15 KB
/
install-windows.ps1
File metadata and controls
84 lines (72 loc) · 3.15 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
param(
[string]$Version = "latest"
)
$ErrorActionPreference = "Stop"
Write-Host "Installing dbc CLI version: $Version"
try {
# Download the official Windows install script
$response = Invoke-WebRequest -Uri "https://dbc.columnar.tech/install.ps1" -UseBasicParsing
# Handle both PowerShell Core (byte[]) and Windows PowerShell 5.1 (string)
if ($response.Content -is [byte[]]) {
$installScript = [System.Text.Encoding]::UTF8.GetString($response.Content)
} else {
$installScript = $response.Content
}
# Save to temporary file to avoid Invoke-Expression security risks
$tempScript = Join-Path $env:TEMP "dbc-install-$(Get-Random).ps1"
$installScript | Out-File -FilePath $tempScript -Encoding UTF8
try {
# Execute script, passing -Version parameter if not "latest"
if ($Version -ne "latest") {
& $tempScript -Version $Version
} else {
& $tempScript
}
} finally {
# Clean up temporary file
Remove-Item -Path $tempScript -ErrorAction SilentlyContinue
}
# Try to find dbc - first check expected location directly
$expectedDbcPath = Join-Path (Join-Path $env:USERPROFILE ".local\bin") "dbc.exe"
if (Test-Path $expectedDbcPath) {
$expectedDir = Split-Path -Parent $expectedDbcPath
$pathEntries = $env:Path -split ';' | ForEach-Object { $_.TrimEnd('\') }
$expectedDirNormalized = $expectedDir.TrimEnd('\')
if ($pathEntries -notcontains $expectedDirNormalized) {
$env:Path = "$expectedDir;$env:Path"
}
}
# Verify installation and get actual location
$dbcPath = Get-Command dbc -ErrorAction SilentlyContinue
if (-not $dbcPath) {
Write-Error "dbc CLI installation failed - command not found"
exit 1
}
# Ensure actual location is in session PATH (may differ from expected)
$actualDbcDir = Split-Path -Parent $dbcPath.Source
$pathEntries = $env:Path -split ';' | ForEach-Object { $_.TrimEnd('\') }
$actualDbcDirNormalized = $actualDbcDir.TrimEnd('\')
if ($pathEntries -notcontains $actualDbcDirNormalized) {
$env:Path = "$actualDbcDir;$env:Path"
}
# Add actual location to GitHub Actions PATH
if ($env:GITHUB_PATH) {
$actualDbcDir | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
}
# Output version for verification
dbc --version
# Save actual install path so cache-hit runs use the verified location.
# Written after dbc --version succeeds to guarantee it records a working install.
# Always written to ~\.local\bin\dbc-install-dir.txt regardless of $actualDbcDir,
# consistent with the cache-restore step that reads from that fixed path.
# Guarded by $env:GITHUB_PATH to skip during local debugging outside GitHub Actions.
if ($env:GITHUB_PATH) {
New-Item -ItemType Directory -Force -Path (Join-Path $env:USERPROFILE ".local\bin") | Out-Null
$actualDbcDir | Out-File -FilePath (Join-Path $env:USERPROFILE ".local\bin\dbc-install-dir.txt") -Encoding utf8
}
Write-Host "dbc CLI installed successfully"
}
catch {
Write-Error "Failed to install dbc CLI: $_"
exit 1
}