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

Use JSON API for chromedriver versions #3

Merged
merged 4 commits into from
Sep 27, 2023
Merged
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
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
Loading