0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-22 06:23:30 +02:00

run playwright via container

This commit is contained in:
TheFox0x7 2026-04-19 21:44:16 +02:00
parent 6f761219b2
commit 85a401fd6d
No known key found for this signature in database
2 changed files with 35 additions and 2 deletions

View File

@ -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

View File

@ -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 "$@"