mirror of
https://github.com/actions/runner-images.git
synced 2025-12-20 06:35:47 +00:00
[Windows] Implement installation helpers refactoring (#8865)
* [Windows] Refactor base Installer helper functions * Fix helper name * Fix name gen logic and improve error handling * Fix hash checking logic * Fix Install-VsixExtension invocation * Fix variable name in Install-OpenSSL.ps1 * Fix type for git downloadUrl
This commit is contained in:
committed by
GitHub
parent
46f21c4413
commit
d3e630f774
@@ -6,20 +6,6 @@
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
#region functions
|
||||
Function Get-PowerShellCoreHash
|
||||
{
|
||||
Param (
|
||||
[Parameter(Mandatory = $True)]
|
||||
[string] $Release
|
||||
)
|
||||
|
||||
$hashURL = "https://github.com/PowerShell/PowerShell/releases/download/v${Release}/hashes.sha256"
|
||||
(Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*PowerShell-${Release}-win-x64.msi*" }).Split(' ')[0]
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
|
||||
$null = New-Item -ItemType Directory -Path $tempDir -Force -ErrorAction SilentlyContinue
|
||||
try {
|
||||
@@ -28,33 +14,12 @@ try {
|
||||
|
||||
$metadata = Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json
|
||||
$release = $metadata.LTSReleaseTag[0] -replace '^v'
|
||||
$packageName = "PowerShell-${release}-win-x64.msi"
|
||||
$downloadUrl = "https://github.com/PowerShell/PowerShell/releases/download/v${release}/PowerShell-${release}-win-x64.msi"
|
||||
|
||||
$downloadURL = "https://github.com/PowerShell/PowerShell/releases/download/v${release}/${packageName}"
|
||||
Write-Verbose "About to download package from '$downloadURL'" -Verbose
|
||||
$hashUrl = "https://github.com/PowerShell/PowerShell/releases/download/v${release}/hashes.sha256"
|
||||
$expectedSHA256Sum = (Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*PowerShell-${Release}-win-x64.msi*" }).Split(' ')[0]
|
||||
|
||||
$packagePath = Join-Path -Path $tempDir -ChildPath $packageName
|
||||
Invoke-WebRequest -Uri $downloadURL -OutFile $packagePath
|
||||
|
||||
#region Supply chain security
|
||||
Write-Verbose "Performing checksum verification"
|
||||
|
||||
$distributor_file_hash = Get-PowerShellCoreHash -Release $release
|
||||
$local_file_hash = (Get-FileHash -Path $packagePath -Algorithm SHA256).Hash
|
||||
|
||||
if ($local_file_hash -ne $distributor_file_hash) {
|
||||
Write-Host "hash must be equal to: ${distributor_file_hash}"
|
||||
Write-Host "actual hash is: ${local_file_hash}"
|
||||
throw 'Checksum verification failed, please rerun install'
|
||||
}
|
||||
#endregion
|
||||
|
||||
Write-Verbose "Performing quiet install"
|
||||
$ArgumentList=@("/i", $packagePath, "/quiet")
|
||||
$process = Start-Process msiexec -ArgumentList $ArgumentList -Wait -PassThru
|
||||
if ($process.exitcode -ne 0) {
|
||||
throw "Quiet install failed, please rerun install without -Quiet switch or ensure you have administrator rights"
|
||||
}
|
||||
Install-Binary -Url $downloadUrl -ExpectedSHA256Sum $expectedSHA256Sum
|
||||
} finally {
|
||||
# Restore original value
|
||||
[Net.ServicePointManager]::SecurityProtocol = $originalValue
|
||||
|
||||
Reference in New Issue
Block a user