Skip to content

Commit

Permalink
Merge pull request #253 from nanasess/master
Browse files Browse the repository at this point in the history
Merge from master branch to v2
  • Loading branch information
nanasess authored Nov 28, 2023
2 parents 3855694 + 480d644 commit b53c9ef
Show file tree
Hide file tree
Showing 6 changed files with 536 additions and 487 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ jobs:
- 'now'
chrome_version:
- 'current'
- '114.0.5735.90'
# FIXME https://github.com/nanasess/setup-chromedriver/issues/229
# - '114.0.5735.90'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- if: startsWith(matrix.os, 'ubuntu')
run: echo 'CHROMEAPP=google-chrome' >> $GITHUB_ENV
- if: startsWith(matrix.os, 'macos')
Expand Down Expand Up @@ -83,7 +84,7 @@ jobs:
# - 'master'
- 'now'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- if: startsWith(matrix.os, 'ubuntu')
run: echo 'CHROMEAPP=google-chrome' >> $GITHUB_ENV
- if: startsWith(matrix.os, 'macos')
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
# - 'master'
- 'now'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- shell: pwsh
run: echo "CHROMEAPP=C:\Program Files\Google\Chrome\Application\chrome.exe" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- run: yarn install --frozen-lockfile
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
# - 'master'
- 'now'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- shell: pwsh
run: echo "CHROMEAPP=C:\Program Files\Google\Chrome\Application\chrome.exe" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- run: yarn install --frozen-lockfile
Expand Down
40 changes: 28 additions & 12 deletions lib/setup-chromedriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Param(
[string]$version
)

