How do I configure Cypress’s custom action to run on self-hosted runners?

I currently have a GitHub Actions setup and run my Cypress integration tests against the default Github runner. This works well, but is becoming expensive.

I run other checks using self-hosted runners on AWS EC2 configured using the Philips Terraform Self-Hosted Runner for AWS, which works well and generally accomplishes the cost-savings we were looking for.

The issue is that the Cypress preconfigured runner expects a handful of dependencies to exist on the runner. Cypress docs do not provide any preconfigured setup for self-hosted runners, as the provided default GitHub runner already has all dependencies that Cypress expects, specifically Chrome browser (or whatever browser(s) you want to automate Cypress against).

There are preconfigured Chrome and Node/npm install actions, which would have worked, but they give the following error when run on Amazon’s flavor of Fedora Linux:

Unsupported OS: amzn

How can I set up these dependencies in order to run Cypress on my self-hosted runners?

Solution:

The following commands allowed me to successfully run my Cypress tests against Chrome in my self-hosted AWS runners. I modified my Terraform config to setup these resources on every runner; This is not mandatory and could be done on a per-job basis, or manually on each runner if your runners aren’t automated. Regardless, these are the commands to setup the necessary dependencies on a given machine:

# setup AWS runner (not needed for cypress, just for my specific GH Actions + AWS runner setup
    wget https://github.com/cli/cli/releases/download/v2.39.2/gh_2.39.2_linux_amd64.rpm
    sudo rpm -i gh_2.39.2_linux_amd64.rpm
# Install Cypress dependencies
    sudo yum install -y xorg-x11-server-Xvfb gtk3-devel libnotify-devel nss libXScrnSaver alsa-lib
# Install NPM for test setup
    sudo yum install -y nodejs npm
# Download Chrome and install
    export BROWSERS_SRC_DIR="/usr/src/browsers"
    mkdir -p $BROWSERS_SRC_DIR
    sudo curl https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm --output $BROWSERS_SRC_DIR/google-chrome-stable_current_x86_64.rpm
    sudo yum install -y -q $BROWSERS_SRC_DIR/google-chrome-stable_current_x86_64.rpm

How I got to that:

While the Cypress Github actions repo docs do not have info about the runner dependencies (or anything self-hosted related), @alexandroid’s answer led me to the Cypress linux prerequisites, which was the first necessary component:

sudo yum install -y xorg-x11-server-Xvfb gtk3-devel libnotify-devel nss libXScrnSaver alsa-lib

The second was actually getting chrome installed. There were several false leads here (Specifically, no answer using the dnf tool seems to work on the Amazon linux, resulting in errors like Error: No matching repo to modify: google-chrome). Ultimately the solution that worked was pulled directly from @alexandroid’s answer, using a similar approach to the much, much easier to find answers on this general Linux question about installing Chrome via CLI, but adapting it to pulling the RPM image for Amazon Linux specifically:

export BROWSERS_SRC_DIR="/usr/src/browsers"
mkdir -p $BROWSERS_SRC_DIR
sudo curl https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm --output $BROWSERS_SRC_DIR/google-chrome-stable_current_x86_64.rpm
sudo yum install -y -q $BROWSERS_SRC_DIR/google-chrome-stable_current_x86_64.rpm

The final piece was a combination of Matthew Herbst’s and Tim Fulmer’s answers to install Node/NPM:

sudo yum install -y nodejs npm

Combining these, I was able to successfully run my Cypress tests automatically via Github Actions on self-hosted runners in AWS EC2, with the following job configuration:

jobs:
  cypress-run:
    runs-on: self-hosted
    steps:
      - name: Checkout
        uses: actions/checkout@master
      - name: Install dependencies
        uses: cypress-io/github-action@v5
        with:
          working-directory: web
          # just perform install
          runTests: false
      - name: Run e2e tests
        uses: cypress-io/github-action@v5
        with:
          # we have already installed all dependencies above
          install: false
          browser: chrome
          spec: cypress/ci/**/*.ts

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật