fix(cd): run tests in explicit ci container
This commit is contained in:
@@ -39,13 +39,15 @@ env:
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: http://192.168.0.188:24318
|
||||
OTEL_SERVICE_NAME: awoooi-cd
|
||||
OTEL_RESOURCE_ATTRIBUTES: service.version=${{ github.sha }},deployment.environment=production
|
||||
CI_IMAGE: 192.168.0.110:5000/awoooi/ci-runner:act-22.04
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
# 2026-04-02 ogt: Gitea runner label 是 ubuntu-latest (非 GitHub 的 self-hosted)
|
||||
# ADR-039 鐵律: 使用自建 runner,但 Gitea label matching 不同於 GitHub
|
||||
# 2026-04-30 Codex: run the tests job on the host runner and launch the
|
||||
# CI image explicitly. The act-managed job container can disappear mid-test
|
||||
# with Docker RWLayer=nil on the shared 110 daemon.
|
||||
timeout-minutes: 30
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: awoooi-host
|
||||
# 2026-04-10 ogt: B5 改用 docker run 本地啟動,移除 services: 宣告
|
||||
# Gitea act runner 的 services: container name 為空,導致 CI 失敗
|
||||
steps:
|
||||
@@ -69,8 +71,9 @@ jobs:
|
||||
COMMIT_ESC=$(echo "$COMMIT_MSG" | sed 's/&/\&/g; s/</\</g; s/>/\>/g')
|
||||
MSG=$(printf '🚀 <b>AWOOOI 部署開始</b>\n├ 📝 <code>%s</code>\n├ 🔖 <code>%s</code>\n└ 👤 %s' "${COMMIT_ESC}" "${SHORT_SHA}" "${ACTOR}")
|
||||
curl -fS -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg c "${{ secrets.TELEGRAM_CHAT_ID }}" --arg t "$MSG" '{chat_id:$c,text:$t,parse_mode:"HTML"}')"
|
||||
-d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \
|
||||
-d "parse_mode=HTML" \
|
||||
--data-urlencode "text=${MSG}"
|
||||
|
||||
|
||||
|
||||
@@ -79,6 +82,7 @@ jobs:
|
||||
# pyproject.toml hash 變才重裝,其餘直接 activate (節省 ~6-7 min)
|
||||
- name: Run API Tests
|
||||
run: |
|
||||
cat > /tmp/awoooi-api-tests.sh <<'CI_SCRIPT'
|
||||
VENV=/opt/api-venv
|
||||
HASH_FILE=/opt/api-venv/.deps_hash
|
||||
CURRENT_HASH=$(md5sum apps/api/pyproject.toml | awk '{print $1}')
|
||||
@@ -141,6 +145,14 @@ jobs:
|
||||
2>&1 | tee /tmp/pytest-output.txt; PYTEST_EXIT=${PIPESTATUS[0]}
|
||||
tail -60 /tmp/pytest-output.txt
|
||||
exit $PYTEST_EXIT
|
||||
CI_SCRIPT
|
||||
docker run --rm \
|
||||
-v "$PWD:/workspace" \
|
||||
-v /tmp/awoooi-api-tests.sh:/tmp/awoooi-api-tests.sh:ro \
|
||||
-v awoooi-api-venv-cache:/opt/api-venv \
|
||||
-w /workspace \
|
||||
"${{ env.CI_IMAGE }}" \
|
||||
bash /tmp/awoooi-api-tests.sh
|
||||
|
||||
# ── 整合測試 B5 (2026-04-10) ──────────────────────────────────────────
|
||||
# B5 整合測試 — postgres-test 由 services: 提供,localhost:15432 直連
|
||||
@@ -155,6 +167,7 @@ jobs:
|
||||
# 修法: 把 pg-test-b5 加入 act task 的 network,用 container name 連線
|
||||
- name: Integration Tests (B5 — 真實 DB)
|
||||
run: |
|
||||
cat > /tmp/awoooi-b5-tests.sh <<'CI_SCRIPT'
|
||||
cd apps/api
|
||||
# 安裝 psql client
|
||||
if ! command -v psql &>/dev/null; then
|
||||
@@ -195,6 +208,15 @@ jobs:
|
||||
/opt/api-venv/bin/pytest tests/integration/test_b5_core_flows.py -v --tb=short -m integration
|
||||
# 清理
|
||||
docker rm -f pg-test-b5 || true
|
||||
CI_SCRIPT
|
||||
docker run --rm \
|
||||
-v "$PWD:/workspace" \
|
||||
-v /tmp/awoooi-b5-tests.sh:/tmp/awoooi-b5-tests.sh:ro \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v awoooi-api-venv-cache:/opt/api-venv \
|
||||
-w /workspace \
|
||||
"${{ env.CI_IMAGE }}" \
|
||||
bash /tmp/awoooi-b5-tests.sh
|
||||
|
||||
- name: Notify Pipeline Failure
|
||||
# 2026-04-30 Codex: tests job failure notifier; no jq dependency for host parity.
|
||||
|
||||
Reference in New Issue
Block a user