Skip to content

Commit

Permalink
try to make chrome work on arm
Browse files Browse the repository at this point in the history
  • Loading branch information
nexxeln committed Feb 19, 2025
1 parent 89c1a55 commit 924a63c
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 58 deletions.
30 changes: 26 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:

jobs:
coverage:
runs-on: blacksmith-4vcpu-ubuntu-2204
runs-on: blacksmith-4vcpu-ubuntu-2204-arm
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
Expand All @@ -20,7 +20,7 @@ jobs:
- run: pnpm test:coverage

build-stateless:
runs-on: blacksmith-4vcpu-ubuntu-2204
runs-on: blacksmith-4vcpu-ubuntu-2204-arm
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
Expand Down Expand Up @@ -85,7 +85,18 @@ jobs:
run: tar -xvf stateless-build.tar

- name: Install playwright
run: npx playwright install chromium
run: |
# Install Playwright browsers with system dependencies
if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then
# Install Chromium from system for ARM
sudo apt-get update
sudo apt-get install -y chromium-browser
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npx playwright install
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium-browser npx playwright install-deps chromium
else
# Regular installation for AMD64
npx playwright install chromium
fi
- name: Run tests
run: |
Expand Down Expand Up @@ -125,7 +136,18 @@ jobs:
run: tar -xvf stateful-build.tar

- name: Install playwright
run: npx playwright install chromium
run: |
# Install Playwright browsers with system dependencies
if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then
# Install Chromium from system for ARM
sudo apt-get update
sudo apt-get install -y chromium-browser
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npx playwright install
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium-browser npx playwright install-deps chromium
else
# Regular installation for AMD64
npx playwright install chromium
fi
- name: Run tests
run: |
Expand Down
136 changes: 82 additions & 54 deletions scripts/check-chrome.sh
Original file line number Diff line number Diff line change
@@ -1,65 +1,93 @@
#!/bin/bash
# Copied and modified from: https://github.com/actions/virtual-environments/issues/5651#issuecomment-1142075171
# Used to ensure that Cypress tests are always using the latest version of Chrome.
# This is important because sometimes when Chrome releases a new version, Github Action runners can run the
# previous version or the new version and when sharding the tests to run in parallel results in this error:
# https://github.com/cypress-io/github-action/issues/518
#!/bin/bash
# Copied and modified from: https://github.com/actions/virtual-environments/issues/5651#issuecomment-1142075171
# Used to ensure that tests are always using the latest version of Chrome.
# This script now handles both ARM64 and AMD64 architectures.

download_with_retries() {
# Due to restrictions of bash functions, positional arguments are used here.
# In case if you using latest argument NAME, you should also set value to all previous parameters.
# Example: download_with_retries $ANDROID_SDK_URL "." "android_sdk.zip"
local URL="$1"
local DEST="${2:-.}"
local NAME="${3:-${URL##*/}}"
local COMPRESSED="$4"
download_with_retries() {
local URL="$1"
local DEST="${2:-.}"
local NAME="${3:-${URL##*/}}"
local COMPRESSED="$4"

if [[ $COMPRESSED == "compressed" ]]; then
local COMMAND="curl $URL -4 -sL --compressed -o '$DEST/$NAME' -w '%{http_code}'"
else
local COMMAND="curl $URL -4 -sL -o '$DEST/$NAME' -w '%{http_code}'"
fi
if [[ $COMPRESSED == "compressed" ]]; then
local COMMAND="curl $URL -4 -sL --compressed -o '$DEST/$NAME' -w '%{http_code}'"
else
local COMMAND="curl $URL -4 -sL -o '$DEST/$NAME' -w '%{http_code}'"
fi

echo "Downloading '$URL' to '${DEST}/${NAME}'..."
retries=20
interval=30
while [ $retries -gt 0 ]; do
((retries--))
# Temporary disable exit on error to retry on non-zero exit code
set +e
http_code=$(eval $COMMAND)
exit_code=$?
if [ $http_code -eq 200 ] && [ $exit_code -eq 0 ]; then
echo "Download completed"
return 0
else
echo "Error — Either HTTP response code for '$URL' is wrong - '$http_code' or exit code is not 0 - '$exit_code'. Waiting $interval seconds before the next attempt, $retries attempts left"
sleep 30
fi
# Enable exit on error back
set -e
done
echo "Downloading '$URL' to '${DEST}/${NAME}'..."
retries=20
interval=30
while [ $retries -gt 0 ]; do
((retries--))
# Temporary disable exit on error to retry on non-zero exit code
set +e
http_code=$(eval $COMMAND)
exit_code=$?
if [ $http_code -eq 200 ] && [ $exit_code -eq 0 ]; then
echo "Download completed"
return 0
else
echo "Error — Either HTTP response code for '$URL' is wrong - '$http_code' or exit code is not 0 - '$exit_code'. Waiting $interval seconds before the next attempt, $retries attempts left"
sleep 30
fi
# Enable exit on error back
set -e
done

echo "Could not download $URL"
return 1
}
echo "Could not download $URL"
return 1
}

