diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 0000000..65a979b --- /dev/null +++ b/.github/workflows/e2e.yml @@ -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 diff --git a/e2e/Dockerfile b/e2e/Dockerfile new file mode 100644 index 0000000..5ffadac --- /dev/null +++ b/e2e/Dockerfile @@ -0,0 +1,7 @@ +FROM archlinux + +COPY prepare.sh /tmp +RUN ./tmp/prepare.sh + +USER e2e +WORKDIR /repo diff --git a/e2e/prepare.sh b/e2e/prepare.sh new file mode 100755 index 0000000..9ec642c --- /dev/null +++ b/e2e/prepare.sh @@ -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 diff --git a/e2e/run.sh b/e2e/run.sh new file mode 100755 index 0000000..b71140e --- /dev/null +++ b/e2e/run.sh @@ -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 "hubber-e2e@getbetter.ro" +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 git@github.com: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