Skip to content

Commit

Permalink
feat: add dockerized e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rarescosma committed Oct 28, 2024
1 parent 7ace585 commit 34c8594
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: e2e

on:
workflow_dispatch

permissions:
contents: read

jobs:
test:
name: e2e-test
runs-on: arc-octotail
steps:
- uses: actions/checkout@v4
- name: Env
run: |
env | sort
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Dockerized tests
run: |
docker run --rm -u 1000:1000 -v $(pwd)/e2e:/repo \
-e HUBBER_CREDS="${{ secrets.HUBBER_CREDS }}" \
-e HUBBER_KEY="${{ secrets.HUBBER_KEY }}" \
ghcr.io/rarescosma/octotail-e2e:latest ./run.sh $GITHUB_SHA
7 changes: 7 additions & 0 deletions e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM archlinux

COPY prepare.sh /tmp
RUN ./tmp/prepare.sh

USER e2e
WORKDIR /repo
38 changes: 38 additions & 0 deletions e2e/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -eux

# install sudo
pacman -Sy --quiet --noconfirm sudo vi git binutils fakeroot debugedit openssh oath-toolkit

# install paru
PARU_VERSION=v2.0.4
curl --fail --location "https://github.com/Morganamilo/paru/releases/download/v2.0.4/paru-${PARU_VERSION}-x86_64.tar.zst" --output /tmp/paru.tar.zst
tar --directory "/usr/local/bin" -xvf "/tmp/paru.tar.zst" --wildcards "paru"
rm /tmp/paru.tar.zst

chmod -R +x /usr/local/bin

# add an user
USER_NAME=e2e
useradd -m $USER_NAME

# god mode
grep -q $USER_NAME /etc/sudoers || {
echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" | EDITOR='tee -a' visudo
}

# install chromium + uv/uvx + gh
sudo -u $USER_NAME bash -x -c "paru -S --noconfirm ungoogled-chromium-bin uv github-cli; uv python install 3.12"

# yolo ssh
mkdir -p /home/$USER_NAME/.ssh
cat << __EOF__ > /home/${USER_NAME}/.ssh/config
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
LogLevel ERROR
__EOF__
chown -R ${USER_NAME}: /home/$USER_NAME/.ssh

rm -rf /var/cache /var/lib/pacman /home/$USER_NAME/.cache
52 changes: 52 additions & 0 deletions e2e/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -euo pipefail

DOT=$(cd -P "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)
sudo chown -R $(id -u):$(id -g) $DOT

OCTOTAIL_REF="${1:-main}"

UVX="uvx --from=git+https://github.com/rarescosma/octotail.git@${OCTOTAIL_REF}"

# generate mitmproxy cert and trust it
sudo trust anchor "$($UVX octotailx generate-cert)"

test -d octotail-e2e && rm -rf octotail-e2e

# git setup
git config --global user.email "[email protected]"
git config --global user.name "hubber-e2e-gb"
echo $HUBBER_KEY | base64 -d >$HOME/.ssh/id_rsa
chmod 400 $HOME/.ssh/id_rsa

git clone [email protected]:getbettr/octotail-e2e.git

# push an empty commit
pushd octotail-e2e
git commit --allow-empty -m "$(date "+%F@%T") e2e trigger"
git push origin --force

# octotail setup
echo $HUBBER_CREDS | base64 -d >/tmp/hubber-creds
source /tmp/hubber-creds
rm -f /tmp/hubber-creds
export OCTOTAIL_GH_OTP="$(eval $OCTOTAIL_GH_OTP_CMD | tr -d '\n')"
export DEBUG=1
export PYTHONUNBUFFERED=1

# look for marker and cancel ongoing run
CANCELLED=""
while IFS= read -r line; do
echo "[octotail]: $line"
if [[ "$line" == *"%%octotail_marker%%"* ]] && test -z "$CANCELLED"; then
# remove colors with sed
RUN_ID="$(echo ${line##*: } | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g")"
echo "[run.sh]: Marker found! Run ID is: $RUN_ID"
gh auth login --with-token < <(echo $OCTOTAIL_GH_PAT)
gh run cancel $RUN_ID
CANCELLED=1
fi
done < <($UVX octotail $(git rev-parse HEAD))

wait

0 comments on commit 34c8594

Please sign in to comment.