Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add e2e runner container and GHA to build and publish #4860

Closed
Closed
30 changes: 30 additions & 0 deletions .github/workflows/publish-e2e-img.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build and Publish E2E Container
on:
pull_request:
branches:
- master
push:
branches:
- master
paths:
- 'apps/desktop/e2e/Dockerfile'

jobs:
docker_publish:
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push container image
uses: docker/build-push-action@v6
with:
context: "apps/desktop/e2e"
push: true
tags: ghcr.io/gitbutlerapp/e2e-runner:latest
38 changes: 5 additions & 33 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
test:
name: Run WebdriverIO Tests
runs-on: ubuntu-latest
container:
image: ghcr.io/gitbutlerapp/e2e-runner:latest
env:
CARGO_TERM_COLOR: always
steps:
Expand All @@ -22,44 +24,14 @@ jobs:
if: ${{ github.event_name == 'workflow_dispatch' }}
with:
ref: ${{ github.event.inputs.sha }}
- name: Install Tauri OS dependencies
run: |
sudo apt update && sudo apt install -y \
libgtk-3-dev \
libayatana-appindicator3-dev \
libwebkit2gtk-4.0-dev \
webkit2gtk-driver \
ffmpeg \
xvfb
- name: Setup rust-toolchain stable
id: rust-toolchain
uses: dtolnay/rust-toolchain@stable
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: cargo-
- name: Setup node environment
uses: ./.github/actions/init-env-node
- name: Build CLI
run: cargo build -p gitbutler-cli
- name: Build SvelteKit
run: pnpm build:desktop -- --mode development
run: |
pnpm install
pnpm build:desktop -- --mode development
- name: Build Tauri
run: pnpm build:test
- name: Install tauri-driver
run: |
if [ ! -e "$HOME/.cargo/bin/tauri-driver" ]; then
cargo install [email protected]
fi

# Run it through `xvfb-run` to have a fake display server which allows our
# application to run headless without any changes to the code
- name: WebdriverIO
run: xvfb-run pnpm test:e2e

Expand Down
89 changes: 89 additions & 0 deletions apps/desktop/e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Container for running E2E tests on MacOS
#
# 1. docker build --tag gitbutler/e2e:latest
# 2. docker run --name e2e-agent --detach -p 2222:22 -v $GITBUTLER_REPO:/root/gitbutler \
# -v /tmp/e2e-pnpm-store:/tmp/pnpm-store gitbutler/e2e:latest
# 3. docker cp -a ~/.ssh/id_ed25519.pub e2e-agent:/root/.ssh/authorized_keys
# 4. ssh -p 2222 -Y root@localhost
# The rest is run inside the container in your SSH session:
# 5. cd /root/gitbutler
# 6. pnpm install && cargo build
# 7. cargo build -p gitbutler-git && cargo build -p gitbutler-cli
# 8. pnpm build:test
# 9. pnpm test:e2e

FROM ubuntu:22.04

RUN apt update && \
apt install -y \
build-essential \
curl \
git \
pkg-config \
psmisc \
vim && \
# Clean up
apt -y autoremove && apt -y clean

# Install Tauri dependencies
# v1: https://v1.tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux
# v2: https://v2.tauri.app/start/prerequisites/#linux
RUN apt install -y \
libwebkit2gtk-4.0-dev \
build-essential \
curl \
wget \
libssl-dev \
libgtk-3-dev \
libayatana-appindicator3-dev \
librsvg2-dev && \
# Clean up
apt -y autoremove && apt -y clean

# Install tauri-driver dependencies
RUN apt install -y \
dbus-x11 \
webkit2gtk-driver \
xvfb && \
# Clean up
apt -y autoremove && apt -y clean

# Install ssh server for X11 forwarding
RUN apt install -y openssh-server && \
# Needed for recording test execution.
apt install -y ffmpeg && \
# Install gitbutler dependencies
apt install -y cmake && \
# Clean up
apt -y autoremove && apt -y clean

# Needed by at least pnpm.
ENV SHELL=bash

# Install rust.
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Install node.
RUN curl -fsSL "https://deb.nodesource.com/setup_20.x" | bash - && \
apt install -y nodejs && \
corepack enable

# Install pnpm and configure store directory.
ENV PNPM_HOME=/tmp/.pnpm
RUN wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.bashrc" SHELL="$(which bash)" bash -
# Home/store dir should be mounted from the host.
RUN pnpm config set store-dir /tmp/.pnpm
ENV PATH="/tmp/.pnpm:${PATH}"
RUN pnpm setup

# Used to manage build dependencies between packages.
RUN pnpm add --global turbo && \
# Used as a proxy for communicating with WebKitWebDriver.
cargo install tauri-driver && \
# Make `tauri-driver` more widely available
ln -s /root/.cargo/bin/tauri-driver /usr/local/bin/tauri-driver && \
# vi bindings on by default.
echo "set -o vi" >> /root/.bashrc

CMD ["/bin/bash"]
10 changes: 7 additions & 3 deletions apps/desktop/wdio.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ export const config: Options.WebdriverIO = {
},

// ensure we are running `tauri-driver` before the session starts so that we can proxy the webdriver requests
beforeSession: () =>
(tauriDriver = spawn(path.resolve(os.homedir(), '.cargo', 'bin', 'tauri-driver'), [], {
beforeSession: () => {
const tauriDriverPath = process.env.CI
? '/usr/local/bin/tauri-driver'
: path.resolve(os.homedir(), '.cargo', 'bin', 'tauri-driver');
tauriDriver = spawn(tauriDriverPath, [], {
stdio: [null, process.stdout, process.stderr]
})),
});
},

afterSession: () => {
tauriDriver.kill();
Expand Down
Loading