Skip to content

Commit

Permalink
chore: improve ci powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
oberrich committed Jan 10, 2025
1 parent 7a0f5a1 commit cc0adc2
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ jobs:
)
$timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
if ($Level -eq "ERROR") {
Write-Error "$timestamp [ERROR] - $Message"
Write-Host "$timestamp [ERROR] - $Message" -ForegroundColor Red
} else {
Write-Host "$timestamp [$Level] - $Message"
Write-Host "$timestamp [$Level] - $Message"
}
}
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
$installs = @(
$deps = @(
# @{ Name = 'Chocolatey'; Url = 'https://chocolatey.org/install.ps1'; Hash = $null;
# Action = { & './install.ps1' }},
# @{ Name = 'Visual Studio 2022 Build Tools (aarch64)'; Hash = $null; Url = $null;
Expand All @@ -63,38 +63,40 @@ jobs:
Action = { & './Git-2.48.0-rc2-arm64.exe' /VERYSILENT }}
)
$installs | ForEach-Object {
if ($_.Url -ne $null) {
Log "Downloading $($_.Name) from $($_.Url)..."
$install_file = Join-Path '${{ github.workspace }}' (Split-Path $_.Url -Leaf)
Invoke-WebRequest -Uri $_.Url -OutFile $install_file
$deps | ForEach-Object {
$dep = $_
if ($dep.Url -ne $null) {
Log "Downloading $($dep.Name) from $($dep.Url)..."
$install_file = Join-Path '${{ github.workspace }}' (Split-Path $dep.Url -Leaf)
Invoke-WebRequest -Uri $dep.Url -OutFile $install_file
}
if ($_.Hash -ne $null) {
$expected_hash = if ($_.Hash -like "*.sha256") {
$hash_file = Join-Path '${{ github.workspace }}' (Split-Path $_.Hash -Leaf)
Invoke-WebRequest -Uri $_.Hash -OutFile $hash_file
if ($dep.Hash -ne $null) {
$expected_hash = if ($dep.Hash -like "*.sha256") {
$hash_file = Join-Path '${{ github.workspace }}' (Split-Path $dep.Hash -Leaf)
Invoke-WebRequest -Uri $dep.Hash -OutFile $hash_file
(Get-Content -Path $hash_file).Trim()
} else {
$_.Hash
$dep.Hash
}
$downloaded_hash = (Get-FileHash -Path $install_file -Algorithm SHA256).Hash
if ($downloaded_hash -eq $expected_hash) {
Log "Hash verified successfully."
} else {
Log "Hash mismatch for $($_.Name). Expected: $expected_hash, Got: $downloaded_hash" -Level "ERROR"
Log "Hash mismatch for $($dep.Name). Expected: $expected_hash, Got: $downloaded_hash" -Level "ERROR"
}
} else {
Log "No hash specified, skipping verification."
}
Log "Starting installation of $($_.Name)..."
Log "Starting installation of $($dep.Name)..."
try {
& $_.Action
Log "$($_.Name) installation completed."
& $dep.Action
Log "$($dep.Name) installation completed."
} catch {
Log "Failed to install $($_.Name)" -Level "ERROR"
Log "An error occurred while installing $($dep.Name): $_" "ERROR"
Log "Error Details: $($_.Exception.Message)" "ERROR"
}
}
Expand Down

0 comments on commit cc0adc2

Please sign in to comment.