$json_url = "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
$chrome_fullversion = (Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion

Write-Output "Chrome version: $chrome_fullversion"
Expand All @@ -13,25 +14,40 @@ else
{
$chrome_majorversion = $version.Split(".")[0]
}

if($chrome_majorversion -lt 115)
{
$response = Invoke-WebRequest "http://chromedriver.storage.googleapis.com/LATEST_RELEASE_$chrome_majorversion"
$version = $response.Content
Invoke-WebRequest "https://chromedriver.storage.googleapis.com/$version/chromedriver_win32.zip" -OutFile chromedriver_win32.zip
Expand-Archive -Path chromedriver_win32.zip -DestinationPath C:\SeleniumWebDrivers\ChromeDriver -Force
Remove-Item chromedriver_win32.zip
Return 0
}
else

if([string]::IsNullOrEmpty($version))
{
$version = $chrome_fullversion
}

$arch = "win32"
Write-Output $arch

Write-Output "Downloading $json_url..."
$json = Invoke-WebRequest $json_url -UseBasicParsing | ConvertFrom-Json
$url = $json | Select-Object -ExpandProperty versions | Where-Object { $_.version -eq $version } | Select-Object -ExpandProperty downloads | Select-Object -ExpandProperty chromedriver | Where-Object { $_.platform -eq $arch } | Select-Object -ExpandProperty url
if (!$url)
{
if([string]::IsNullOrEmpty($version))
{
$version = $chrome_fullversion
}
$arch = "win32"
Write-Output $arch
$url = Invoke-WebRequest "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json" -UseBasicParsing | ConvertFrom-Json | Select-Object -ExpandProperty versions | Where-Object { $_.version -eq $version } | Select-Object -ExpandProperty downloads | Select-Object -ExpandProperty chromedriver | Where-Object { $_.platform -eq $arch } | Select-Object -ExpandProperty url
Invoke-WebRequest $url -OutFile chromedriver-win32.zip
Expand-Archive -Path chromedriver-win32.zip -Force
Move-Item -Path .\chromedriver-win32\chromedriver-win32\chromedriver.exe -Destination C:\SeleniumWebDrivers\ChromeDriver -Force
Remove-Item chromedriver-win32.zip
Write-Output "Falling back to latest version of ChromeDriver for $arch"
$version3 = $version.Substring(0, $version.LastIndexOf('.'))
Write-Output "VERSION3 = $version3"
$version = $json | Select-Object -ExpandProperty versions | Where-Object { $_.version -like "$version3.*" } | Select-Object -Last 1 -ExpandProperty version
Write-Output "VERSION = $version"
$url = $json | Select-Object -ExpandProperty versions | Where-Object { $_.version -eq $version } | Select-Object -ExpandProperty downloads | Select-Object -ExpandProperty chromedriver | Where-Object { $_.platform -eq $arch } | Select-Object -ExpandProperty url
}
Write-Output "Installing ChromeDriver $version for $arch"
Write-Output "Downloading $url..."
Invoke-WebRequest $url -OutFile chromedriver-win32.zip
Expand-Archive -Path chromedriver-win32.zip -Force
Move-Item -Path .\chromedriver-win32\chromedriver-win32\chromedriver.exe -Destination C:\SeleniumWebDrivers\ChromeDriver -Force
Remove-Item chromedriver-win32.zip
62 changes: 36 additions & 26 deletions lib/setup-chromedriver.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
#!/bin/bash
#!/usr/bin/env bash

set -eo pipefail

CURL="curl --silent --location --fail --retry 10"
JSON_URL=https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json

VERSION=$1
ARCH=$2
VERSION="${1:-}"
ARCH="${2:-linux64}"

sudo=$(command -v sudo)

if [[ "${ARCH}" =~ ^linux64 ]]; then
CHROMEAPP=google-chrome
sudo=$(command -v sudo)
APP="${CHROMEAPP}"
if ! dpkg -s "${APP}" >/dev/null; then
${sudo} apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A040830F7FAC5991
echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" | ${sudo} tee /etc/apt/sources.list.d/google.list
APP=google-chrome-stable
fi
apps=()
test -z "${sudo}" && apps+=(sudo)
type -a curl > /dev/null 2>&1 || apps+=(curl)
type -a "${CHROMEAPP}" > /dev/null 2>&1 || apps+=("${APP}")
type -a jq > /dev/null 2>&1 || apps+=(jq)
type -a unzip > /dev/null 2>&1 || apps+=(unzip)
if (("${#apps[@]}")); then
echo "Installing ${apps[*]}..."
export DEBIAN_FRONTEND=noninteractive
${sudo} apt-get update
${sudo} apt-get install -y "${apps[@]}"
if command -v dpkg &>/dev/null; then
if ! dpkg -s "${APP}" >/dev/null; then
${sudo} apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A040830F7FAC5991
echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" | ${sudo} tee /etc/apt/sources.list.d/google.list >/dev/null
APP=google-chrome-stable
fi
apps=()
test -z "${sudo}" && apps+=(sudo)
type -a curl > /dev/null 2>&1 || apps+=(curl)
type -a "${CHROMEAPP}" > /dev/null 2>&1 || apps+=("${APP}")
type -a jq > /dev/null 2>&1 || apps+=(jq)
type -a unzip > /dev/null 2>&1 || apps+=(unzip)
if (("${#apps[@]}")); then
echo "Installing ${apps[*]}..."
export DEBIAN_FRONTEND=noninteractive
${sudo} apt-get update
${sudo} apt-get install -y --no-install-recommends "${apps[@]}"
fi
fi
fi

if [[ "${ARCH}" =~ ^mac64 ]]; then
CHROMEAPP="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
fi

if [[ "${VERSION}" ]]; then
if [[ -n "${VERSION}" ]]; then
CHROME_VERSION=$(cut -d '.' -f 1 <<<"${VERSION}")
else
CHROME_VERSION=$("${CHROMEAPP}" --version | cut -f 3 -d ' ' | cut -d '.' -f 1)
CHROME_VERSION=$("${CHROMEAPP}" --version | cut -d ' ' -f 3 | cut -d '.' -f 1)
fi
echo "CHROME_VERSION=${CHROME_VERSION}"

Expand All @@ -54,13 +57,13 @@ if ((CHROME_VERSION < 115)); then
echo "Downloading ${URL}..."
${CURL} -o chromedriver.zip "${URL}"
unzip -o -q chromedriver.zip
sudo mv chromedriver /usr/local/bin/chromedriver
${sudo} mv chromedriver /usr/local/bin/chromedriver
rm -f chromedriver.zip
exit
fi

if [[ -z "${VERSION}" ]]; then
VERSION=$("${CHROMEAPP}" --version | cut -f 3 -d ' ')
VERSION=$("${CHROMEAPP}" --version | cut -d ' ' -f 3)
echo "VERSION=${VERSION}"
fi
if [[ "${ARCH}" =~ ^mac64 ]]; then
Expand All @@ -73,7 +76,7 @@ JQ=".versions[] | select(.version == \"${VERSION}\") | .downloads.chromedriver[]
URL=$(jq -r "${JQ}" <<<"${JSON}")
if [[ -z "${URL}" ]]; then
echo "Falling back to latest version of ChromeDriver for ${ARCH}"
VERSION3=$(cut -d '.' -f1-3 <<<"${VERSION}")
VERSION3=$(cut -d '.' -f 1-3 <<<"${VERSION}")
echo "VERSION3=${VERSION3}"
JQ2="[ .versions[] | select(.version | startswith(\"${VERSION3}.\")) ] | last | .version"
VERSION=$(jq -r "${JQ2}" <<<"${JSON}")
Expand All @@ -85,5 +88,12 @@ echo "Installing ChromeDriver ${VERSION} for ${ARCH}"
echo "Downloading ${URL}..."
${CURL} -o chromedriver.zip "${URL}"
unzip -o -q chromedriver.zip
sudo mv "chromedriver-${ARCH}/chromedriver" /usr/local/bin/chromedriver
echo Installing chromedriver to /usr/local/bin
${sudo} mv "chromedriver-${ARCH}/chromedriver" /usr/local/bin/chromedriver
rm -fr chromedriver.zip chromedriver-*
if command -v "${CHROMEAPP}" >/dev/null; then
echo Chrome version:
"${CHROMEAPP}" --version
fi
echo Chromedriver version:
/usr/local/bin/chromedriver --version
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@
"author": "nanasess",
"license": "GPL",
"dependencies": {
"@actions/core": "1.10.0",
"@actions/core": "1.10.1",
"@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1",
"@actions/github": "^6.0.0",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.1",
"semver": "^7.5.2",
"semver": "^7.5.4",
"typed-rest-client": "^1.8.11"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/node": "^20.5.0",
"@types/selenium-webdriver": "^4.1.15",
"@types/semver": "^7.3.13",
"@types/yauzl": "^2.10.0",
"@vercel/ncc": "^0.36.1",
"@types/node": "^20.10.0",
"@types/selenium-webdriver": "^4.1.19",
"@types/semver": "^7.5.4",
"@types/yauzl": "^2.10.3",
"@vercel/ncc": "^0.38.1",
"husky": "^8.0.3",
"jest": "^27.5.1",
"jest-circus": "^29.6.2",
"prettier": "^3.0.1",
"selenium-webdriver": "^4.11.1",
"jest-circus": "^29.7.0",
"prettier": "^3.1.0",
"selenium-webdriver": "^4.15.0",
"ts-jest": "^27.1.3",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
Expand Down
Loading

0 comments on commit b53c9ef

Please sign in to comment.