Skip to content

Commit

Permalink
feat: support Google Chrome betas (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelicianoTech authored Jul 21, 2022
1 parent 2d14282 commit 2c499a8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
23 changes: 23 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ jobs:
firefox-version: <<parameters.firefox-version>>
replace-existing-chrome: <<parameters.replace-existing-chrome>>
chrome-version: <<parameters.chrome-version>>
int-tests-chrome:
parameters:
executor:
type: executor
channel:
type: string
executor: << parameters.executor >>
steps:
- jq/install
- browser-tools/install-chrome:
channel: << parameters.channel >>
int-test-chrome:
parameters:
executor:
Expand Down Expand Up @@ -142,6 +153,18 @@ workflows:
filters: *filters
- orb-tools/pack:
filters: *filters
# This matrix job can likely replace the several others above in the future
- int-tests-chrome:
matrix:
parameters:
executor:
- "cimg-base"
- "cimg-node"
- "linux"
- "macos"
channel:
- "stable"
- "beta"
- orb-tools/publish:
orb-name: circleci/browser-tools
vcs-type: << pipeline.project.type >>
Expand Down
7 changes: 7 additions & 0 deletions src/commands/install-chrome.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ parameters:
e.g., 85.0.4183.83
Only supported on centos and debian
If replace-existing is false, this version is ignored.
channel:
description: |
The release channel of Google Chrome to use. Defaults to 'stable'.
type: enum
enum: [ "stable", "beta" ]
default: "stable"

steps:
- run:
name: Install Google Chrome
environment:
ORB_PARAM_CHROME_VERSION: <<parameters.chrome-version>>
ORB_PARAM_REPLACE_EXISTING: <<parameters.replace-existing>>
ORB_PARAM_CHANNEL: << parameters.channel >>
command: <<include(scripts/install-chrome.sh)>>
38 changes: 21 additions & 17 deletions src/scripts/install-chrome.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,28 @@ fi
if uname -a | grep Darwin >/dev/null 2>&1; then
echo "Preparing Chrome installation for MacOS-based systems"
# Universal MacOS .pkg with license pre-accepted: https://support.google.com/chrome/a/answer/9915669?hl=en
CHROME_MAC_URL="https://dl.google.com/chrome/mac/stable/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg"
CHROME_MAC_URL="https://dl.google.com/chrome/mac/${ORB_PARAM_CHANNEL}/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg"
CHROME_TEMP_DIR="$(mktemp -d)"
curl -L -o "$CHROME_TEMP_DIR/googlechrome.pkg" "$CHROME_MAC_URL"
sudo /usr/sbin/installer -pkg "$CHROME_TEMP_DIR/googlechrome.pkg" -target /
sudo rm -rf "$CHROME_TEMP_DIR"
xattr -rc "/Applications/Google Chrome.app"
echo '#!/usr/bin/env bash' >> google-chrome
echo '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome "$@"' >> google-chrome
sudo mv google-chrome /usr/local/bin/
sudo chmod +x /usr/local/bin/google-chrome
echo '#!/usr/bin/env bash' >> google-chrome-$ORB_PARAM_CHANNEL
if [[ $ORB_PARAM_CHANNEL == "beta" ]]; then
xattr -rc "/Applications/Google Chrome Beta.app"
echo '/Applications/Google\ Chrome\ Beta.app/Contents/MacOS/Google\ Chrome\ Beta "$@"' >> google-chrome-$ORB_PARAM_CHANNEL
else
xattr -rc "/Applications/Google Chrome.app"
echo '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome "$@"' >> google-chrome-$ORB_PARAM_CHANNEL
fi
sudo mv google-chrome-$ORB_PARAM_CHANNEL /usr/local/bin/
sudo chmod +x /usr/local/bin/google-chrome-$ORB_PARAM_CHANNEL
# test/verify installation
if google-chrome --version >/dev/null 2>&1; then
echo "$(google-chrome --version)has been installed in the /Applications directory"
if google-chrome-$ORB_PARAM_CHANNEL --version >/dev/null 2>&1; then
echo "$(google-chrome-$ORB_PARAM_CHANNEL --version)has been installed in the /Applications directory"
echo "A shortcut has also been created at $(command -v google-chrome)"
exit 0
else
echo "Something went wrong; Google Chrome could not be installed"
echo "The latest release of Google Chrome (${ORB_PARAM_CHANNEL}) failed to install."
exit 1
fi
elif command -v yum >/dev/null 2>&1; then
Expand All @@ -84,7 +89,7 @@ elif command -v yum >/dev/null 2>&1; then
if [[ "$ORB_PARAM_CHROME_VERSION" == "latest" ]]; then
CHROME_URL="https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm"
else
CHROME_URL="https://dl.google.com/linux/chrome/rpm/stable/x86_64/google-chrome-stable-$ORB_PARAM_CHROME_VERSION-1.x86_64.rpm"
CHROME_URL="https://dl.google.com/linux/chrome/rpm/stable/x86_64/google-chrome-${ORB_PARAM_CHANNEL}-$ORB_PARAM_CHROME_VERSION-1.x86_64.rpm"
fi
curl --silent --show-error --location --fail --retry 3 \
--output google-chrome.rpm \
Expand All @@ -111,31 +116,30 @@ else
$SUDO sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
fi
$SUDO apt-get update
$SUDO apt-get install -y google-chrome-stable
$SUDO apt-get install -y google-chrome-${ORB_PARAM_CHANNEL}
else
# Google does not keep older releases in their PPA, but they can be installed manually. HTTPS should be enough to secure the download.
wget --no-verbose -O /tmp/chrome.deb "https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${ORB_PARAM_CHROME_VERSION}-1_amd64.deb" \
&& $SUDO apt-get install -y /tmp/chrome.deb \
&& rm /tmp/chrome.deb
fi
$SUDO sed -i 's|HERE/chrome"|HERE/chrome" --disable-setuid-sandbox --no-sandbox|g' "/opt/google/chrome/google-chrome"
fi

# test/verify installation
if [[ "$ORB_PARAM_CHROME_VERSION" != "latest" ]]; then
if google-chrome --version | grep "$ORB_PARAM_CHROME_VERSION" >/dev/null 2>&1; then
if google-chrome-$ORB_PARAM_CHANNEL --version | grep "$ORB_PARAM_CHROME_VERSION" >/dev/null 2>&1; then
:
else
echo "Something went wrong; Google Chrome could not be installed"
echo "Google Chrome v${ORB_PARAM_CHROME_VERSION} (${ORB_PARAM_CHANNEL}) failed to install."
exit 1
fi
else
if google-chrome --version >/dev/null 2>&1; then
if google-chrome-$ORB_PARAM_CHANNEL --version >/dev/null 2>&1; then
:
else
echo "Something went wrong; Google Chrome could not be installed"
echo "The latest release of Google Chrome (${ORB_PARAM_CHANNEL}) failed to install."
exit 1
fi
echo "$(google-chrome --version) has been installed to $(command -v google-chrome)"
echo "$(google-chrome-$ORB_PARAM_CHANNEL --version) has been installed to $(command -v google-chrome-$ORB_PARAM_CHANNEL)"
echo "Chrome: $ORB_PARAM_CHROME_VERSION" >>"${HOME}/.browser-versions"
fi

0 comments on commit 2c499a8

Please sign in to comment.