ci: notify-telegram.sh — append last 30 log lines on fail
This commit is contained in:
@@ -18,6 +18,7 @@ fi
|
||||
VERB="${1:-}"
|
||||
STAGE="${2:-}"
|
||||
EXTRA="${3:-}"
|
||||
LOG_PATH="${4:-}"
|
||||
|
||||
case "$VERB" in
|
||||
start|ok|fail) ;;
|
||||
@@ -49,6 +50,15 @@ BODY="${HEAD}
|
||||
commit: ${SHORT_SHA}
|
||||
gitea run: ${RUN_URL}"
|
||||
|
||||
if [ "$VERB" = "fail" ] && [ -n "$LOG_PATH" ] && [ -f "$LOG_PATH" ]; then
|
||||
TAIL_LINES=$(tail -n 30 "$LOG_PATH")
|
||||
TAIL_COUNT=$(printf '%s\n' "$TAIL_LINES" | wc -l | tr -d ' ')
|
||||
BODY="${BODY}
|
||||
|
||||
last ${TAIL_COUNT} lines:
|
||||
${TAIL_LINES}"
|
||||
fi
|
||||
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
printf '%s\n' "$BODY"
|
||||
exit 0
|
||||
|
||||
@@ -44,4 +44,18 @@ if "$SCRIPT" ok ci-deploy 2>/dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# --- fail with log tail ---
|
||||
TMPLOG=$(mktemp)
|
||||
printf 'line1\nline2\nline3\n' > "$TMPLOG"
|
||||
out=$("$SCRIPT" --dry-run fail ci-deploy "Run Playwright e2e" "$TMPLOG")
|
||||
assert_contains "$out" "last 3 lines"
|
||||
assert_contains "$out" "line1"
|
||||
assert_contains "$out" "line3"
|
||||
rm -f "$TMPLOG"
|
||||
|
||||
# --- fail with missing log file: should still print message, no crash ---
|
||||
out=$("$SCRIPT" --dry-run fail ci-deploy "Build" "/nonexistent/log")
|
||||
assert_contains "$out" "❌ ci-deploy FAILED"
|
||||
|
||||
echo "PASS: notify-telegram.sh"
|
||||
|
||||
Reference in New Issue
Block a user