Skip to content

Commit 03c7d6f

Browse files
authored
feat: allow for version to be optional and discover the latest version (#138)
of Chrome for Testing and install it
1 parent 87bfa23 commit 03c7d6f

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

.circleci/test-deploy.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ jobs:
1818
- browser-tools/install_chrome_for_testing:
1919
version: <<parameters.version >>
2020
- checkout
21+
int-chrome-for-testing-no-args:
22+
parameters:
23+
executor:
24+
type: executor
25+
executor: <<parameters.executor >>
26+
steps:
27+
- browser-tools/install_chrome_for_testing
28+
- checkout
2129
int-test-all:
2230
parameters:
2331
executor:
@@ -242,7 +250,13 @@ workflows:
242250
alias: install_chrome_for_testing
243251
parameters:
244252
executor: [cimg-base, linux, macos]
245-
version: ["136.0.7103.113", "137.0.7151.40"]
253+
version: ["136.0.7103.113", "137.0.7151.40", "latest"]
254+
- int-chrome-for-testing-no-args:
255+
name: install_chrome_for_testing_no_args-<<matrix.executor>>
256+
matrix:
257+
alias: install_chrome_for_testing_no_args
258+
parameters:
259+
executor: [cimg-base, linux, macos]
246260
- orb-tools/pack:
247261
filters: *filters
248262
# This matrix job can likely replace the several others above in the future

src/commands/install_chrome_for_testing.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ description: >
66
parameters:
77
version:
88
type: string
9+
default: "latest"
910
description: >
10-
Which version to install. No default version provided, you must specify the one you want.
11+
Which version to install. If none provided, the latest available will be installed.
1112
1213
install_dir:
1314
type: string

src/scripts/install_chrome_for_testing.sh

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,50 @@ if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
33

44
cd "$ORB_PARAM_DIR" || { echo "$ORB_PARAM_DIR does not exist. Exiting"; exit 1; }
55

6-
if [ -z "$ORB_PARAM_VERSION" ]; then
7-
echo "ORB_PARAM_VERSION is not set. Exiting."
8-
exit 1
6+
# process ORB_PARAM_VERSION
7+
if command -v circleci &>/dev/null; then
8+
# CircleCI is installed, proceed with substitution
9+
PROCESSED_CHROME_VERSION=$(circleci env subst "$ORB_PARAM_VERSION")
10+
else
11+
# CircleCI is not installed, fallback to using the environment variable as-is
12+
echo "CircleCI CLI is not installed. Relying on the environment variable ORB_PARAM_VERSION to be set manually."
13+
PROCESSED_CHROME_VERSION=${ORB_PARAM_VERSION:-latest} # Default to "latest" if the variable is unset
914
fi
1015

1116
if uname -a | grep Darwin >/dev/null 2>&1; then
12-
$SUDO curl -s -o chrome-for-testing.zip "https://storage.googleapis.com/chrome-for-testing-public/$ORB_PARAM_VERSION/mac-arm64/chrome-mac-arm64.zip"
17+
if [[ "$PROCESSED_CHROME_VERSION" == "latest" ]]; then
18+
LATEST_VERSION="$(curl -s 'https://chromiumdash.appspot.com/fetch_releases?channel=Stable&platform=Mac' | jq -r ' .[0] | .version ')"
19+
target_version="$LATEST_VERSION"
20+
else
21+
target_version="$PROCESSED_CHROME_VERSION"
22+
fi
23+
24+
$SUDO curl -s -o chrome-for-testing.zip "https://storage.googleapis.com/chrome-for-testing-public/$target_version/mac-arm64/chrome-mac-arm64.zip"
1325
if [ -s "chrome-for-testing.zip" ]; then
1426
$SUDO unzip chrome-for-testing.zip >/dev/null 2>&1
1527
else
16-
echo "Version $ORB_PARAM_VERSION doesn't exist"
17-
exit 1
28+
echo "Version $target_version doesn't exist"
29+
#exit 1
1830
fi
1931

2032
if [ "$ORB_PARAM_INSTALL_CHROMEDRIVER" = true ] ; then
21-
$SUDO curl -s -o chrome-for-testing-driver.zip "https://storage.googleapis.com/chrome-for-testing-public/$ORB_PARAM_VERSION/mac-arm64/chromedriver-mac-arm64.zip"
33+
$SUDO curl -s -o chrome-for-testing-driver.zip "https://storage.googleapis.com/chrome-for-testing-public/$target_version/mac-arm64/chromedriver-mac-arm64.zip"
2234
$SUDO unzip chrome-for-testing-driver.zip >/dev/null 2>&1
2335
$SUDO mv chromedriver-mac-arm64/chromedriver chromedriver
2436
fi
2537
elif command -v apt >/dev/null 2>&1; then
26-
$SUDO curl -s -o chrome-for-testing.zip "https://storage.googleapis.com/chrome-for-testing-public/$ORB_PARAM_VERSION/linux64/chrome-linux64.zip"
38+
if [[ "$PROCESSED_CHROME_VERSION" == "latest" ]]; then
39+
LATEST_VERSION="$(curl -s 'https://chromiumdash.appspot.com/fetch_releases?channel=Stable&platform=Linux' | jq -r ' .[0] | .version ')"
40+
target_version="$LATEST_VERSION"
41+
else
42+
target_version="$PROCESSED_CHROME_VERSION"
43+
fi
44+
45+
$SUDO curl -s -o chrome-for-testing.zip "https://storage.googleapis.com/chrome-for-testing-public/$target_version/linux64/chrome-linux64.zip"
2746
if [ -s "chrome-for-testing.zip" ]; then
2847
$SUDO unzip chrome-for-testing.zip >/dev/null 2>&1
2948
else
30-
echo "Version $ORB_PARAM_VERSION doesn't exist"
49+
echo "Version $target_version doesn't exist"
3150
exit 1
3251
fi
3352
$SUDO apt-get update
@@ -36,7 +55,7 @@ elif command -v apt >/dev/null 2>&1; then
3655
done < chrome-linux64/deb.deps;
3756

3857
if [ "$ORB_PARAM_INSTALL_CHROMEDRIVER" = true ] ; then
39-
$SUDO curl -s -o chrome-for-testing-driver.zip "https://storage.googleapis.com/chrome-for-testing-public/$ORB_PARAM_VERSION/linux64/chromedriver-linux64.zip"
58+
$SUDO curl -s -o chrome-for-testing-driver.zip "https://storage.googleapis.com/chrome-for-testing-public/$target_version/linux64/chromedriver-linux64.zip"
4059
$SUDO unzip chrome-for-testing-driver.zip >/dev/null 2>&1
4160
$SUDO mv chromedriver-linux64/chromedriver chromedriver
4261
fi
@@ -47,7 +66,7 @@ if [ "$ORB_PARAM_INSTALL_CHROMEDRIVER" = true ] ; then
4766
fi
4867

4968
if [ "$ORB_PARAM_INSTALL_CHROMEDRIVER" = true ] ; then
50-
if chromedriver --version | grep "$ORB_PARAM_VERSION" >/dev/null 2>&1; then
69+
if chromedriver --version | grep "$target_version" >/dev/null 2>&1; then
5170
echo "chromedriver for Chrome for testing installed correctly"
5271
else
5372
echo "Error installing Chrome for testing"

0 commit comments

Comments
 (0)