feat: Add configurable Ntfy and Gmail options, Ntfy Basic Auth, and parallel notification sending.
This commit is contained in:
56
action.yml
56
action.yml
@@ -3,29 +3,75 @@ description: "Notify deployment result via ntfy, Gmail SMTP, and Telegram"
|
||||
|
||||
inputs:
|
||||
status:
|
||||
description: 'Deployment status (e.g., success, failure)'
|
||||
required: true
|
||||
title:
|
||||
description: 'Notification title'
|
||||
required: true
|
||||
message:
|
||||
description: 'Notification message body'
|
||||
required: true
|
||||
|
||||
# Configuration
|
||||
ntfy_url:
|
||||
description: 'Ntfy server URL'
|
||||
required: false
|
||||
default: 'https://ntfy.hcmc.online'
|
||||
ntfy_topic:
|
||||
description: 'Ntfy topic'
|
||||
required: false
|
||||
default: 'act_runner_deployment'
|
||||
ntfy_username:
|
||||
description: 'Ntfy Basic Auth Username'
|
||||
required: false
|
||||
default: 'homesrv'
|
||||
ntfy_password:
|
||||
description: 'Ntfy Basic Auth Password'
|
||||
required: false
|
||||
server_url:
|
||||
description: 'Git server BASE URL (e.g., https://git.hcmc.online)'
|
||||
required: false
|
||||
default: 'https://git.hcmc.online'
|
||||
|
||||
# Email Configuration
|
||||
gmail_user:
|
||||
description: 'Gmail username (sender)'
|
||||
required: false
|
||||
default: 'sitienbmt@gmail.com'
|
||||
gmail_to:
|
||||
description: 'Email recipient'
|
||||
required: false
|
||||
default: 'sitienbmt@gmail.com'
|
||||
gmail_password:
|
||||
description: 'Gmail App Password'
|
||||
required: false
|
||||
|
||||
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Send notification
|
||||
shell: bash
|
||||
env:
|
||||
# Core
|
||||
STATUS: ${{ inputs.status }}
|
||||
TITLE: ${{ inputs.title }}
|
||||
MESSAGE: ${{ inputs.message }}
|
||||
|
||||
NTFY_URL: "https://ntfy.hcmc.online"
|
||||
NTFY_TOPIC: "deploy"
|
||||
# Ntfy
|
||||
NTFY_URL: ${{ inputs.ntfy_url }}
|
||||
NTFY_TOPIC: ${{ inputs.ntfy_topic }}
|
||||
NTFY_USERNAME: ${{ inputs.ntfy_username }}
|
||||
NTFY_PASSWORD: ${{ inputs.ntfy_password || secrets.NTFY_PASSWORD }}
|
||||
GIT_URL: ${{ inputs.server_url }}
|
||||
|
||||
GMAIL_USER: "sitienbmt@gmail.com"
|
||||
GMAIL_TO: "sitienbmt@gmail.com"
|
||||
GMAIL_PASS: ${{ secrets.GMAIL_APP_PASSWORD }}
|
||||
# Gmail
|
||||
GMAIL_USER: ${{ inputs.gmail_user }}
|
||||
GMAIL_TO: ${{ inputs.gmail_to }}
|
||||
GMAIL_PASS: ${{ inputs.gmail_password || secrets.GMAIL_APP_PASSWORD }}
|
||||
|
||||
# Telegram
|
||||
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
||||
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
|
||||
run: |
|
||||
|
||||
80
notify.sh
80
notify.sh
@@ -1,23 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# Determine Icon based on Status
|
||||
ICON="🚀"
|
||||
if [ "$STATUS" = "failure" ]; then
|
||||
ICON="❌"
|
||||
fi
|
||||
|
||||
# Prepare Text for Telegram (Markdown)
|
||||
TEXT="$ICON *$TITLE*%0A%0A$MESSAGE"
|
||||
|
||||
# ---- ntfy ----
|
||||
if [ -n "$NTFY_URL" ] && [ -n "$NTFY_TOPIC" ]; then
|
||||
curl -s -X POST "$NTFY_URL/$NTFY_TOPIC" \
|
||||
echo "Starting notifications..."
|
||||
|
||||
# Function: Send to Ntfy
|
||||
send_ntfy() {
|
||||
if [ -n "$NTFY_URL" ] && [ -n "$NTFY_TOPIC" ]; then
|
||||
local click_url="$GIT_URL/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
|
||||
local auth_args=""
|
||||
|
||||
# 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" \
|
||||
-d "$MESSAGE"
|
||||
fi
|
||||
-H "Click: $click_url" \
|
||||
-H "Actions: view, Open Logs, $click_url" \
|
||||
-d "$MESSAGE"; then
|
||||
echo "[Ntfy] Sent."
|
||||
else
|
||||
echo "[Ntfy] Failed."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# ---- Gmail SMTP ----
|
||||
if [ -n "$GMAIL_USER" ] && [ -n "$GMAIL_TO" ]; then
|
||||
# Function: Send to Gmail
|
||||
send_gmail() {
|
||||
if [ -n "$GMAIL_USER" ] && [ -n "$GMAIL_TO" ] && [ -n "$GMAIL_PASS" ]; then
|
||||
if ! command -v sendmail &> /dev/null; then
|
||||
echo "[Gmail] Warning: sendmail not found, skipping."
|
||||
return
|
||||
fi
|
||||
echo "[Gmail] Sending..."
|
||||
{
|
||||
echo "Subject: $ICON $TITLE"
|
||||
echo "From: $GMAIL_USER"
|
||||
@@ -27,13 +54,38 @@ if [ -n "$GMAIL_USER" ] && [ -n "$GMAIL_TO" ]; then
|
||||
} | sendmail -S smtp.gmail.com:587 \
|
||||
-au"$GMAIL_USER" \
|
||||
-ap"$GMAIL_PASS" \
|
||||
"$GMAIL_TO"
|
||||
fi
|
||||
"$GMAIL_TO" && echo "[Gmail] Sent." || echo "[Gmail] Failed."
|
||||
fi
|
||||
}
|
||||
|
||||
# ---- Telegram ----
|
||||
if [ -n "$TELEGRAM_BOT_TOKEN" ] && [ -n "$TELEGRAM_CHAT_ID" ]; then
|
||||
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
|
||||
# Function: Send to Telegram
|
||||
send_telegram() {
|
||||
if [ -n "$TELEGRAM_BOT_TOKEN" ] && [ -n "$TELEGRAM_CHAT_ID" ]; then
|
||||
echo "[Telegram] Sending..."
|
||||
if curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
|
||||
-d chat_id="$TELEGRAM_CHAT_ID" \
|
||||
-d parse_mode="Markdown" \
|
||||
-d text="$TEXT"
|
||||
fi
|
||||
-d text="$TEXT"; then
|
||||
echo "[Telegram] Sent."
|
||||
else
|
||||
echo "[Telegram] Failed."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Execute in parallel
|
||||
send_ntfy &
|
||||
PID_NTFY=$!
|
||||
|
||||
send_gmail &
|
||||
PID_GMAIL=$!
|
||||
|
||||
send_telegram &
|
||||
PID_TG=$!
|
||||
|
||||
# Wait for completion
|
||||
wait $PID_NTFY
|
||||
wait $PID_GMAIL
|
||||
wait $PID_TG
|
||||
|
||||
echo "All notifications processed."
|
||||
Reference in New Issue
Block a user