diff --git a/action.yml b/action.yml index 4aa0680..2ac8079 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/notify.sh b/notify.sh index cdd9f93..ce7164a 100644 --- a/notify.sh +++ b/notify.sh @@ -18,31 +18,70 @@ 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 # 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 <&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 }