diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fd010d8..ebe3013 100755 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,8 +16,8 @@ jobs: steps: - uses: actions/setup-java@v4 with: - distribution: "zulu" - java-version: "17" + distribution: 'zulu' + java-version: '17' - name: Checkout uses: actions/checkout@v4 @@ -175,7 +175,7 @@ jobs: **Download Links:** " - + MODULES_MSG=" **Modules:** ${MODULES} @@ -189,15 +189,15 @@ jobs: curl -X POST -H "Content-Type: application/json" \ -d "$(jq -n --arg content "$MSG" '{content: $content}')" \ "$DISCORD_WEBHOOK_URL" - + # curl -X POST -H "Content-Type: application/json" \ # -d "$(jq -n --arg content "$MODULES_MSG" '{content: $content}')" \ # "$DISCORD_WEBHOOK_URL" - + curl -X POST -H "Content-Type: application/json" \ -d "$(jq -n --arg content "$APKS_MSG" '{content: $content}')" \ "$DISCORD_WEBHOOK_URL" - + - name: Report to Noob Discord env: DISCORD_WEBHOOK_NOOB_URL: ${{ secrets.DISCORD_WEBHOOK_NOOB_URL }} @@ -227,7 +227,7 @@ jobs: **Download Links:** " - + MODULES_MSG=" **Modules:** ${MODULES} @@ -241,11 +241,109 @@ jobs: curl -X POST -H "Content-Type: application/json" \ -d "$(jq -n --arg content "$MSG" '{content: $content}')" \ "$DISCORD_WEBHOOK_NOOB_URL" - + # curl -X POST -H "Content-Type: application/json" \ # -d "$(jq -n --arg content "$MODULES_MSG" '{content: $content}')" \ # "$DISCORD_WEBHOOK_NOOB_URL" - + curl -X POST -H "Content-Type: application/json" \ -d "$(jq -n --arg content "$APKS_MSG" '{content: $content}')" \ "$DISCORD_WEBHOOK_NOOB_URL" + + - name: Send Email Notification (Resend) + env: + RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }} + MAIL_TO: ${{ secrets.MAIL_TO }} + MAIL_CC: ${{ secrets.MAIL_CC }} + MAIL_BCC: ${{ secrets.MAIL_BCC }} + MAIL_FROM: ${{ secrets.MAIL_FROM }} + if: env.RESEND_API_KEY != null && env.MAIL_TO != null + run: | + VERSION="${{ steps.next_ver_code.outputs.NEXT_VER_CODE }}" + RELEASE_URL="${{ github.server_url }}/${{ github.repository }}/releases/tag/${VERSION}" + REPO="${{ github.repository }}" + + # Set default FROM address if not provided + FROM_ADDRESS="${MAIL_FROM:-ReVanced Build Bot }" + + # Build download links from build folder + cd build || { echo "build folder not found"; exit 1; } + + DOWNLOAD_LINKS="" + for OUTPUT in *; do + DL_URL="${{ github.server_url }}/${{ github.repository }}/releases/download/${VERSION}/${OUTPUT}" + if [[ $OUTPUT = *.apk ]]; then + DOWNLOAD_LINKS+="
  • 📦 ${OUTPUT}
  • " + elif [[ $OUTPUT = *.zip ]]; then + DOWNLOAD_LINKS+="
  • 📁 ${OUTPUT}
  • + fi + done + cd .. + + # Create HTML email body + HTML_BODY=$(cat < + + + + + +
    +

    🎉 New ReVanced Build!

    +

    Version: v${VERSION}

    +
    +
    +
    +

    📋 Build Summary

    +

    A new ReVanced build has been completed successfully!

    +
    +
    +

    📥 Downloads

    +
      + ${DOWNLOAD_LINKS} +
    +
    +
    + + View Release on GitHub + +
    +
    +
    +

    This is an automated message from ReVanced Build Bot

    +

    Repository: ${REPO}

    +
    + + + EOF + ) + + # Build JSON payload with TO, CC and BCC recipients + # Resend allows up to 50 recipients per field (to, cc, bcc) + JSON_PAYLOAD=$(jq -n \ + --arg from "$FROM_ADDRESS" \ + --arg to "$MAIL_TO" \ + --arg cc "$MAIL_CC" \ + --arg bcc "$MAIL_BCC" \ + --arg subject "🚀 New ReVanced Build Available - v${VERSION}" \ + --arg html "$HTML_BODY" \ + '{ + from: $from, + to: ($to | split(",") | map(select(. != "") | gsub("^\\s+|\\s+$"; ""))), + subject: $subject, + html: $html + } + + (if $cc != "" then {cc: ($cc | split(",") | map(select(. != "") | gsub("^\\s+|\\s+$"; "")))} else {} end) + + (if $bcc != "" then {bcc: ($bcc | split(",") | map(select(. != "") | gsub("^\\s+|\\s+$"; "")))} else {} end)' + ) + + echo "📧 Sending email notification..." + + # Send email via Resend API + RESPONSE=$(curl -s -X POST "https://api.resend.com/emails" \ + -H "Authorization: Bearer ${RESEND_API_KEY}" \ + -H "Content-Type: application/json" \ + -d "$JSON_PAYLOAD") + + echo "Response: $RESPONSE" + echo "✅ Email sent successfully!" diff --git a/.github/workflows/email-notify-check.yml b/.github/workflows/email-notify-check.yml new file mode 100644 index 0000000..480ec59 --- /dev/null +++ b/.github/workflows/email-notify-check.yml @@ -0,0 +1,125 @@ +name: Email Notification Test + +on: + workflow_dispatch: + inputs: + recipient_email: + description: 'Email address to send test to (leave empty to use MAIL_TO secret)' + required: false + type: string + +jobs: + send-test-email: + runs-on: ubuntu-latest + steps: + - name: Send Test Email (Resend) + env: + RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }} + MAIL_TO: ${{ inputs.recipient_email || secrets.MAIL_TO }} + MAIL_CC: ${{ secrets.MAIL_CC }} + MAIL_BCC: ${{ secrets.MAIL_BCC }} + MAIL_FROM: ${{ secrets.MAIL_FROM }} + run: | + if [ -z "$RESEND_API_KEY" ]; then + echo "❌ Error: RESEND_API_KEY secret is not set!" + exit 1 + fi + + if [ -z "$MAIL_TO" ]; then + echo "❌ Error: No email recipient specified!" + echo "Either provide recipient_email input or set MAIL_TO secret." + exit 1 + fi + + # Set default FROM address if not provided + FROM_ADDRESS="${MAIL_FROM:-ReVanced Build Bot }" + + VERSION="TEST-$(date +%Y%m%d-%H%M%S)" + RELEASE_URL="${{ github.server_url }}/${{ github.repository }}/releases" + REPO="${{ github.repository }}" + + # Create test HTML email body + HTML_BODY=$(cat < + + + + + +
    +

    🧪 Test Email

    +

    Version: ${VERSION}

    +
    +
    +
    +

    ✅ Email Configuration Working!

    +

    Nếu bạn nhận được email này, nghĩa là cấu hình Resend đã hoạt động chính xác.

    +
    +
    +

    📋 Configuration Details

    +
      +
    • 📧 From: ${FROM_ADDRESS}
    • +
    • 📬 To: ${MAIL_TO}
    • +
    • 🕐 Sent at: $(date -u '+%Y-%m-%d %H:%M:%S UTC')
    • +
    +
    + +
    +
    +

    This is a TEST email from ReVanced Build Bot

    +

    Repository: ${REPO}

    +
    + + + EOF + ) + + # Build JSON payload + JSON_PAYLOAD=$(jq -n \ + --arg from "$FROM_ADDRESS" \ + --arg to "$MAIL_TO" \ + --arg cc "$MAIL_CC" \ + --arg bcc "$MAIL_BCC" \ + --arg subject "🧪 [TEST] ReVanced Build Email - ${VERSION}" \ + --arg html "$HTML_BODY" \ + '{ + from: $from, + to: ($to | split(",") | map(select(. != "") | gsub("^\\s+|\\s+$"; ""))), + subject: $subject, + html: $html + } + + (if $cc != "" then {cc: ($cc | split(",") | map(select(. != "") | gsub("^\\s+|\\s+$"; "")))} else {} end) + + (if $bcc != "" then {bcc: ($bcc | split(",") | map(select(. != "") | gsub("^\\s+|\\s+$"; "")))} else {} end)' + ) + + echo "📧 Sending test email to: $MAIL_TO" + if [ -n "$MAIL_CC" ]; then echo "📋 CC: $MAIL_CC"; fi + if [ -n "$MAIL_BCC" ]; then echo "🔒 BCC: $MAIL_BCC"; fi + echo "" + + # Send email via Resend API + RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "https://api.resend.com/emails" \ + -H "Authorization: Bearer ${RESEND_API_KEY}" \ + -H "Content-Type: application/json" \ + -d "$JSON_PAYLOAD") + + HTTP_CODE=$(echo "$RESPONSE" | tail -n1) + BODY=$(echo "$RESPONSE" | sed '$d') + + echo "Response: $BODY" + echo "HTTP Code: $HTTP_CODE" + + if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then + echo "" + echo "✅ Test email sent successfully!" + echo "📬 Check your inbox at: $MAIL_TO" + else + echo "" + echo "❌ Failed to send email!" + echo "Please check your RESEND_API_KEY and email addresses." + exit 1 + fi