diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 0000000..10df456 --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,36 @@ +name: E2E Tests + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + e2e: + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - uses: actions/checkout@v4 + + # We use actions/setup-node just to have npm available to run the test script wrapper. + # The actual e2e test runs inside the Docker container. + - name: Use Node.js 22.x + uses: actions/setup-node@v4 + with: + node-version: 22.x + + - name: Enable KVM group perms + # This enables hardware acceleration for the Android emulator inside the Docker container + # since Docker on Linux can pass through /dev/kvm + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + - name: Run E2E tests (Docker) + run: npm run test:e2e:docker + # We need to make sure the docker container can access /dev/kvm if we want hardware acceleration, + # but by default the `test-e2e-docker.sh` might not pass `--device /dev/kvm`... + # Let's check test-e2e-docker.sh again. diff --git a/docker/e2e/Dockerfile b/docker/e2e/Dockerfile index d31fef0..8435ba1 100644 --- a/docker/e2e/Dockerfile +++ b/docker/e2e/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-bookworm +FROM --platform=linux/amd64 node:20-bookworm ENV DEBIAN_FRONTEND=noninteractive ENV ANDROID_SDK_ROOT=/opt/android-sdk @@ -55,6 +55,7 @@ RUN npm ci COPY src ./src COPY test ./test +COPY docs ./docs COPY openpocket ./openpocket COPY openpocket.config.example.json ./openpocket.config.example.json COPY README.md ./README.md diff --git a/scripts/test-e2e-docker.sh b/scripts/test-e2e-docker.sh index 44e147b..d6e910d 100755 --- a/scripts/test-e2e-docker.sh +++ b/scripts/test-e2e-docker.sh @@ -11,7 +11,12 @@ echo "[e2e] Building Docker image: ${IMAGE_TAG}" docker build -f docker/e2e/Dockerfile -t "${IMAGE_TAG}" . echo "[e2e] Running Docker container" -docker run --rm \ - --shm-size="${SHM_SIZE}" \ +DOCKER_RUN_ARGS=(--rm --shm-size="${SHM_SIZE}") +if [ -e /dev/kvm ]; then + echo "[e2e] Hardware virtualization (/dev/kvm) detected. Enabling KVM." + DOCKER_RUN_ARGS+=(--device /dev/kvm) +fi + +docker run "${DOCKER_RUN_ARGS[@]}" \ -e OPENPOCKET_E2E_TASK="${OPENPOCKET_E2E_TASK:-Open Android Settings, then return to the home screen, then finish.}" \ "${IMAGE_TAG}"