test(staging): add smoke suite script and gameplay smoke command (closes #22)
This commit is contained in:
59
infra/staging/smoke_suite.sh
Executable file
59
infra/staging/smoke_suite.sh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BASE_URL="${BASE_URL:-http://127.0.0.1:8000}"
|
||||
APP_DIR="${APP_DIR:-/opt/wpp-staging/app}"
|
||||
ISSUE_ON_FAIL="${ISSUE_ON_FAIL:-1}"
|
||||
|
||||
fail() {
|
||||
local message="$1"
|
||||
echo "[smoke] FAIL: ${message}" >&2
|
||||
|
||||
if [[ "${ISSUE_ON_FAIL}" == "1" ]] && [[ -n "${GITEA_BASE:-}" ]] && [[ -n "${GITEA_REPO:-}" ]] && [[ -n "${GITEA_USER:-}" ]] && [[ -n "${GITEA_TOKEN:-}" ]]; then
|
||||
python3 - <<PY || true
|
||||
import json
|
||||
import os
|
||||
import urllib.request
|
||||
import base64
|
||||
from datetime import datetime, timezone
|
||||
|
||||
base = os.environ["GITEA_BASE"].rstrip("/")
|
||||
repo = os.environ["GITEA_REPO"]
|
||||
user = os.environ["GITEA_USER"]
|
||||
token = os.environ["GITEA_TOKEN"]
|
||||
message = os.environ.get("SMOKE_FAIL_MESSAGE", "unknown")
|
||||
when = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
|
||||
|
||||
payload = {
|
||||
"title": f"[smoke-fail] staging smoke failed ({when})",
|
||||
"body": (
|
||||
"Automatisk oprettet af smoke-suite.\n\n"
|
||||
f"Fejl: `{message}`\n"
|
||||
"Kontekst: issue #22 (staging smoke-suite)"
|
||||
),
|
||||
"labels": ["smoke-fail", "need-to-have", "staging"],
|
||||
}
|
||||
|
||||
url = f"{base}/api/v1/repos/{repo}/issues"
|
||||
req = urllib.request.Request(url, data=json.dumps(payload).encode(), method="POST")
|
||||
auth = base64.b64encode(f"{user}:{token}".encode()).decode()
|
||||
req.add_header("Authorization", f"Basic {auth}")
|
||||
req.add_header("Content-Type", "application/json")
|
||||
with urllib.request.urlopen(req) as r:
|
||||
print(f"[smoke] Created fail issue: HTTP {r.status}")
|
||||
PY
|
||||
fi
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "[smoke] healthz check: ${BASE_URL}/healthz"
|
||||
curl -fsS "${BASE_URL}/healthz" >/dev/null || { SMOKE_FAIL_MESSAGE="healthz check failed" fail "healthz check failed"; }
|
||||
|
||||
echo "[smoke] gameplay flow via management command"
|
||||
(
|
||||
cd "${APP_DIR}"
|
||||
.venv/bin/python manage.py smoke_staging
|
||||
) || { SMOKE_FAIL_MESSAGE="manage.py smoke_staging failed" fail "manage.py smoke_staging failed"; }
|
||||
|
||||
echo "[smoke] OK"
|
||||
Reference in New Issue
Block a user