Skip to content

Commit 58ad897

Browse files
refactor: replace Get-FileHash with custom SHA256 hash function for better error handling
1 parent 5ee4eab commit 58ad897

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

artifacts/SHA256SUMS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cc7a6dce911bcc4778a8e8f315428dcf1f42d21a29240cbc94849ea85309ad63 cloudsqlctl.exe

tools/stage-artifacts.ps1

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,37 @@ $ExeSource = Join-Path $BinDir "cloudsqlctl.exe"
1818
$SetupSource = Join-Path $DistDir "cloudsqlctl-setup.exe"
1919

2020
if (-not (Test-Path $ExeSource)) { Write-Error "Missing binary: $ExeSource"; exit 1 }
21-
if (-not (Test-Path $SetupSource)) { Write-Error "Missing installer: $SetupSource"; exit 1 }
21+
22+
if (Test-Path $SetupSource) {
23+
Copy-Item $SetupSource -Destination $ArtifactsDir
24+
}
25+
else {
26+
Write-Warning "Installer not found at $SetupSource. Skipping."
27+
}
2228

2329
Copy-Item $ExeSource -Destination $ArtifactsDir
24-
Copy-Item $SetupSource -Destination $ArtifactsDir
2530

2631
# 3. Generate SHA256 Checksums
2732
$ChecksumFile = Join-Path $ArtifactsDir "SHA256SUMS.txt"
28-
Get-ChildItem $ArtifactsDir -Filter "*.exe" | Get-FileHash -Algorithm SHA256 | ForEach-Object {
29-
"$($_.Hash) $($_.Path | Split-Path -Leaf)"
33+
34+
function Get-Sha256Hash {
35+
param($FilePath)
36+
try {
37+
$fileStream = [System.IO.File]::OpenRead($FilePath)
38+
$hasher = [System.Security.Cryptography.SHA256]::Create()
39+
$hashBytes = $hasher.ComputeHash($fileStream)
40+
$fileStream.Close()
41+
return [BitConverter]::ToString($hashBytes).Replace("-", "").ToLower()
42+
}
43+
catch {
44+
Write-Error "Failed to calculate hash for ${FilePath}: $_"
45+
exit 1
46+
}
47+
}
48+
49+
Get-ChildItem $ArtifactsDir -Filter "*.exe" | ForEach-Object {
50+
$hash = Get-Sha256Hash -FilePath $_.FullName
51+
"$hash $($_.Name)"
3052
} | Out-File -Encoding ASCII $ChecksumFile
3153

3254
# 4. Create Distribution Zip

0 commit comments

Comments
 (0)