diff --git a/Makefile b/Makefile index 0e4d68bffe0..136b0ef9737 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1 ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1.7.11 +CONTAINER_RUNTIME ?= docker DOCKER_IMAGE ?= gitea/gitea DOCKER_TAG ?= latest DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG) @@ -521,7 +522,7 @@ playwright: deps-frontend @pnpm exec playwright install --with-deps chromium firefox webkit $(PLAYWRIGHT_FLAGS) .PHONY: test-e2e -test-e2e: playwright $(EXECUTABLE_E2E) +test-e2e: $(EXECUTABLE_E2E) @EXECUTABLE=$(EXECUTABLE_E2E) ./tools/test-e2e.sh $(GITEA_TEST_E2E_FLAGS) .PHONY: bench-sqlite diff --git a/tools/test-e2e.sh b/tools/test-e2e.sh index 39405387b5b..b4f7d8e1c89 100755 --- a/tools/test-e2e.sh +++ b/tools/test-e2e.sh @@ -1,6 +1,30 @@ #!/bin/bash set -euo pipefail +wait_for_container() { + local max_attempts=$1 + local attempt=1 + local wait_time=1 + sleep 5 # give the container some time to start listening. + + while [ $attempt -le $max_attempts ]; do + if $CONTAINER_RUNTIME logs gitea-e2e-runner 2>&1 | grep -q "Listening on"; then + echo "Container is ready." + return 0 # Success + fi + + if [ $attempt -eq $max_attempts ]; then + echo "Error: Container did not become ready after $max_attempts attempts." + return 1 # Failure + fi + + echo "Attempt $attempt: Container not ready, waiting $wait_time second(s)..." + sleep $wait_time + ((attempt++)) + ((wait_time*=2)) # Exponential backoff + done +} + # Create isolated work directory WORK_DIR=$(mktemp -d) @@ -8,6 +32,7 @@ WORK_DIR=$(mktemp -d) FREE_PORT=$(node -e "const s=require('net').createServer();s.listen(0,'127.0.0.1',()=>{process.stdout.write(String(s.address().port));s.close()})") cleanup() { + $CONTAINER_RUNTIME stop gitea-e2e-runner if [ -n "${SERVER_PID:-}" ]; then kill "$SERVER_PID" 2>/dev/null || true wait "$SERVER_PID" 2>/dev/null || true @@ -15,6 +40,13 @@ cleanup() { rm -rf "$WORK_DIR" } trap cleanup EXIT +# Start playwright worker +$CONTAINER_RUNTIME run --network=host --name gitea-e2e-runner -d --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.59.1-noble /bin/sh -c "npx -y playwright@1.59.1 run-server --port 4000 --host 0.0.0.0" + +if ! wait_for_container 5; then + exit 1 +fi + # Write config file for isolated instance mkdir -p "$WORK_DIR/custom/conf" @@ -112,4 +144,4 @@ export GITEA_TEST_E2E_PASSWORD export GITEA_TEST_E2E_EMAIL export GITEA_TEST_E2E_TIMEOUT_FACTOR -pnpm exec playwright test "$@" +PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:4000/ pnpm exec playwright test "$@"