forked from CircleCI-Public/browser-tools-orb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_chrome_for_testing.sh
More file actions
executable file
·103 lines (91 loc) · 4.32 KB
/
install_chrome_for_testing.sh
File metadata and controls
executable file
·103 lines (91 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
retry() {
local -r -i max_attempts=5
local -i attempt_num=1
until "$@"; do
if (( attempt_num == max_attempts )); then
echo "Attempt $attempt_num failed and there are no more attempts left!"
exit 1
else
echo "Attempt $attempt_num failed! Trying again..."
((attempt_num++))
$SUDO rm -rf /var/lib/apt/lists/*
sleep 5
fi
done
}
cd "$ORB_PARAM_DIR" || { echo "$ORB_PARAM_DIR does not exist. Exiting"; exit 1; }
# process ORB_PARAM_VERSION
if command -v circleci &>/dev/null; then
# CircleCI is installed, proceed with substitution
PROCESSED_CHROME_VERSION=$(circleci env subst "$ORB_PARAM_VERSION")
else
# CircleCI is not installed, fallback to using the environment variable as-is
echo "CircleCI CLI is not installed. Relying on the environment variable ORB_PARAM_VERSION to be set manually."
PROCESSED_CHROME_VERSION=${ORB_PARAM_VERSION:-latest} # Default to "latest" if the variable is unset
fi
if uname -a | grep Darwin >/dev/null 2>&1; then
if [[ "$PROCESSED_CHROME_VERSION" == "latest" ]]; then
LATEST_VERSION="$(curl -s 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json' | jq -r '.channels.Stable.version')"
target_version="$LATEST_VERSION"
else
target_version="$PROCESSED_CHROME_VERSION"
fi
$SUDO curl -s -o chrome-for-testing.zip "https://storage.googleapis.com/chrome-for-testing-public/$target_version/mac-arm64/chrome-mac-arm64.zip"
if [ -s "chrome-for-testing.zip" ]; then
$SUDO unzip chrome-for-testing.zip >/dev/null
$SUDO rm chrome-for-testing.zip
$SUDO mv ./chrome-mac-arm64 /opt/chrome-for-testing
# leveraging /opt instead of /Applications/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing as this should be temporary
$SUDO ln -fs /opt/chrome-for-testing/chrome "$ORB_PARAM_DIR/chrome"
else
echo "Version $target_version doesn't exist"
#exit 1
fi
if [ "$ORB_PARAM_INSTALL_CHROMEDRIVER" = true ] ; then
$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"
$SUDO unzip chrome-for-testing-driver.zip >/dev/null 2>&1
$SUDO rm chrome-for-testing-driver.zip
$SUDO mv chromedriver-mac-arm64/chromedriver chromedriver
fi
elif command -v apt >/dev/null 2>&1; then
if [[ "$PROCESSED_CHROME_VERSION" == "latest" ]]; then
LATEST_VERSION="$(curl -s 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json' | jq -r '.channels.Stable.version')"
target_version="$LATEST_VERSION"
else
target_version="$PROCESSED_CHROME_VERSION"
fi
$SUDO curl -s -o chrome-for-testing.zip "https://storage.googleapis.com/chrome-for-testing-public/$target_version/linux64/chrome-linux64.zip"
if [ -s "chrome-for-testing.zip" ]; then
$SUDO unzip chrome-for-testing.zip >/dev/null 2>&1
$SUDO rm chrome-for-testing.zip
$SUDO mv ./chrome-linux64 /opt/chrome-for-testing
$SUDO ln -fs /opt/chrome-for-testing/chrome "$ORB_PARAM_DIR/chrome"
else
echo "Version $target_version doesn't exist"
exit 1
fi
retry $SUDO apt-get update
$SUDO chmod +r /opt/chrome-for-testing/deb.deps
while read -r pkg; do
$SUDO apt-get satisfy -y --no-install-recommends "${pkg}";
done < /opt/chrome-for-testing/deb.deps;
if [ "$ORB_PARAM_INSTALL_CHROMEDRIVER" = true ] ; then
$SUDO curl -s -o chrome-for-testing-driver.zip "https://storage.googleapis.com/chrome-for-testing-public/$target_version/linux64/chromedriver-linux64.zip"
$SUDO unzip chrome-for-testing-driver.zip >/dev/null 2>&1
$SUDO rm chrome-for-testing-driver.zip
$SUDO mv chromedriver-linux64/chromedriver chromedriver
fi
fi
if [ "$ORB_PARAM_INSTALL_CHROMEDRIVER" = true ] ; then
$SUDO chmod +x chromedriver
fi
if [ "$ORB_PARAM_INSTALL_CHROMEDRIVER" = true ] ; then
if chromedriver --version | grep "$target_version" >/dev/null 2>&1; then
echo "chromedriver for Chrome for testing installed correctly"
else
echo "Error installing Chrome for testing"
exit 1
fi
fi