Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge from master to v2 branch #210

Merged
merged 12 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 68 additions & 58 deletions lib/setup-chromedriver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,88 @@

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

if [ "$ARCH" == "linux64" ]; then
if [[ "${ARCH}" =~ ^linux64 ]]; then
CHROMEAPP=google-chrome
if ! type -a sudo > /dev/null 2>&1; then
apt-get update
apt-get install -y sudo
fi
if ! type -a curl > /dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y curl
fi
if ! type -a google-chrome > /dev/null 2>&1; then
# for debian
# curl -O https://dl.google.com/linux/direct/google-chrome-stable_current_amd64f.deb
# sudo apt install -y ./google-chrome-stable_current_amd64.deb
# CHROMEAPP=google-chrome-stable
sudo apt-get update
sudo apt-get install -y google-chrome
fi
if ! type -a jq > /dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y jq
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
if ! type -a bc > /dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y bc
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[@]}"
fi
elif [ "$ARCH" == "mac64" ]; then
fi

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

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

UNDER115=$(echo "$CHROME_VERSION < 115" | bc)
if [ "$UNDER115" -eq 1 ]; then
if [ "$VERSION" == "" ]; then
VERSION=$(curl --location --fail --retry 10 http://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION})
if ((CHROME_VERSION < 115)); then
if [[ -z "${VERSION}" ]]; then
URL="https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION}"
echo "Downloading ${URL}..."
VERSION=$(${CURL} "${URL}")
echo "VERSION=${VERSION}"
fi
echo "Installing ChromeDriver $VERSION for $ARCH"

curl --location --fail --retry 10 -O https://chromedriver.storage.googleapis.com/${VERSION}/chromedriver_${ARCH}.zip
unzip -o -q chromedriver_${ARCH}.zip
echo "Installing ChromeDriver ${VERSION} for ${ARCH}"
URL="https://chromedriver.storage.googleapis.com/${VERSION}/chromedriver_${ARCH}.zip"
echo "Downloading ${URL}..."
${CURL} -o chromedriver.zip "${URL}"
unzip -o -q chromedriver.zip
sudo mv chromedriver /usr/local/bin/chromedriver
rm chromedriver_${ARCH}.zip
else
if [ "$VERSION" == "" ]; then
VERSION=$("$CHROMEAPP" --version | cut -f 3 -d ' ')
fi
if [ "$ARCH" == "mac64" ]; then
ARCH="mac-x64"
fi

echo "Installing ChromeDriver $VERSION for $ARCH"
URL=$(curl --location --fail --retry 10 https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | jq -r ".versions[] | select(.version == \"${VERSION}\") | .downloads.chromedriver[] | select(.platform == \"${ARCH}\") | .url")
if [ "$URL" == "" ]; then
echo "Fallback to latest version of ChromeDriver for $ARCH"
VERSION=$(curl --location --fail --retry 10 https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | jq -r ".versions[] | select(.version | startswith(\"$(echo $VERSION | cut -d '.' -f1-3).\")) | .version" | tail -1)
URL=$(curl --location --fail --retry 10 https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | jq -r ".versions[] | select(.version == \"${VERSION}\") | .downloads.chromedriver[] | select(.platform == \"${ARCH}\") | .url")
echo "Installing ChromeDriver $VERSION for $ARCH"
fi
echo "Downloading $URL"
curl --location --fail --retry 10 -O "$URL"
unzip -o -q chromedriver-${ARCH}.zip
sudo mv chromedriver-${ARCH}/chromedriver /usr/local/bin/chromedriver
rm chromedriver-${ARCH}.zip
rm -r chromedriver-${ARCH}
rm -f chromedriver.zip
exit
fi

if [[ -z "${VERSION}" ]]; then
VERSION=$("${CHROMEAPP}" --version | cut -f 3 -d ' ')
echo "VERSION=${VERSION}"
fi
if [[ "${ARCH}" =~ ^mac64 ]]; then
ARCH="mac-x64"
fi

echo "Downloading ${JSON_URL}..."
JSON=$(${CURL} "${JSON_URL}")
JQ=".versions[] | select(.version == \"${VERSION}\") | .downloads.chromedriver[] | select(.platform == \"${ARCH}\") | .url"
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}")
echo "VERSION3=${VERSION3}"
JQ2="[ .versions[] | select(.version | startswith(\"${VERSION3}.\")) ] | last | .version"
VERSION=$(jq -r "${JQ2}" <<<"${JSON}")
echo "VERSION=${VERSION}"
JQ3=".versions[] | select(.version == \"${VERSION}\") | .downloads.chromedriver[] | select(.platform == \"${ARCH}\") | .url"
URL=$(jq -r "${JQ3}" <<<"${JSON}")
fi
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
rm -fr chromedriver.zip chromedriver-*
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/node": "^20.4.5",
"@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",
"husky": "^8.0.3",
"jest": "^27.5.1",
"jest-circus": "^29.6.1",
"prettier": "^3.0.0",
"selenium-webdriver": "^4.11.0",
"jest-circus": "^29.6.2",
"prettier": "^3.0.1",
"selenium-webdriver": "^4.11.1",
"ts-jest": "^27.1.3",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
Expand Down
Loading