From 947a84e6c1d25f005994d796072922d26db04a01 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 19 May 2026 14:25:19 +0800 Subject: [PATCH] fix(ci): clean root-owned pytest cache artifacts --- .gitea/workflows/cd.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/cd.yaml b/.gitea/workflows/cd.yaml index 20a76dcf..9a7dc4f7 100644 --- a/.gitea/workflows/cd.yaml +++ b/.gitea/workflows/cd.yaml @@ -159,6 +159,13 @@ jobs: fi cd apps/api + cleanup_pytest_workspace_cache() { + # 2026-05-19 Codex: CI image runs as root against a bind-mounted + # checkout. Remove Python cache artifacts before act-runner cleanup + # so successful jobs do not end with root-owned __pycache__ noise. + find tests -type d -name __pycache__ -prune -exec rm -rf {} + 2>/dev/null || true + rm -rf .pytest_cache 2>/dev/null || true + } # CI 排除需外部服務的測試 (Redis pool / Ollama — 2026-04-01 Claude Code) # 2026-04-05 Claude Code: 修正 exit code — | tail 會吃掉 segfault (exit 139) # 改用 tee + PIPESTATUS[0] 正確捕捉 pytest 本身的 exit code @@ -182,6 +189,7 @@ jobs: --ignore=tests/e2e_network_test.py \ 2>&1 | tee /tmp/pytest-output.txt; PYTEST_EXIT=${PIPESTATUS[0]} tail -60 /tmp/pytest-output.txt + cleanup_pytest_workspace_cache exit $PYTEST_EXIT CI_SCRIPT docker run --rm \ @@ -246,9 +254,11 @@ jobs: # 2026-04-22 ogt: DATABASE_URL 改為必填後,import chain 需要此 env var 讓 Settings 通過驗證 DATABASE_URL="postgresql+asyncpg://awoooi:awoooi_test_2026@pg-test-b5:5432/awoooi_test?ssl=disable" \ TEST_DATABASE_URL="postgresql+asyncpg://awoooi:awoooi_test_2026@pg-test-b5:5432/awoooi_test?ssl=disable" \ - /opt/api-venv/bin/pytest tests/integration/test_b5_core_flows.py -v --tb=short -m integration + /opt/api-venv/bin/pytest tests/integration/test_b5_core_flows.py -v --tb=short -m integration || PYTEST_EXIT=$? # 清理 docker rm -f pg-test-b5 || true + find tests/integration -type d -name __pycache__ -prune -exec rm -rf {} + 2>/dev/null || true + exit "${PYTEST_EXIT:-0}" CI_SCRIPT docker run --rm \ --name "awoooi-cd-${GITHUB_RUN_ID:-manual}-${GITHUB_RUN_ATTEMPT:-1}-b5-tests" \