Automaticaly fetch chromedriver version based on chrome

This commit is contained in:
Andrejs Cunskis 2022-07-04 14:11:03 +00:00
parent 0a603faec2
commit f71fe0261d
No known key found for this signature in database
GPG key ID: 87CB75083F227241
3 changed files with 29 additions and 34 deletions

View file

@ -15,47 +15,48 @@ function build_debian() {
fi
CHROME_VERSION=${1:-99.0.4844.74-1}
CHROME_DRIVER_VERSION=${2:-99.0.4844.51}
# We hard code the URL rather than using $CI_API_V4_URL $CI_PROJECT_ID,
# because we would need to forward those variables
CHROME_DOWNLOAD_URL_BASE="https://gitlab.com/api/v4/projects/1075790/packages/generic/google-chrome-stable"
export DEBIAN_FRONTEND=noninteractive
curl -sS -L https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >/etc/apt/sources.list.d/google.list
apt-get update -q -y
# Download from our package registry if we can't find the package in the apt repository
echo "Searching for $CHROME_VERSION in apt repository"
CHECK_VERSION=$(apt-cache show google-chrome-stable | grep Version | grep "$CHROME_VERSION") || true
# Download from our package registry if we can't find the package in the apt repository
echo "Searching for $CHROME_VERSION in apt repository"
CHECK_VERSION=$(apt-cache show google-chrome-stable | grep Version | grep "$CHROME_VERSION") || true
apt-cache policy google-chrome-stable
apt-cache policy google-chrome-stable
if [[ -z $CHECK_VERSION ]]; then
CHROME_DEB="google-chrome-stable_${CHROME_VERSION}_$(dpkg --print-architecture).deb"
CHROME_URL="${CHROME_DOWNLOAD_URL_BASE}/${CHROME_VERSION}/${CHROME_DEB}"
echo "Downloading from our Package registry: $CHROME_URL"
curl --silent --show-error --fail -O $CHROME_URL
dpkg -i ./$CHROME_DEB || true
apt-get install -f -y
rm -f $CHROME_DEB
else
echo "Installing via apt-get"
apt-get install -y google-chrome-stable=$CHROME_VERSION
fi
if [[ -z $CHECK_VERSION ]]; then
CHROME_DEB="google-chrome-stable_${CHROME_VERSION}_$(dpkg --print-architecture).deb"
CHROME_URL="${CHROME_DOWNLOAD_URL_BASE}/${CHROME_VERSION}/${CHROME_DEB}"
echo "Downloading from our Package registry: $CHROME_URL"
curl --silent --show-error --fail -O $CHROME_URL
dpkg -i ./$CHROME_DEB || true
apt-get install -f -y
rm -f $CHROME_DEB
else
echo "Installing via apt-get"
apt-get install -y google-chrome-stable=$CHROME_VERSION
fi
rm -rf /var/lib/apt/lists/*
rm -rf /var/lib/apt/lists/*
# Install ChromeDriver
wget -q https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip
unzip chromedriver_linux64.zip -d /usr/local/bin
rm -f chromedriver_linux64.zip
# Install ChromeDriver
CHROME_VERSION_BASE=$(echo $CHROME_VERSION | awk -F "." '{print $1 "." $2 "." $3}')
CHROME_DRIVER_VERSION=$(curl -q https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION_BASE)
wget -q https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip
unzip chromedriver_linux64.zip -d /usr/local/bin
rm -f chromedriver_linux64.zip
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
rm -rf /etc/apt/sources.list.d/google*.list
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
rm -rf /etc/apt/sources.list.d/google*.list
}
BUILD_OS=${BUILD_OS:-debian}

View file

@ -47,24 +47,19 @@ function print_chrome_args() {
case "$1" in
94|94.0)
CHROME_VERSION=94.0.4606.81-1
CHROME_DRIVER_VERSION=94.0.4606.113
;;
97|97.0)
CHROME_VERSION=97.0.4692.99-1
CHROME_DRIVER_VERSION=97.0.4692.71
;;
99|99.0)
CHROME_VERSION=99.0.4844.74-1
CHROME_DRIVER_VERSION=99.0.4844.51
;;
101|101.0)
CHROME_VERSION=101.0.4951.64-1
CHROME_DRIVER_VERSION=101.0.4951.41
;;
*) echo "Unknown chrome version $1"; exit 1;
esac
printf -- "--build-arg CHROME_VERSION=%s " "$CHROME_VERSION"
printf -- "--build-arg CHROME_DRIVER_VERSION=%s " "$CHROME_DRIVER_VERSION"
}
# see https://www.kernel.org/pub/software/scm/git