INSTALLED_CHROME_VERSION=$(google-chrome --product-version)
# Detect architecture
ARCH=$(uname -m)
echo "Detected architecture: $ARCH"

LATEST_VERSION_URL="https://omahaproxy.appspot.com/linux"
echo "Fetching latest chrome version from: $LATEST_VERSION_URL"
LATEST_CHROME_VERSION=$(curl "$LATEST_VERSION_URL")
# Check if Chrome is installed
if command -v google-chrome &> /dev/null; then
INSTALLED_CHROME_VERSION=$(google-chrome --product-version)
else
INSTALLED_CHROME_VERSION="none"
fi

echo "Installed Chrome Version: $INSTALLED_CHROME_VERSION"
echo "Latest Chrome Version: $LATEST_CHROME_VERSION"
LATEST_VERSION_URL="https://omahaproxy.appspot.com/linux"
echo "Fetching latest chrome version from: $LATEST_VERSION_URL"
LATEST_CHROME_VERSION=$(curl "$LATEST_VERSION_URL")

if [ "$INSTALLED_CHROME_VERSION" == "$LATEST_CHROME_VERSION" ]; then
echo "Installed Chrome Version: $INSTALLED_CHROME_VERSION"
echo "Latest Chrome Version: $LATEST_CHROME_VERSION"

if [ "$INSTALLED_CHROME_VERSION" == "$LATEST_CHROME_VERSION" ]; then
echo "The latest major version of Chrome is already installed."
exit 0
fi
fi

# Install dependencies
echo "Installing dependencies..."
sudo apt-get update
sudo apt-get install -y wget gnupg

# Add Chrome repository and install Chrome based on architecture
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
echo "Installing Chrome for ARM64..."

# For ARM64, we need to use Chromium as Chrome doesn't provide official ARM64 builds
sudo apt-get install -y chromium-browser

# Create symlink to make chromium accessible as google-chrome
sudo ln -sf /usr/bin/chromium-browser /usr/bin/google-chrome

# Install additional dependencies that might be needed
sudo apt-get install -y libnss3 libgbm1 libasound2
else
echo "Installing Chrome for AMD64..."
# Download and install Google Chrome
CHROME_DEB_URL="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
CHROME_DEB_NAME="google-chrome-stable_current_amd64.deb"
download_with_retries $CHROME_DEB_URL "/tmp" "${CHROME_DEB_NAME}"
sudo apt-get install -y "/tmp/${CHROME_DEB_NAME}" -f
fi

# Download and install Google Chrome
CHROME_DEB_URL="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
CHROME_DEB_NAME="google-chrome-stable_current_amd64.deb"
download_with_retries $CHROME_DEB_URL "/tmp" "${CHROME_DEB_NAME}"
sudo apt-get install -y "/tmp/${CHROME_DEB_NAME}" -f
# Verify installation
CHROME_VERSION=$(google-chrome --version)
echo "Installed Chrome/Chromium version: $CHROME_VERSION"

0 comments on commit 924a63c

Please sign in to comment.