Skip to content

Commit ac4f511

Browse files
Add local file:// URI support to PowerShell installer
Add helper functions (Resolve-LocalSourcePath, Copy-ArtifactToFile, Read-TextResource) to install.ps1 so that artifact downloads and checksum reads transparently handle both remote URLs and local file:// paths. This lets the integration tests supply local zip artifacts without needing EasyMode or a real HTTP server. Update the two PowerShell integration tests accordingly: - Remove the Windows-only guard so they run on any platform with pwsh. - Drop the now-unnecessary -EasyMode flag since the installer natively handles file:// URIs through the new helpers. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 347b3e4 commit ac4f511

2 files changed

Lines changed: 49 additions & 16 deletions

File tree

install.ps1

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,52 @@ function Get-SiblingUrl {
7373
}
7474
}
7575

76+
function Resolve-LocalSourcePath {
77+
param([string]$Location)
78+
79+
if (-not $Location) { return $null }
80+
81+
try {
82+
$uri = [System.Uri]$Location
83+
if ($uri.IsAbsoluteUri -and $uri.IsFile) {
84+
return $uri.LocalPath
85+
}
86+
} catch {
87+
}
88+
89+
if (Test-Path -LiteralPath $Location) {
90+
return (Resolve-Path -LiteralPath $Location).ProviderPath
91+
}
92+
93+
return $null
94+
}
95+
96+
function Copy-ArtifactToFile {
97+
param(
98+
[string]$Location,
99+
[string]$Destination
100+
)
101+
102+
$localPath = Resolve-LocalSourcePath $Location
103+
if ($localPath) {
104+
Copy-Item -LiteralPath $localPath -Destination $Destination -Force
105+
return
106+
}
107+
108+
Invoke-WebRequest -Uri $Location -OutFile $Destination
109+
}
110+
111+
function Read-TextResource {
112+
param([string]$Location)
113+
114+
$localPath = Resolve-LocalSourcePath $Location
115+
if ($localPath) {
116+
return Get-Content -LiteralPath $localPath -Raw
117+
}
118+
119+
return Invoke-RestMethod -Uri $Location -ErrorAction Stop
120+
}
121+
76122
# Map architecture to the naming convention used by release.yml
77123
$arch = "amd64"
78124
$zip = "cass-windows-${arch}.zip"
@@ -94,7 +140,7 @@ try {
94140
$zipFile = Join-Path $tmp $zip
95141

96142
Write-Host "Downloading $url"
97-
Invoke-WebRequest -Uri $url -OutFile $zipFile
143+
Copy-ArtifactToFile -Location $url -Destination $zipFile
98144

99145
$checksumToUse = $Checksum
100146
if (-not $checksumToUse) {
@@ -107,11 +153,8 @@ try {
107153
if ($checksumFetched) { break }
108154
if (-not $tryUrl) { continue }
109155
try {
110-
# Use Invoke-RestMethod which returns the body as a string and follows
111-
# redirects reliably across all PowerShell versions (Windows PS 5.x and
112-
# PS Core 7+). Invoke-WebRequest with -UseBasicParsing can return
113-
# .Content as a byte array in PS 5.x, breaking .Trim().
114-
$raw = Invoke-RestMethod -Uri $tryUrl -ErrorAction Stop
156+
# Read checksum content as text from either a local file or a remote URL.
157+
$raw = Read-TextResource $tryUrl
115158
if ($tryUrl -like "*/SHA256SUMS.txt") {
116159
# SHA256SUMS.txt contains lines like: <hash> <filename>
117160
foreach ($line in $raw -split "`n") {

tests/install_scripts.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,6 @@ fn find_powershell() -> Option<String> {
392392

393393
#[test]
394394
fn install_ps1_succeeds_with_valid_checksum() {
395-
if !cfg!(target_os = "windows") {
396-
eprintln!("skipping powershell test: non-windows runner");
397-
return;
398-
}
399395
let Some(ps) = find_powershell() else {
400396
eprintln!("skipping powershell test: pwsh not found");
401397
return;
@@ -422,7 +418,6 @@ fn install_ps1_succeeds_with_valid_checksum() {
422418
.arg(dest.path())
423419
.arg("-Checksum")
424420
.arg(&checksum)
425-
.arg("-EasyMode")
426421
.arg("-ArtifactUrl")
427422
.arg(format!("file://{}", zip.display()))
428423
.status()
@@ -437,10 +432,6 @@ fn install_ps1_succeeds_with_valid_checksum() {
437432

438433
#[test]
439434
fn install_ps1_fails_with_bad_checksum() {
440-
if !cfg!(target_os = "windows") {
441-
eprintln!("skipping powershell test: non-windows runner");
442-
return;
443-
}
444435
let Some(ps) = find_powershell() else {
445436
eprintln!("skipping powershell test: pwsh not found");
446437
return;
@@ -461,7 +452,6 @@ fn install_ps1_fails_with_bad_checksum() {
461452
.arg(dest.path())
462453
.arg("-Checksum")
463454
.arg("deadbeef")
464-
.arg("-EasyMode")
465455
.arg("-ArtifactUrl")
466456
.arg(format!("file://{}", zip.display()))
467457
.status()

0 commit comments

Comments
 (0)