From b62856deeab08e87de3b0b775af7fa48c61732bc Mon Sep 17 00:00:00 2001 From: Tien Ngo Date: Tue, 30 Dec 2025 14:23:41 +0700 Subject: [PATCH] fix ntfy --- notify.sh | 66 +++++++++++-------------------------------------------- 1 file changed, 13 insertions(+), 53 deletions(-) diff --git a/notify.sh b/notify.sh index 09fccf0..cdd9f93 100644 --- a/notify.sh +++ b/notify.sh @@ -18,71 +18,31 @@ send_ntfy() { echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo -e "${YELLOW}🔔 Ntfy Push Notification${NC}" echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + + echo -e " Server: ${GREEN}$NTFY_URL${NC}" + echo -e " Topic: ${GREEN}$NTFY_TOPIC${NC}" + echo "" if [ -n "$NTFY_URL" ] && [ -n "$NTFY_TOPIC" ]; then - echo -e " Server: ${GREEN}$NTFY_URL${NC}" - echo -e " Topic: ${GREEN}$NTFY_TOPIC${NC}" - echo "" - local click_url="$GIT_URL/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" local auth_args="" - local priority=4 - local tags="rocket,deployment" - # Adjust priority and tags based on status - if [ "$STATUS" = "failure" ]; then - priority=5 - tags="x,warning,deployment" - fi - - - local curl_auth_args=() + # Check for Basic Auth if [ -n "$NTFY_USERNAME" ] && [ -n "$NTFY_PASSWORD" ]; then - curl_auth_args=(-u "$NTFY_USERNAME:$NTFY_PASSWORD") - echo -e " ${GREEN}✓${NC} Using Basic Authentication" - else - echo -e " ${YELLOW}⚠${NC} No authentication (public topic)" + auth_args="-u $NTFY_USERNAME:$NTFY_PASSWORD" fi - echo "" - # Build rich message with metadata - local rich_message=$(cat <&1) - - http_code=$(echo "$response" | tail -n1) - response_body=$(echo "$response" | head -n -1) - - if [ "$http_code" = "200" ] || [ "$http_code" = "201" ]; then - echo -e " ${GREEN}✓${NC} Notification sent successfully (HTTP $http_code)" + -H "Actions: view, Open Logs, $click_url" \ + -d "$MESSAGE"; then + echo "[Ntfy] Sent." else - echo -e " ${RED}✗${NC} Failed to send notification (HTTP $http_code)" - if [ -n "$response_body" ]; then - echo -e " ${RED}Response:${NC} $response_body" - fi + echo "[Ntfy] Failed." fi - echo "" - else - echo -e " ${RED}✗${NC} Skipping Ntfy - Missing required configuration" - [ -z "$NTFY_URL" ] && echo -e " ${RED}•${NC} NTFY_URL is not set" - [ -z "$NTFY_TOPIC" ] && echo -e " ${RED}•${NC} NTFY_TOPIC is not set" - echo "" fi }