commit 982e814a0f3c440191b82e49c1783bb66eb010de Author: Tien Ngo Date: Mon Dec 29 15:53:40 2025 +0700 feat: add GitHub Action for deployment notifications via ntfy and Gmail SMTP diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..2c48338 --- /dev/null +++ b/action.yml @@ -0,0 +1,52 @@ +name: "Deploy Notification" +description: "Notify deployment result via ntfy and Gmail SMTP" + +inputs: + status: + description: "Deployment status (success | failure)" + required: true + + title: + description: "Notification title" + required: true + + message: + description: "Notification message" + required: true + + ntfy_url: + description: "ntfy server URL (e.g. https://ntfy.example.com)" + default: "https://ntfy.hcmc.online" + required: false + + ntfy_topic: + description: "ntfy topic" + default: "deploy" + required: false + + gmail_user: + description: "Gmail address" + default: "sitienbmt@gmail.com" + required: false + + gmail_to: + description: "Recipient email" + default: "sitienbmt@gmail.com" + required: false + +runs: + using: "composite" + steps: + - name: Send notification + shell: bash + env: + STATUS: ${{ inputs.status }} + TITLE: ${{ inputs.title }} + MESSAGE: ${{ inputs.message }} + NTFY_URL: ${{ inputs.ntfy_url }} + NTFY_TOPIC: ${{ inputs.ntfy_topic }} + GMAIL_USER: ${{ inputs.gmail_user }} + GMAIL_TO: ${{ inputs.gmail_to }} + GMAIL_PASS: ${{ secrets.GMAIL_APP_PASSWORD }} + run: | + bash ${{ github.action_path }}/notify.sh diff --git a/notify.sh b/notify.sh new file mode 100644 index 0000000..9f31f3a --- /dev/null +++ b/notify.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -e + +ICON="🚀" +if [ "$STATUS" = "failure" ]; then + ICON="❌" +fi + +# ---- ntfy ---- +if [ -n "$NTFY_URL" ] && [ -n "$NTFY_TOPIC" ]; then + curl -s -X POST "$NTFY_URL/$NTFY_TOPIC" \ + -H "Title: $ICON $TITLE" \ + -H "Priority: 4" \ + -d "$MESSAGE" +fi + +# ---- Gmail SMTP ---- +if [ -n "$GMAIL_USER" ] && [ -n "$GMAIL_TO" ]; then + { + 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" +fi \ No newline at end of file