Skip to content

Commit

Permalink
Use JSON API for chromedriver versions (#3)
Browse files Browse the repository at this point in the history
* Use JSON API for chromedriver versions
* Use sed/grep for listing versions

---------

Co-authored-by: Matthew Schinckel <matt@schinckel.net>
  • Loading branch information
sax and schinckel authored Sep 27, 2023
1 parent c7627ff commit 8ce131a
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for chromedriver.
SOURCE="http://chromedriver.storage.googleapis.com"
SOURCE="https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
TOOL_NAME="chromedriver"
TOOL_TEST="chromedriver --help"

Expand All @@ -18,14 +18,12 @@ platform() {
ARCH=$(uname -m)
PLATFORM=$(uname)

if [[ $ARCH = "arm64" ]]; then
NAME=chromedriver_mac_arm64
elif [[ $ARCH = "x86_64" ]]; then
if [[ $PLATFORM = "Darwin" ]]; then
NAME=chromedriver_mac64
else
NAME=chromedriver_linux64
fi
if [[ $ARCH = "arm64" && $PLATFORM = "Darwin" ]]; then
NAME=mac-arm64
elif [[ $ARCH = "x86_64" && $PLATFORM = "Darwin" ]]; then
NAME=mac-x64
else
NAME=linux64
fi
echo "$NAME"
}
Expand All @@ -35,17 +33,21 @@ sort_versions() {
LC_ALL=C sort -n -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

rdom() {
local IFS=\>
read -r -d \< E C
list_all_versions() {
curl -s "$SOURCE" \
| sed 's/[,\[]/\n/g' \
| sed 's/{//g' \
| grep '"version":' \
| sed 's/"version":"\(.*\)"/\1/g' \
| sort_versions
}

list_all_versions() {
curl -s "$SOURCE" | while rdom; do
if [[ $E = "Key" ]]; then
echo "$C"
fi
done | grep "$(platform)" | cut -d '/' -f 1 | sort_versions
release_url() {
local version platform
version="$1"
platform="$2"

curl -s "$SOURCE" | jq -r ".versions[] | select(.version == \"$version\") | .downloads.chromedriver[] | select(.platform == \"$platform\") | .url"
}

download_release() {
Expand All @@ -54,7 +56,8 @@ download_release() {
filename="$2"

# TODO: Adapt the release URL convention for chromedriver
url="${SOURCE}/${version}/$(platform).zip"
# url="${SOURCE}/${version}/$(platform).zip"
url=$(release_url $version $(platform))

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -71,7 +74,7 @@ install_version() {

(
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/chromedriver-$(platform)/* "$install_path"

# TODO: Assert chromedriver executable exists.
local tool_cmd
Expand Down

0 comments on commit 8ce131a

Please sign in to comment.