opt: fix ntfy

This commit is contained in:
2025-12-30 14:32:04 +07:00
parent b62856deea
commit e969f3da44
2 changed files with 56 additions and 17 deletions

View File

@@ -67,8 +67,8 @@ runs:
# Ntfy
NTFY_URL: ${{ inputs.ntfy_url || 'https://ntfy.hcmc.online' }}
NTFY_TOPIC: ${{ inputs.ntfy_topic || 'act_runner_deployment' }}
NTFY_USERNAME: ${{ inputs.ntfy_username || env.NTFY_USERNAME }}
NTFY_PASSWORD: ${{ inputs.ntfy_password || env.NTFY_PASSWORD }}
NTFY_USERNAME: ${{ inputs.ntfy_username || env.NTFY_AUTH_USER }}
NTFY_PASSWORD: ${{ inputs.ntfy_password || env.NTFY_AUTH_PASS }}
GIT_URL: ${{ inputs.server_url || 'https://git.hcmc.online' }}
# Gmail

View File

@@ -19,30 +19,69 @@ send_ntfy() {
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
# Check for Basic Auth
if [ -n "$NTFY_USERNAME" ] && [ -n "$NTFY_PASSWORD" ]; then
auth_args="-u $NTFY_USERNAME:$NTFY_PASSWORD"
fi
echo "[Ntfy] Sending..."
if curl -s $auth_args -X POST "$NTFY_URL/$NTFY_TOPIC" \
-H "Title: $ICON $TITLE" \
-H "Priority: 4" \
-H "Click: $click_url" \
-H "Actions: view, Open Logs, $click_url" \
-d "$MESSAGE"; then
echo "[Ntfy] Sent."
echo -e " ${GREEN}${NC} Using Basic Authentication"
else
echo "[Ntfy] Failed."
echo -e " ${YELLOW}${NC} No authentication (public topic)"
fi
echo ""
# Build rich message with metadata
local rich_message=$(cat <<EOF
$MESSAGE
📦 Repository: ${GITHUB_REPOSITORY:-N/A}
🔢 Run ID: ${GITHUB_RUN_ID:-N/A}
⏰ Time: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
EOF
)
echo -e " ${YELLOW}${NC} Sending push notification..."
echo -e " ${YELLOW}${NC} Target: $NTFY_URL/$NTFY_TOPIC"
response=$(curl -s -w "\n%{http_code}" $auth_args -X POST "$NTFY_URL/$NTFY_TOPIC" \
-H "Title: $ICON $TITLE" \
-H "Priority: $priority" \
-H "Tags: $tags" \
-H "Click: $click_url" \
-H "Actions: view, Open Logs, $click_url, clear=true" \
-d "$rich_message" 2>&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)"
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
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
}