mirror of
https://github.com/actions/runner-images.git
synced 2025-12-24 10:28:00 +08:00
Improve Windows browsers provisioners stability (#725)
* Improve Chrome provisioner * Improve Edge provisioner * Improve Firefox provisioner * Resolve conflicts in Install-Chrome.ps1
This commit is contained in:
@@ -5,71 +5,48 @@
|
||||
|
||||
Import-Module -Name ImageHelpers -Force
|
||||
|
||||
$temp_install_dir = 'C:\Windows\Installer'
|
||||
New-Item -Path $temp_install_dir -ItemType Directory -Force
|
||||
# Install and configure Firefox browser
|
||||
Write-Host "Install latest Firefox browser..."
|
||||
$VersionsManifest = Invoke-RestMethod "https://product-details.mozilla.org/1.0/firefox_versions.json"
|
||||
$InstallerName = "firefox-browser.exe"
|
||||
$InstallerUrl = "https://download.mozilla.org/?product=firefox-$($VersionsManifest.LATEST_FIREFOX_VERSION)&os=win64&lang=en-US"
|
||||
$ArgumentList = ("/silent", "/install")
|
||||
|
||||
$versionsJson = Invoke-RestMethod "https://product-details.mozilla.org/1.0/firefox_versions.json"
|
||||
$latestVersion = $versionsJson.LATEST_FIREFOX_VERSION
|
||||
Write-Host "Firefox latest version: $latestVersion"
|
||||
Install-Binary -Url $InstallerUrl -Name $InstallerName -ArgumentList $ArgumentList
|
||||
|
||||
# url for latest version of firefox
|
||||
$urlLatestVersion = "https://download.mozilla.org/?product=firefox-${latestVersion}&os=win64&lang=en-US"
|
||||
Install-Binary -Url $urlLatestVersion -Name "Firefox Setup $latestVersion.exe" -ArgumentList ("/silent", "/install")
|
||||
|
||||
# Disable autoupdate
|
||||
$firefoxDirectoryPath = Join-Path $env:ProgramFiles "Mozilla Firefox"
|
||||
New-Item -path $firefoxDirectoryPath -Name 'mozilla.cfg' -Value '//
|
||||
Write-Host "Disable autoupdate..."
|
||||
$FirefoxDirectoryPath = Join-Path $env:ProgramFiles "Mozilla Firefox"
|
||||
New-Item -path $FirefoxDirectoryPath -Name 'mozilla.cfg' -Value '//
|
||||
pref("browser.shell.checkDefaultBrowser", false);
|
||||
pref("app.update.enabled", false);' -ItemType file -force
|
||||
|
||||
$firefoxPreferencesFolder = Join-Path $firefoxDirectoryPath "defaults\pref"
|
||||
New-Item -path $firefoxPreferencesFolder -Name 'local-settings.js' -Value 'pref("general.config.obscure_value", 0);
|
||||
$FirefoxPreferencesFolder = Join-Path $FirefoxDirectoryPath "defaults\pref"
|
||||
New-Item -path $FirefoxPreferencesFolder -Name 'local-settings.js' -Value 'pref("general.config.obscure_value", 0);
|
||||
pref("general.config.filename", "mozilla.cfg");' -ItemType file -force
|
||||
|
||||
# Install Firefox gecko Web Driver
|
||||
Write-Host "Install Firefox WebDriver"
|
||||
$DestinationPath = "$($env:SystemDrive)\";
|
||||
$SeleniumWebDriverPath = Join-Path $DestinationPath "SeleniumWebDrivers"
|
||||
|
||||
$geckodriverJson = Invoke-RestMethod "https://api.github.com/repos/mozilla/geckodriver/releases/latest"
|
||||
$geckodriverWindowsAsset = $geckodriverJson.assets | Where-Object { $_.name -Match "win64" } | Select-Object -First 1
|
||||
|
||||
$geckodriverVersion = $geckodriverJson.tag_name
|
||||
Write-Host "Geckodriver version: $geckodriverVersion"
|
||||
|
||||
$DriversZipFile = $geckodriverWindowsAsset.name
|
||||
Write-Host "Selenium drivers download and install..."
|
||||
|
||||
$FirefoxDriverPath = Join-Path $SeleniumWebDriverPath "GeckoDriver"
|
||||
|
||||
if (-not (Test-Path -Path $FirefoxDriverPath)) {
|
||||
New-Item -Path $FirefoxDriverPath -ItemType "directory"
|
||||
# Download and install Gecko WebDriver
|
||||
Write-Host "Install Gecko WebDriver..."
|
||||
$GeckoDriverPath = "$($env:SystemDrive)\SeleniumWebDrivers\GeckoDriver"
|
||||
if (-not (Test-Path -Path $GeckoDriverPath))
|
||||
{
|
||||
New-Item -Path $GeckoDriverPath -ItemType Directory -Force
|
||||
}
|
||||
|
||||
$geckodriverVersion.Substring(1) | Out-File -FilePath "$FirefoxDriverPath\versioninfo.txt" -Force;
|
||||
Write-Host "Get the Gecko WebDriver version..."
|
||||
$GeckoDriverJson = Invoke-RestMethod "https://api.github.com/repos/mozilla/geckodriver/releases/latest"
|
||||
$GeckoDriverWindowsAsset = $GeckoDriverJson.assets | Where-Object { $_.name -Match "win64" } | Select-Object -First 1
|
||||
$GeckoDriverVersion = $GeckoDriverJson.tag_name
|
||||
$GeckoDriverVersion.Substring(1) | Out-File -FilePath "$GeckoDriverPath\versioninfo.txt" -Force;
|
||||
|
||||
# Install Firefox Web Driver
|
||||
Write-Host "FireFox driver download...."
|
||||
if (-not (Test-Path -Path $FireFoxDriverPath)) {
|
||||
New-Item -Path $FireFoxDriverPath -ItemType "directory"
|
||||
}
|
||||
Write-Host "Download Gecko WebDriver WebDriver..."
|
||||
$GeckoDriverArchName = $GeckoDriverWindowsAsset.name
|
||||
$GeckoDriverDownloadUrl = $GeckoDriverWindowsAsset.browser_download_url
|
||||
|
||||
$DestFile = Join-Path $FireFoxDriverPath $DriversZipFile
|
||||
$FireFoxDriverDownloadUrl = $geckodriverWindowsAsset.browser_download_url
|
||||
try{
|
||||
Invoke-WebRequest -Uri $FireFoxDriverDownloadUrl -OutFile $DestFile
|
||||
} catch {
|
||||
Write-Error "[!] Failed to download $DriversZipFile"
|
||||
exit 1
|
||||
}
|
||||
$GeckoDriverArchPath = Start-DownloadWithRetry -Url $GeckoDriverDownloadUrl -Name $GeckoDriverArchName
|
||||
|
||||
Write-Host "FireFox driver install...."
|
||||
Expand-Archive -Path $DestFile -DestinationPath $FireFoxDriverPath -Force
|
||||
Remove-Item -Path $DestFile -Force
|
||||
Write-Host "Expand Gecko WebDriver archive..."
|
||||
Expand-Archive -Path $GeckoDriverArchPath -DestinationPath $GeckoDriverPath -Force
|
||||
|
||||
|
||||
Write-Host "Setting the environment variables"
|
||||
Add-MachinePathItem -PathItem $FireFoxDriverPath
|
||||
setx GeckoWebDriver "$FirefoxDriverPath" /M;
|
||||
|
||||
exit 0
|
||||
Write-Host "Setting the environment variables..."
|
||||
Add-MachinePathItem -PathItem $GeckoDriverPath
|
||||
setx GeckoWebDriver "$GeckoDriverPath" /M
|
||||
Reference in New Issue
Block a user