Compare commits
25 Commits
v1
...
adb71b9f35
| Author | SHA1 | Date | |
|---|---|---|---|
| adb71b9f35 | |||
| a89df4d9c5 | |||
| b8b03858a4 | |||
| f3417df036 | |||
| 8284b41d30 | |||
| 428a753fa2 | |||
| a3aae4ea1d | |||
| fdcac755aa | |||
| 4a94742273 | |||
| e969f3da44 | |||
| b62856deea | |||
| dad171096b | |||
| c3ab382adc | |||
| ec6d95ed7b | |||
| c95c3212c4 | |||
| c047741832 | |||
| 783b920fa4 | |||
| b428b04fef | |||
| 7c86049049 | |||
| 8613e74f11 | |||
| 002788fc03 | |||
| 6472fe639a | |||
| 19ba568834 | |||
| 72836873c7 | |||
| b87291aa21 |
35
action.yml
35
action.yml
@@ -24,7 +24,6 @@ inputs:
|
||||
ntfy_username:
|
||||
description: 'Ntfy Basic Auth Username'
|
||||
required: false
|
||||
default: 'homesrv'
|
||||
ntfy_password:
|
||||
description: 'Ntfy Basic Auth Password'
|
||||
required: false
|
||||
@@ -37,14 +36,20 @@ inputs:
|
||||
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
|
||||
|
||||
# Telegram Configuration
|
||||
telegram_bot_token:
|
||||
description: 'Telegram Bot Token'
|
||||
required: false
|
||||
telegram_chat_id:
|
||||
description: 'Telegram Chat ID'
|
||||
required: false
|
||||
|
||||
|
||||
|
||||
@@ -60,19 +65,23 @@ runs:
|
||||
MESSAGE: ${{ inputs.message }}
|
||||
|
||||
# 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 }}
|
||||
NTFY_URL: ${{ inputs.ntfy_url || 'https://ntfy.hcmc.online' }}
|
||||
NTFY_TOPIC: ${{ inputs.ntfy_topic || 'act_runner_deployment' }}
|
||||
NTFY_USERNAME: ${{ inputs.ntfy_username || env.NTFY_AUTH_USER }}
|
||||
NTFY_PASSWORD: ${{ inputs.ntfy_password || env.NTFY_AUTH_PASS }}
|
||||
|
||||
# Git
|
||||
GIT_URL: ${{ inputs.server_url || 'https://git.hcmc.online' }}
|
||||
GITHUB_REPOSITORY: ${{ github.repository }}
|
||||
GITHUB_RUN_ID: ${{ github.run_number }}
|
||||
|
||||
# Gmail
|
||||
GMAIL_USER: ${{ inputs.gmail_user }}
|
||||
GMAIL_TO: ${{ inputs.gmail_to }}
|
||||
GMAIL_PASS: ${{ inputs.gmail_password || secrets.GMAIL_APP_PASSWORD }}
|
||||
GMAIL_USER: ${{ inputs.gmail_user || env.GMAIL_USER }}
|
||||
GMAIL_TO: ${{ inputs.gmail_to || 'tienngodev@proton.me' }}
|
||||
GMAIL_PASS: ${{ inputs.gmail_password || env.GMAIL_PASSWORD }}
|
||||
|
||||
# Telegram
|
||||
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
||||
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
|
||||
TELEGRAM_BOT_TOKEN: ${{ inputs.telegram_bot_token || env.TELEGRAM_BOT_TOKEN }}
|
||||
TELEGRAM_CHAT_ID: ${{ inputs.telegram_chat_id || env.TELEGRAM_BOT_CHATID }}
|
||||
run: |
|
||||
bash ${{ github.action_path }}/notify.sh
|
||||
|
||||
326
notify.sh
326
notify.sh
@@ -7,13 +7,25 @@ if [ "$STATUS" = "failure" ]; then
|
||||
ICON="❌"
|
||||
fi
|
||||
|
||||
# Prepare Text for Telegram (Markdown)
|
||||
TEXT="$ICON *$TITLE*%0A%0A$MESSAGE"
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
echo "Starting notifications..."
|
||||
|
||||
# Function: Send to Ntfy
|
||||
echo ""
|
||||
echo -e "${GREEN}╔════════════════════════════════════════╗${NC}"
|
||||
echo -e "${GREEN}║ 🚀 Deployment Notification System ║${NC}"
|
||||
echo -e "${GREEN}╚════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
|
||||
# Function: Send to Ntfy (Modern Push Notification)
|
||||
send_ntfy() {
|
||||
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||
echo -e "${YELLOW}🔔 Ntfy Push Notification${NC}"
|
||||
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||
|
||||
if [ -n "$NTFY_URL" ] && [ -n "$NTFY_TOPIC" ]; then
|
||||
local click_url="$GIT_URL/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
|
||||
local auth_args=""
|
||||
@@ -37,55 +49,305 @@ send_ntfy() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function: Send to Gmail
|
||||
# Function: Send to Gmail (Modern HTML Email)
|
||||
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
|
||||
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||
echo -e "${YELLOW}📧 Gmail SMTP Email${NC}"
|
||||
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||
echo -e " From: ${GREEN}$GMAIL_USER${NC}"
|
||||
echo -e " To: ${GREEN}$GMAIL_TO${NC}"
|
||||
echo -e " SMTP: ${GREEN}smtp.gmail.com:587${NC}"
|
||||
echo ""
|
||||
|
||||
# Determine status color and badge
|
||||
local status_color="#22c55e"
|
||||
local status_bg="#dcfce7"
|
||||
local status_text="SUCCESS"
|
||||
|
||||
if [ "$STATUS" = "failure" ]; then
|
||||
status_color="#ef4444"
|
||||
status_bg="#fee2e2"
|
||||
status_text="FAILURE"
|
||||
fi
|
||||
echo "[Gmail] Sending..."
|
||||
{
|
||||
echo "Subject: $ICON $TITLE"
|
||||
echo "From: $GMAIL_USER"
|
||||
echo "To: $GMAIL_TO"
|
||||
echo ""
|
||||
echo "$MESSAGE"
|
||||
} | sendmail -S smtp.gmail.com:587 \
|
||||
-au"$GMAIL_USER" \
|
||||
-ap"$GMAIL_PASS" \
|
||||
"$GMAIL_TO" && echo "[Gmail] Sent." || echo "[Gmail] Failed."
|
||||
|
||||
# Parse structured message data
|
||||
local branch=$(echo "$MESSAGE" | grep -oP '^Branch:\s*\K.*' || echo "")
|
||||
local commit=$(echo "$MESSAGE" | grep -oP '^Commit:\s*\K.*' || echo "")
|
||||
local commit_msg=$(echo "$MESSAGE" | grep -oP '^Message:\s*\K.*' || echo "")
|
||||
local actor=$(echo "$MESSAGE" | grep -oP '^Actor:\s*\K.*' || echo "")
|
||||
|
||||
# Shorten commit hash for display
|
||||
local commit_short="${commit:0:8}"
|
||||
|
||||
# Build modern HTML email with inline CSS
|
||||
local html_body=$(cat <<EOF
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>$TITLE</title>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; background-color: #f3f4f6;">
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f3f4f6; padding: 40px 20px;">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 12px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); overflow: hidden;">
|
||||
<!-- Header -->
|
||||
<tr>
|
||||
<td style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 32px 40px; text-align: center;">
|
||||
<h1 style="margin: 0; color: #ffffff; font-size: 28px; font-weight: 700;">$ICON Deployment Notification</h1>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Status Badge -->
|
||||
<tr>
|
||||
<td style="padding: 32px 40px 24px; text-align: center;">
|
||||
<div style="display: inline-block; background-color: $status_bg; color: $status_color; padding: 8px 20px; border-radius: 20px; font-weight: 600; font-size: 14px; letter-spacing: 0.5px;">
|
||||
$status_text
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Repository Info -->
|
||||
<tr>
|
||||
<td style="padding: 0 40px 24px; text-align: center;">
|
||||
<h2 style="margin: 0; color: #111827; font-size: 20px; font-weight: 600;">${GITHUB_REPOSITORY:-Repository}</h2>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Deployment Details Cards -->
|
||||
<tr>
|
||||
<td style="padding: 0 40px 32px;">
|
||||
<table width="100%" cellpadding="0" cellspacing="0">
|
||||
<!-- Branch -->
|
||||
<tr>
|
||||
<td style="padding-bottom: 12px;">
|
||||
<div style="background-color: #f9fafb; border-left: 4px solid #3b82f6; padding: 16px; border-radius: 6px;">
|
||||
<div style="color: #6b7280; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px;">🌿 Branch</div>
|
||||
<div style="color: #111827; font-size: 15px; font-weight: 500; font-family: 'Courier New', monospace;">$branch</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Commit -->
|
||||
<tr>
|
||||
<td style="padding-bottom: 12px;">
|
||||
<div style="background-color: #f9fafb; border-left: 4px solid #8b5cf6; padding: 16px; border-radius: 6px;">
|
||||
<div style="color: #6b7280; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px;">🔖 Commit</div>
|
||||
<div style="color: #111827; font-size: 15px; font-weight: 500; font-family: 'Courier New', monospace;">$commit_short</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Commit Message -->
|
||||
<tr>
|
||||
<td style="padding-bottom: 12px;">
|
||||
<div style="background-color: #f9fafb; border-left: 4px solid $status_color; padding: 16px; border-radius: 6px;">
|
||||
<div style="color: #6b7280; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px;">💬 Commit Message</div>
|
||||
<div style="color: #111827; font-size: 15px; line-height: 1.5;">$commit_msg</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Actor -->
|
||||
<tr>
|
||||
<td>
|
||||
<div style="background-color: #f9fafb; border-left: 4px solid #10b981; padding: 16px; border-radius: 6px;">
|
||||
<div style="color: #6b7280; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px;">👤 Author</div>
|
||||
<div style="color: #111827; font-size: 15px; font-weight: 500;">$actor</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Metadata -->
|
||||
<tr>
|
||||
<td style="padding: 0 40px 32px;">
|
||||
<table width="100%" cellpadding="8" cellspacing="0" style="border-top: 1px solid #e5e7eb; background-color: #fafafa; border-radius: 6px;">
|
||||
<tr>
|
||||
<td style="color: #6b7280; font-size: 13px; padding-top: 16px;">
|
||||
<strong>🔢 Run ID:</strong> ${GITHUB_RUN_ID:-N/A}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="color: #6b7280; font-size: 13px;">
|
||||
<strong>⏰ Timestamp:</strong> $(date -u +"%Y-%m-%d %H:%M:%S UTC")
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Action Button -->
|
||||
<tr>
|
||||
<td style="padding: 0 40px 40px; text-align: center;">
|
||||
<a href="$GIT_URL/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" style="display: inline-block; background-color: #667eea; color: #ffffff; text-decoration: none; padding: 14px 36px; border-radius: 8px; font-weight: 600; font-size: 15px; box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);">
|
||||
📋 View Deployment Logs
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Footer -->
|
||||
<tr>
|
||||
<td style="background-color: #f9fafb; padding: 24px 40px; text-align: center; border-top: 1px solid #e5e7eb;">
|
||||
<p style="margin: 0; color: #9ca3af; font-size: 12px;">
|
||||
🤖 Automated deployment notification from <strong>Act Runner</strong>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
)
|
||||
|
||||
# Create MIME email with proper headers
|
||||
local boundary="----=_Part_$(date +%s)_$(( RANDOM ))"
|
||||
local email_content=$(cat <<EOF
|
||||
From: Act Runner Deployment <noreply@actrunner>
|
||||
Reply-To: $GMAIL_USER
|
||||
To: $GMAIL_TO
|
||||
Subject: $ICON $TITLE
|
||||
MIME-Version: 1.0
|
||||
Content-Type: multipart/alternative; boundary="$boundary"
|
||||
|
||||
--$boundary
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
$ICON $TITLE
|
||||
|
||||
Status: $STATUS
|
||||
Message: $MESSAGE
|
||||
|
||||
Repository: ${GITHUB_REPOSITORY:-N/A}
|
||||
Run ID: ${GITHUB_RUN_ID:-N/A}
|
||||
Timestamp: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
|
||||
|
||||
View logs: $GIT_URL/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}
|
||||
|
||||
--$boundary
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
$html_body
|
||||
--$boundary--
|
||||
EOF
|
||||
)
|
||||
|
||||
# Send email via SMTP
|
||||
echo -e " ${YELLOW}→${NC} Sending HTML email..."
|
||||
response=$(printf "%s" "$email_content" | curl --ssl-reqd \
|
||||
--url "smtp://smtp.gmail.com:587" \
|
||||
--user "$GMAIL_USER:$GMAIL_PASS" \
|
||||
--mail-from "$GMAIL_USER" \
|
||||
--mail-rcpt "$GMAIL_TO" \
|
||||
--upload-file - \
|
||||
--silent \
|
||||
--show-error 2>&1)
|
||||
|
||||
exit_code=$?
|
||||
|
||||
if [ $exit_code -eq 0 ]; then
|
||||
echo -e " ${GREEN}✓${NC} Email sent successfully"
|
||||
else
|
||||
echo -e " ${RED}✗${NC} Failed to send email"
|
||||
echo -e " ${RED}Error:${NC} $response"
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# Function: Send to Telegram
|
||||
# Function: Send to Telegram (Modern Rich Message)
|
||||
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"; then
|
||||
echo "[Telegram] Sent."
|
||||
else
|
||||
echo "[Telegram] Failed."
|
||||
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||
echo -e "${YELLOW}✈️ Telegram Message${NC}"
|
||||
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||
echo -e " Chat ID: ${GREEN}$TELEGRAM_CHAT_ID${NC}"
|
||||
echo ""
|
||||
|
||||
# Determine status emoji and formatting
|
||||
local status_emoji="✅"
|
||||
local status_text="SUCCESS"
|
||||
if [ "$STATUS" = "failure" ]; then
|
||||
status_emoji="❌"
|
||||
status_text="FAILURE"
|
||||
fi
|
||||
|
||||
# Build rich Telegram message with MarkdownV2 formatting
|
||||
local telegram_message=$(cat <<EOF
|
||||
$ICON *$TITLE*
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━
|
||||
$status_emoji *Status:* \`$status_text\`
|
||||
━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
📝 *Message:*
|
||||
$MESSAGE
|
||||
|
||||
📊 *Details:*
|
||||
• Repository: \`${GITHUB_REPOSITORY:-N/A}\`
|
||||
• Run ID: \`${GITHUB_RUN_ID:-N/A}\`
|
||||
• Timestamp: \`$(date -u +"%Y-%m-%d %H:%M:%S UTC")\`
|
||||
|
||||
🔗 [View Deployment Logs]($GIT_URL/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID})
|
||||
EOF
|
||||
)
|
||||
|
||||
echo -e " ${YELLOW}→${NC} Sending Telegram message..."
|
||||
response=$(curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"chat_id\": \"$TELEGRAM_CHAT_ID\",
|
||||
\"parse_mode\": \"Markdown\",
|
||||
\"text\": $(echo "$telegram_message" | jq -Rs .),
|
||||
\"disable_web_page_preview\": false,
|
||||
\"reply_markup\": {
|
||||
\"inline_keyboard\": [[
|
||||
{
|
||||
\"text\": \"📋 View Logs\",
|
||||
\"url\": \"$GIT_URL/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}\"
|
||||
}
|
||||
]]
|
||||
}
|
||||
}" 2>&1)
|
||||
|
||||
# Check if message was sent successfully
|
||||
if echo "$response" | grep -q '"ok":true'; then
|
||||
echo -e " ${GREEN}✓${NC} Message sent successfully"
|
||||
else
|
||||
echo -e " ${RED}✗${NC} Failed to send message"
|
||||
# Try to extract error description
|
||||
error_desc=$(echo "$response" | grep -o '"description":"[^"]*"' | cut -d'"' -f4)
|
||||
if [ -n "$error_desc" ]; then
|
||||
echo -e " ${RED}Error:${NC} $error_desc"
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# Execute in parallel
|
||||
send_ntfy &
|
||||
PID_NTFY=$!
|
||||
|
||||
send_gmail &
|
||||
PID_GMAIL=$!
|
||||
|
||||
send_telegram &
|
||||
PID_TG=$!
|
||||
|
||||
send_ntfy &
|
||||
PID_NTFY=$!
|
||||
|
||||
# Wait for completion
|
||||
wait $PID_NTFY
|
||||
wait $PID_GMAIL
|
||||
wait $PID_TG
|
||||
wait $PID_NTFY
|
||||
|
||||
echo "All notifications processed."
|
||||
Reference in New Issue
Block a user