opt: fix ntfy
This commit is contained in:
@@ -70,6 +70,8 @@ runs:
|
|||||||
NTFY_USERNAME: ${{ inputs.ntfy_username || env.NTFY_AUTH_USER }}
|
NTFY_USERNAME: ${{ inputs.ntfy_username || env.NTFY_AUTH_USER }}
|
||||||
NTFY_PASSWORD: ${{ inputs.ntfy_password || env.NTFY_AUTH_PASS }}
|
NTFY_PASSWORD: ${{ inputs.ntfy_password || env.NTFY_AUTH_PASS }}
|
||||||
GIT_URL: ${{ inputs.server_url || 'https://git.hcmc.online' }}
|
GIT_URL: ${{ inputs.server_url || 'https://git.hcmc.online' }}
|
||||||
|
GITHUB_REPOSITORY: ${{ github.repository }}
|
||||||
|
GITHUB_RUN_ID: ${{ github.run_id }}
|
||||||
|
|
||||||
# Gmail
|
# Gmail
|
||||||
GMAIL_USER: ${{ inputs.gmail_user || env.GMAIL_USER }}
|
GMAIL_USER: ${{ inputs.gmail_user || env.GMAIL_USER }}
|
||||||
|
|||||||
74
notify.sh
74
notify.sh
@@ -7,6 +7,13 @@ if [ "$STATUS" = "failure" ]; then
|
|||||||
ICON="❌"
|
ICON="❌"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${GREEN}╔════════════════════════════════════════╗${NC}"
|
echo -e "${GREEN}╔════════════════════════════════════════╗${NC}"
|
||||||
echo -e "${GREEN}║ 🚀 Deployment Notification System ║${NC}"
|
echo -e "${GREEN}║ 🚀 Deployment Notification System ║${NC}"
|
||||||
@@ -20,80 +27,37 @@ send_ntfy() {
|
|||||||
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
|
||||||
if [ -n "$NTFY_URL" ] && [ -n "$NTFY_TOPIC" ]; then
|
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 click_url="$GIT_URL/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
|
||||||
local auth_args=""
|
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
|
|
||||||
|
|
||||||
# Check for Basic Auth
|
# Check for Basic Auth
|
||||||
if [ -n "$NTFY_USERNAME" ] && [ -n "$NTFY_PASSWORD" ]; then
|
if [ -n "$NTFY_USERNAME" ] && [ -n "$NTFY_PASSWORD" ]; then
|
||||||
|
echo -e " Server: ${GREEN}$NTFY_URL${NC}"
|
||||||
|
echo -e " Topic: ${GREEN}$NTFY_TOPIC${NC}"
|
||||||
|
echo -e " Auth: ${GREEN}Basic Auth${NC}"
|
||||||
auth_args="-u $NTFY_USERNAME:$NTFY_PASSWORD"
|
auth_args="-u $NTFY_USERNAME:$NTFY_PASSWORD"
|
||||||
echo -e " ${GREEN}✓${NC} Using Basic Authentication"
|
|
||||||
else
|
|
||||||
echo -e " ${YELLOW}⚠${NC} No authentication (public topic)"
|
|
||||||
fi
|
fi
|
||||||
echo ""
|
|
||||||
|
|
||||||
echo -e " ${YELLOW}→${NC} Sending push notification..."
|
echo -e " ${YELLOW}→${NC} Sending push notification..."
|
||||||
echo -e " ${YELLOW}→${NC} Target: $NTFY_URL/$NTFY_TOPIC"
|
echo -e " ${YELLOW}→${NC} Target: $NTFY_URL/$NTFY_TOPIC"
|
||||||
|
echo -e " ${YELLOW}→${NC} Click URL: $click_url"
|
||||||
|
echo -e " ${YELLOW}→${NC} Message: $MESSAGE"
|
||||||
|
echo -e ""
|
||||||
|
|
||||||
# Capture curl response and exit code separately
|
if curl -s $auth_args -X POST "$NTFY_URL/$NTFY_TOPIC" \
|
||||||
set +e # Temporarily disable exit on error for curl
|
|
||||||
response=$(curl -s -w "\n%{http_code}" --http1.1 -k $auth_args -X POST "$NTFY_URL/$NTFY_TOPIC" \
|
|
||||||
-H "Title: $ICON $TITLE" \
|
-H "Title: $ICON $TITLE" \
|
||||||
-H "Priority: $priority" \
|
-H "Priority: 4" \
|
||||||
-H "Tags: $tags" \
|
|
||||||
-H "Click: $click_url" \
|
-H "Click: $click_url" \
|
||||||
-H "Actions: view, View Logs, $click_url, clear=true" \
|
-H "Actions: view, Open Logs, $click_url" \
|
||||||
-d "$MESSAGE" 2>&1)
|
-d "$MESSAGE"; then
|
||||||
curl_exit_code=$?
|
echo -e " ${GREEN}✓${NC} Sent successfully"
|
||||||
set -e # Re-enable exit on error
|
|
||||||
|
|
||||||
# Check if curl command itself failed
|
|
||||||
if [ $curl_exit_code -ne 0 ]; then
|
|
||||||
echo -e " ${RED}✗${NC} Failed to send notification (curl error: $curl_exit_code)"
|
|
||||||
if [ -n "$response" ]; then
|
|
||||||
echo -e " ${RED}Error:${NC} $response"
|
|
||||||
fi
|
|
||||||
echo ""
|
|
||||||
return 0 # Return success to prevent script failure
|
|
||||||
fi
|
|
||||||
|
|
||||||
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)"
|
|
||||||
else
|
else
|
||||||
echo -e " ${RED}✗${NC} Failed to send notification (HTTP $http_code)"
|
echo -e " ${RED}✗${NC} Failed to send notification"
|
||||||
if [ -n "$response_body" ]; then
|
|
||||||
echo -e " ${RED}Response:${NC} $response_body"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
echo ""
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
RED='\033[0;31m'
|
|
||||||
GREEN='\033[0;32m'
|
|
||||||
YELLOW='\033[1;33m'
|
|
||||||
NC='\033[0m'
|
|
||||||
|
|
||||||
# Function: Send to Gmail (Modern HTML Email)
|
# Function: Send to Gmail (Modern HTML Email)
|
||||||
send_gmail() {
|
send_gmail() {
|
||||||
if [ -n "$GMAIL_USER" ] && [ -n "$GMAIL_TO" ] && [ -n "$GMAIL_PASS" ]; then
|
if [ -n "$GMAIL_USER" ] && [ -n "$GMAIL_TO" ] && [ -n "$GMAIL_PASS" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user