From 5f12c60c53e120b12348996a74723eafc451c3de Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Wed, 26 Jul 2023 23:53:10 +0900 Subject: [PATCH] Support Chrome for Testing on *NIX --- .github/workflows/test.yml | 8 +++++++- lib/setup-chromedriver.sh | 26 ++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9160b7fb..1bda41f6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,7 @@ jobs: matrix: os: [ ubuntu-latest, ubuntu-20.04, macos-latest, macos-11 ] branch: [ 'master', 'now' ] + chrome_version: [ 'current', '114.0.5735.90' ] steps: - uses: actions/checkout@v3 - if: startsWith(matrix.os, 'ubuntu') @@ -37,9 +38,14 @@ jobs: node_modules/.bin/tsc $GITHUB_WORKSPACE/__tests__/chromedriver.ts node_modules/.bin/ncc build $GITHUB_WORKSPACE/__tests__/chromedriver.js -o $GITHUB_WORKSPACE/__tests__ rm -rf node_modules - - run: | + - if: matrix.chrome_version != 'current' + run: | CHROME_VERSION=$("$CHROMEAPP" --version | cut -f 3 -d ' ' | cut -d '.' -f 1) echo "CHROMEDRIVER_VERSION=$(curl --location --fail --retry 10 http://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION})" >> $GITHUB_ENV + - if: matrix.chrome_version == 'current' + run: | + CHROME_VERSION=$("$CHROMEAPP" --version | cut -f 3 -d ' ' | cut -d '.' -f 1) + echo "CHROMEDRIVER_VERSION=$CHROME_VERSION" >> $GITHUB_ENV - uses: ./ if: matrix.branch == 'now' with: diff --git a/lib/setup-chromedriver.sh b/lib/setup-chromedriver.sh index a2cf18e5..e0b97eb8 100755 --- a/lib/setup-chromedriver.sh +++ b/lib/setup-chromedriver.sh @@ -11,16 +11,34 @@ if [ "$ARCH" == "linux64" ]; then 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 + fi elif [ "$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) - VERSION=$(curl --location --fail --retry 10 http://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION}) +CHROME_VERSION=$("$CHROMEAPP" --version | cut -f 3 -d ' ' | cut -d '.' -f 1) +UNDER115=0 +dpkg --compare-versions "$CHROME_VERSION" "le" "115" || UNDER115=$? +if [ "$UNDER115" -eq 1 ]; then + if [ "$VERSION" == "" ]; then + VERSION=$(curl --location --fail --retry 10 http://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION}) + fi + + curl --location --fail --retry 10 -O https://chromedriver.storage.googleapis.com/${VERSION}/chromedriver_${ARCH}.zip +else + if [ "$VERSION" == "" ]; then + VERSION=$CHROME_VERSION + fi + if [ "$ARCH" == "mac64" ]; then + ARCH="mac-x64" + fi + URL=$(curl --location --fail --retry 10 https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | jq '.versions[] | select(.version == "$VERSION") | .downloads.chromedriver[] | select(.platform == "$ARCH") | .url') + curl --location --fail --retry 10 -O "$URL" fi -wget -c -nc --retry-connrefused --tries=0 https://chromedriver.storage.googleapis.com/${VERSION}/chromedriver_${ARCH}.zip unzip -o -q chromedriver_${ARCH}.zip sudo mv chromedriver /usr/local/bin/chromedriver rm chromedriver_${ARCH}.zip