mirror of
https://github.com/actions/runner-images.git
synced 2026-01-04 17:18:52 +08:00
Merge pull request #185 from andy-mishechkin/v-andmish/win-image-gen/install-chrome
Install Google Chrome, Chromedriver and Selenium
This commit is contained in:
@@ -336,6 +336,12 @@
|
||||
"{{ template_dir }}/scripts/Installers/Install-Firefox.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Install-Selenium.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
|
||||
@@ -306,6 +306,12 @@
|
||||
"{{ template_dir }}/scripts/Installers/Install-Firefox.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Install-Selenium.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
|
||||
@@ -16,4 +16,6 @@ Export-ModuleMember -Function @(
|
||||
'Install-EXE'
|
||||
'Add-ContentToMarkdown'
|
||||
'Add-SoftwareDetailsToMarkdown'
|
||||
'Stop-SvcWithErrHandling'
|
||||
'Set-SvcWithErrHandling'
|
||||
)
|
||||
|
||||
@@ -81,3 +81,82 @@ function Install-EXE
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
function Stop-SvcWithErrHandling
|
||||
<#
|
||||
.DESCRIPTION
|
||||
Function for stopping the Windows Service with error handling
|
||||
|
||||
.AUTHOR
|
||||
Andrey Mishechkin v-andmis@microsoft.com
|
||||
|
||||
.PARAMETER -ServiceName
|
||||
The name of stopping service
|
||||
|
||||
.PARAMETER -StopOnError
|
||||
Switch for stopping the script and exit from PowerShell if one service is absent
|
||||
#>
|
||||
{
|
||||
param (
|
||||
[Parameter(Mandatory, ValueFromPipeLine = $true)] [string] $ServiceName,
|
||||
[Parameter()] [switch] $StopOnError
|
||||
)
|
||||
|
||||
Process {
|
||||
$Service = Get-Service $ServiceName -ErrorAction SilentlyContinue
|
||||
if (-not $Service) {
|
||||
Write-Warning "[!] Service [$ServiceName] is not found";
|
||||
if ($StopOnError) {
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host "Try to stop service [$ServiceName]";
|
||||
try {
|
||||
Stop-Service -Name $ServiceName -Force;
|
||||
$Service.WaitForStatus("Stopped", "00:01:00");
|
||||
Write-Host "Service [$ServiceName] has been stopped successfuly";
|
||||
}
|
||||
catch {
|
||||
Write-Error "[!] Failed to stop service [$ServiceName] with error:"
|
||||
$_ | Out-String | Write-Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Set-SvcWithErrHandling
|
||||
<#
|
||||
.DESCRIPTION
|
||||
Function for setting the Windows Service parameter with error handling
|
||||
|
||||
.AUTHOR
|
||||
Andrey Mishechkin v-andmis@microsoft.com
|
||||
|
||||
.PARAMETER -ServiceName
|
||||
The name of stopping service
|
||||
|
||||
.PARAMETER -Arguments
|
||||
Hashtable for service arguments
|
||||
#>
|
||||
{
|
||||
|
||||
param (
|
||||
[Parameter(Mandatory, ValueFromPipeLine = $true)] [string] $ServiceName,
|
||||
[Parameter(Mandatory)] [hashtable] $Arguments
|
||||
)
|
||||
|
||||
Process {
|
||||
$Service = Get-Service $ServiceName -ErrorAction SilentlyContinue
|
||||
if (-not $Service) {
|
||||
Write-Warning "[!] Service [$ServiceName] is not found";
|
||||
}
|
||||
try {
|
||||
Set-Service $ServiceName @Arguments;
|
||||
}
|
||||
catch {
|
||||
Write-Error "[!] Failed to set service [$ServiceName] arguments with error:"
|
||||
$_ | Out-String | Write-Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,24 +3,40 @@
|
||||
## Desc: Install Google Chrome
|
||||
################################################################################
|
||||
|
||||
Import-Module -Name ImageHelpers -Force
|
||||
Import-Module -Name ImageHelpers -Force;
|
||||
|
||||
$temp_install_dir = 'C:\Windows\Installer'
|
||||
New-Item -Path $temp_install_dir -ItemType Directory -Force
|
||||
$ChromeInstallerFile = "chrome_installer.exe";
|
||||
$ChromeInstallerUri = "https://dl.google.com/chrome/install/375.126/${ChromeInstallerFile}";
|
||||
Install-Exe -Url $ChromeInstallerUri -Name $ChromeInstallerFile -ArgumentList ("/silent", "/install")
|
||||
|
||||
Install-MSI -MsiUrl "https://seleniumwebdrivers.blob.core.windows.net/knownchromeversion/googlechromestandaloneenterprise64.msi" -MsiName "googlechromestandaloneenterprise64.msi"
|
||||
Write-Host "Adding the firewall rule for Google update blocking";
|
||||
New-NetFirewallRule -DisplayName "BlockGoogleUpdate" -Direction Outbound -Action Block -Program "C:\Program Files (x86)\Google\Update\GoogleUpdate.exe";
|
||||
|
||||
New-NetFirewallRule -DisplayName "BlockGoogleUpdate" -Direction Outbound -Action Block -Program "C:\Program Files (x86)\Google\Update\GoogleUpdate.exe"
|
||||
$GoogleSvcs = ('gupdate','gupdatem');
|
||||
$GoogleSvcs | Stop-SvcWithErrHandling -StopOnError;
|
||||
$GoogleSvcs | Set-SvcWithErrHandling -Arguments @{StartupType = "Disabled"};
|
||||
|
||||
$regGoogleUpdatePath = "HKLM:\SOFTWARE\Policies\Google\Update";
|
||||
$regGoogleUpdateChrome = "HKLM:\SOFTWARE\Policies\Google\Chrome";
|
||||
($regGoogleUpdatePath, $regGoogleUpdateChrome) | ForEach-Object {
|
||||
New-Item -Path $_ -Force;
|
||||
}
|
||||
|
||||
$regGoogleParameters = @(
|
||||
@{ Name = "AutoUpdateCheckPeriodMinutes"; Value = 00000000},
|
||||
@{ Name = "UpdateDefault"; Value = 00000000 },
|
||||
@{ Name = "DisableAutoUpdateChecksCheckboxValue"; Value = 00000001 },
|
||||
@{ Name = "Update{8A69D345-D564-463C-AFF1-A69D9E530F96}"; Value = 00000000 },
|
||||
@{ Path = $regGoogleUpdateChrome; Name = "DefaultBrowserSettingEnabled"; Value = 00000000 }
|
||||
)
|
||||
|
||||
$regGoogleParameters | ForEach-Object {
|
||||
$Arguments = $_;
|
||||
if (-not ($Arguments.Path)) {
|
||||
$Arguments.Add("Path", $regGoogleUpdatePath);
|
||||
}
|
||||
$Arguments.Add("Force", $true);
|
||||
New-ItemProperty @Arguments;
|
||||
}
|
||||
|
||||
Stop-Service -Name gupdate -Force
|
||||
Set-Service -Name gupdate -StartupType "Disabled"
|
||||
Stop-Service -Name gupdatem -Force
|
||||
Set-Service -Name gupdatem -StartupType "Disabled"
|
||||
|
||||
New-Item -Path "HKLM:\SOFTWARE\Policies\Google\Update" -Force
|
||||
New-ItemProperty "HKLM:\SOFTWARE\Policies\Google\Update" -Name "AutoUpdateCheckPeriodMinutes" -Value 00000000 -Force
|
||||
New-ItemProperty "HKLM:\SOFTWARE\Policies\Google\Update" -Name "UpdateDefault" -Value 00000000 -Force
|
||||
New-ItemProperty "HKLM:\SOFTWARE\Policies\Google\Update" -Name "DisableAutoUpdateChecksCheckboxValue" -Value 00000001 -Force
|
||||
New-ItemProperty "HKLM:\SOFTWARE\Policies\Google\Update" -Name "Update{8A69D345-D564-463C-AFF1-A69D9E530F96}" -Value 00000000 -Force
|
||||
New-Item -Path "HKLM:\SOFTWARE\Policies\Google\Chrome" -Force
|
||||
New-ItemProperty "HKLM:\SOFTWARE\Policies\Google\Chrome" -Name "DefaultBrowserSettingEnabled" -Value 00000000 -Force
|
||||
|
||||
36
images/win/scripts/Installers/Install-Selenium.ps1
Normal file
36
images/win/scripts/Installers/Install-Selenium.ps1
Normal file
@@ -0,0 +1,36 @@
|
||||
################################################################################
|
||||
## File: Install-Selenium.ps1
|
||||
## Desc: Install Selenium Server standalone
|
||||
################################################################################
|
||||
|
||||
# Acquire latest Selenium release number from GitHub API
|
||||
$latestReleaseUrl = "https://api.github.com/repos/SeleniumHQ/selenium/releases/latest"
|
||||
try {
|
||||
$latestReleaseInfo = Invoke-RestMethod -Uri $latestReleaseUrl
|
||||
} catch {
|
||||
Write-Error $_
|
||||
exit 1
|
||||
}
|
||||
Write-Debug $latestReleaseInfo
|
||||
$seleniumVersionString = $latestReleaseInfo.name.Split(" ")[1]
|
||||
Write-Debug $seleniumVersionString
|
||||
$seleniumVersion = [version]::Parse($seleniumVersionString)
|
||||
|
||||
# Download Selenium
|
||||
Write-Host "Downloading selenium-server-standalone v$seleniumVersion..."
|
||||
|
||||
$seleniumReleaseUrl = "https://selenium-release.storage.googleapis.com/$($seleniumVersion.ToString(2))/selenium-server-standalone-$($seleniumVersion.ToString(3)).jar"
|
||||
New-Item -ItemType directory -Path "C:\selenium\"
|
||||
$seleniumBinPath = "C:\selenium\selenium-server-standalone.jar"
|
||||
try {
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $seleniumReleaseUrl -OutFile $seleniumBinPath
|
||||
} catch {
|
||||
Write-Error $_
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Add selenium to CLASSPATH..."
|
||||
setx "CLASSPATH" "$($seleniumBinPath);$($env:CLASSPATH)" /M
|
||||
Write-Host "CLASSPATH: $($seleniumBinPath);$($env:CLASSPATH)"
|
||||
|
||||
exit 0
|
||||
@@ -2,16 +2,58 @@
|
||||
## File: Install-SeleniumWebDrivers.ps1
|
||||
## Desc: Install Selenium Web Drivers
|
||||
################################################################################
|
||||
$DestinationPath = "$($env:SystemDrive)\";
|
||||
$DriversZipFile = "SeleniumWebDrivers.zip"
|
||||
Write-Host "Destination path: [$DestinationPath]";
|
||||
Write-Host "Selenium drivers download and install...";
|
||||
try {
|
||||
Invoke-WebRequest -UseBasicParsing -Uri "https://seleniumwebdrivers.blob.core.windows.net/seleniumwebdrivers/${DriversZipFile}" -OutFile $DriversZipFile;
|
||||
}
|
||||
catch {
|
||||
Write-Error "[!] Failed to download $DriverZipFile";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
Invoke-WebRequest -UseBasicParsing -Uri "https://seleniumwebdrivers.blob.core.windows.net/seleniumwebdrivers/SeleniumWebDrivers.zip" -OutFile SeleniumWebDrivers.zip
|
||||
Expand-Archive -Path $DriversZipFile -DestinationPath $DestinationPath -Force;
|
||||
Remove-Item $DriversZipFile;
|
||||
|
||||
Expand-Archive -Path SeleniumWebDrivers.zip -DestinationPath "C:\" -Force
|
||||
$ChromeDriverPath = "$DestinationPath\SeleniumWebDrivers\ChromeDriver";
|
||||
Write-Host "Chrome driver path: [$ChromeDriverPath]";
|
||||
Remove-Item -Path "$ChromeDriverPath\*" -Force;
|
||||
|
||||
Remove-Item SeleniumWebDrivers.zip
|
||||
$ChromePath = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe').'(default)';
|
||||
[version]$ChromeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ChromePath).ProductVersion;
|
||||
Write-Host "Chrome version: [$ChromeVersion]";
|
||||
|
||||
setx IEWebDriver "C:\SeleniumWebDrivers\IEDriver" /M
|
||||
setx GeckoWebDriver "C:\SeleniumWebDrivers\GeckoDriver" /M
|
||||
setx ChromeWebDriver "C:\SeleniumWebDrivers\ChromeDriver" /M
|
||||
$ChromeDriverVersionUri = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$($ChromeVersion.Major).$($ChromeVersion.Minor).$($ChromeVersion.Build)";
|
||||
Write-Host "Chrome driver version Uri [$ChromeDriverVersionUri]";
|
||||
Write-Host "Getting the Chrome driver version...";
|
||||
$ChromeDriverVersion = Invoke-WebRequest -Uri $ChromeDriverVersionUri;
|
||||
Write-Host "Current Chrome driver version: [$ChromeDriverVersion]";
|
||||
|
||||
exit 0
|
||||
$ChromeDriverZipDownloadUri = "https://chromedriver.storage.googleapis.com/$($ChromeDriverVersion.ToString())/chromedriver_win32.zip";
|
||||
Write-Host "Chrome driver zip file download Uri: [$ChromeDriverZipDownloadUri]";
|
||||
|
||||
$DestFile= "$ChromeDriverPath\chromedriver_win32.zip";
|
||||
$ChromeDriverVersion.Content | Out-File -FilePath "$ChromeDriverPath\versioninfo.txt" -Force;
|
||||
|
||||
Write-Host "Chrome driver download....";
|
||||
Invoke-WebRequest -Uri $ChromeDriverZipDownloadUri -OutFile $DestFile;
|
||||
|
||||
Write-Host "Chrome driver install....";
|
||||
Expand-Archive -Path "$ChromeDriverPath\chromedriver_win32.zip" -DestinationPath $ChromeDriverPath -Force;
|
||||
Remove-Item -Path "$ChromeDriverPath\chromedriver_win32.zip" -Force;
|
||||
|
||||
Write-Host "Setting the environment variables";
|
||||
|
||||
setx IEWebDriver "C:\SeleniumWebDrivers\IEDriver" /M;
|
||||
setx GeckoWebDriver "C:\SeleniumWebDrivers\GeckoDriver" /M;
|
||||
setx ChromeWebDriver "C:\SeleniumWebDrivers\ChromeDriver" /M;
|
||||
|
||||
$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\';
|
||||
$PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path';
|
||||
$PathValue += ";C:\SeleniumWebDrivers\ChromeDriver\";
|
||||
Set-ItemProperty -Path $regEnvKey -Name 'Path' -Value $PathValue;
|
||||
|
||||
exit 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user