From 24358fd3e3b424b83f61c11af56bfd6bee8bb6ab Mon Sep 17 00:00:00 2001 From: gnezim Date: Sat, 25 Apr 2026 02:35:33 +0300 Subject: [PATCH] =?UTF-8?q?ci:=20notify-telegram.sh=20=E2=80=94=20append?= =?UTF-8?q?=20last=2030=20log=20lines=20on=20fail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ci/notify-telegram.sh | 10 ++++++++++ tests/ci/test-notify-telegram.sh | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/scripts/ci/notify-telegram.sh b/scripts/ci/notify-telegram.sh index b3d9d620..db070636 100755 --- a/scripts/ci/notify-telegram.sh +++ b/scripts/ci/notify-telegram.sh @@ -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 diff --git a/tests/ci/test-notify-telegram.sh b/tests/ci/test-notify-telegram.sh index c9a816ce..ef678387 100755 --- a/tests/ci/test-notify-telegram.sh +++ b/tests/ci/test-notify-telegram.sh @@ -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"