mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2026-01-03 15:57:26 +08:00
[Windows] Apply code style rules to Windows scripts (#8957)
* Apply code style rules to Windows scripts * Fix typo * Fix configure-toolset script * Fix parameters in Msys2 installation script * Improve log readability * Remove broken exit code validation
This commit is contained in:
committed by
GitHub
parent
76d6f0f574
commit
7fe65a2204
@@ -7,75 +7,104 @@
|
||||
# https://github.com/msys2/MINGW-packages/blob/master/azure-pipelines.yml
|
||||
# https://packages.msys2.org/group/
|
||||
|
||||
$dash = "-" * 40
|
||||
$logPrefix = "`n" + ("-" * 40) + "`n---"
|
||||
$origPath = $env:PATH
|
||||
|
||||
function Install-Msys2 {
|
||||
# We can't use Resolve-GithubReleaseAssetUrl function here
|
||||
# because msys2-installer releases don't have a consistent versioning scheme
|
||||
# We can't use Resolve-GithubReleaseAssetUrl function here
|
||||
# because msys2-installer releases don't have a consistent versioning scheme
|
||||
|
||||
$assets = (Invoke-RestMethod -Uri "https://api.github.com/repos/msys2/msys2-installer/releases/latest").assets
|
||||
$downloadUri = ($assets | Where-Object { $_.name -match "^msys2-x86_64" -and $_.name.EndsWith(".exe") }).browser_download_url
|
||||
$installerName = Split-Path $downloadUri -Leaf
|
||||
$assets = (Invoke-RestMethod -Uri "https://api.github.com/repos/msys2/msys2-installer/releases/latest").assets
|
||||
$downloadUri = ($assets | Where-Object { $_.name -match "^msys2-x86_64" -and $_.name.EndsWith(".exe") }).browser_download_url
|
||||
$installerName = Split-Path $downloadUri -Leaf
|
||||
|
||||
# Download the latest msys2 x86_64, filename includes release date
|
||||
Write-Host "Download msys2 installer $installerName"
|
||||
$installerPath = Invoke-DownloadWithRetry $downloadUri
|
||||
# Download the latest msys2 x86_64, filename includes release date
|
||||
Write-Host "Download msys2 installer $installerName"
|
||||
$installerPath = Invoke-DownloadWithRetry $downloadUri
|
||||
|
||||
#region Supply chain security - MSYS2
|
||||
$externalHash = Get-ChecksumFromUrl -Type "SHA256" `
|
||||
-Url ($downloadUri -replace $installerName, "msys2-checksums.txt") `
|
||||
-FileName $installerName
|
||||
Test-FileChecksum $installerPath -ExpectedSHA256Sum $externalHash
|
||||
#endregion
|
||||
#region Supply chain security - MSYS2
|
||||
$externalHash = Get-ChecksumFromUrl -Type "SHA256" `
|
||||
-Url ($downloadUri -replace $installerName, "msys2-checksums.txt") `
|
||||
-FileName $installerName
|
||||
Test-FileChecksum $installerPath -ExpectedSHA256Sum $externalHash
|
||||
#endregion
|
||||
|
||||
Write-Host "Starting msys2 installation"
|
||||
& $installerPath in --confirm-command --accept-messages --root C:/msys64
|
||||
Remove-Item $installerPath
|
||||
Write-Host "Starting msys2 installation"
|
||||
& $installerPath in --confirm-command --accept-messages --root C:/msys64
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw "MSYS2 installation failed with exit code $LastExitCode"
|
||||
}
|
||||
Remove-Item $installerPath
|
||||
}
|
||||
|
||||
function Install-Msys2Packages($Packages) {
|
||||
if (-not $Packages) {
|
||||
return
|
||||
}
|
||||
function Install-Msys2Packages {
|
||||
param (
|
||||
[Parameter(Mandatory = $true)]
|
||||
[AllowEmptyCollection()]
|
||||
[string[]]$Packages
|
||||
)
|
||||
|
||||
Write-Host "`n$dash Install msys2 packages"
|
||||
pacman.exe -S --noconfirm --needed --noprogressbar $Packages
|
||||
taskkill /f /fi "MODULES eq msys-2.0.dll"
|
||||
if (-not $Packages) {
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "`n$dash Remove p7zip/7z package due to conflicts"
|
||||
pacman.exe -R --noconfirm --noprogressbar p7zip
|
||||
Write-Host "$logPrefix Install msys2 packages"
|
||||
pacman.exe -S --noconfirm --needed --noprogressbar $Packages
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw "MSYS2 packages installation failed with exit code $LastExitCode"
|
||||
}
|
||||
taskkill /f /fi "MODULES eq msys-2.0.dll"
|
||||
|
||||
Write-Host "$logPrefix Remove p7zip/7z package due to conflicts"
|
||||
pacman.exe -R --noconfirm --noprogressbar p7zip
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw "Removal of p7zip/7z package failed with exit code $LastExitCode"
|
||||
}
|
||||
}
|
||||
|
||||
function Install-MingwPackages($Packages) {
|
||||
if (-not $Packages) {
|
||||
return
|
||||
}
|
||||
function Install-MingwPackages {
|
||||
param (
|
||||
[Parameter(Mandatory = $true)]
|
||||
[AllowEmptyCollection()]
|
||||
[object[]] $Packages
|
||||
)
|
||||
|
||||
Write-Host "`n$dash Install mingw packages"
|
||||
$archs = $Packages.arch
|
||||
if (-not $Packages) {
|
||||
return
|
||||
}
|
||||
|
||||
foreach ($arch in $archs) {
|
||||
Write-Host "Installing $arch packages"
|
||||
$archPackages = $toolsetContent.mingw | Where-Object { $_.arch -eq $arch }
|
||||
$runtimePackages = $archPackages.runtime_packages.name | ForEach-Object { "${arch}-$_" }
|
||||
$additionalPackages = $archPackages.additional_packages | ForEach-Object { "${arch}-$_" }
|
||||
$packagesToInstall = $runtimePackages + $additionalPackages
|
||||
Write-Host "The following packages will be installed: $packagesToInstall"
|
||||
pacman.exe -S --noconfirm --needed --noprogressbar $packagesToInstall
|
||||
}
|
||||
Write-Host "$logPrefix Install mingw packages"
|
||||
$archs = $Packages.arch
|
||||
|
||||
# clean all packages to decrease image size
|
||||
Write-Host "`n$dash Clean packages"
|
||||
pacman.exe -Scc --noconfirm
|
||||
foreach ($arch in $archs) {
|
||||
Write-Host "Installing $arch packages"
|
||||
$archPackages = $toolsetContent.mingw | Where-Object { $_.arch -eq $arch }
|
||||
$runtimePackages = $archPackages.runtime_packages.name | ForEach-Object { "${arch}-$_" }
|
||||
$additionalPackages = $archPackages.additional_packages | ForEach-Object { "${arch}-$_" }
|
||||
$packagesToInstall = $runtimePackages + $additionalPackages
|
||||
Write-Host "The following packages will be installed: $packagesToInstall"
|
||||
pacman.exe -S --noconfirm --needed --noprogressbar $packagesToInstall
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw "Installation of $arch packages failed with exit code $LastExitCode"
|
||||
}
|
||||
}
|
||||
|
||||
$pkgs = pacman.exe -Q
|
||||
# clean all packages to decrease image size
|
||||
Write-Host "$logPrefix Clean packages"
|
||||
pacman.exe -Scc --noconfirm
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw "Cleaning of packages failed with exit code $LastExitCode"
|
||||
}
|
||||
|
||||
foreach ($arch in $archs)
|
||||
{
|
||||
Write-Host "`n$dash Installed $arch packages"
|
||||
$pkgs | grep ^${arch}-
|
||||
}
|
||||
$pkgs = pacman.exe -Q
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw "Listing of packages failed with exit code $LastExitCode"
|
||||
}
|
||||
|
||||
foreach ($arch in $archs) {
|
||||
Write-Host "$logPrefix Installed $arch packages"
|
||||
$pkgs | Select-String -Pattern "^${arch}-"
|
||||
}
|
||||
}
|
||||
|
||||
Install-Msys2
|
||||
@@ -83,11 +112,18 @@ Install-Msys2
|
||||
# Add msys2 bin tools folders to PATH temporary
|
||||
$env:PATH = "C:\msys64\mingw64\bin;C:\msys64\usr\bin;$origPath"
|
||||
|
||||
Write-Host "`n$dash pacman --noconfirm -Syyuu"
|
||||
Write-Host "$logPrefix pacman --noconfirm -Syyuu"
|
||||
pacman.exe -Syyuu --noconfirm
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw "Updating of packages failed with exit code $LastExitCode"
|
||||
}
|
||||
taskkill /f /fi "MODULES eq msys-2.0.dll"
|
||||
Write-Host "`n$dash pacman --noconfirm -Syuu (2nd pass)"
|
||||
pacman.exe -Syuu --noconfirm
|
||||
|
||||
Write-Host "$logPrefix pacman --noconfirm -Syuu (2nd pass)"
|
||||
pacman.exe -Syuu --noconfirm
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw "Second pass updating of packages failed with exit code $LastExitCode"
|
||||
}
|
||||
taskkill /f /fi "MODULES eq msys-2.0.dll"
|
||||
|
||||
$toolsetContent = (Get-ToolsetContent).MsysPackages
|
||||
|
||||
Reference in New Issue
Block a user