From 788e38af7a18571c30aa54e9464f47fe8fe70a29 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:18:42 +0000 Subject: [PATCH 1/5] Initial plan From c10f466e022072dbc7f7aadc02181b3a7044638d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:26:29 +0000 Subject: [PATCH 2/5] Add Telegram notification system for releases Co-authored-by: hcastc00 <47385090+hcastc00@users.noreply.github.com> --- .github/workflows/release.yml | 10 ++++ README.md | 2 + installer_instructions/INSTALLER.md | 30 ++++++++++ scripts/telegram_notify.sh | 83 +++++++++++++++++++++++++++ test/test_telegram_notify.sh | 88 +++++++++++++++++++++++++++++ 5 files changed, 213 insertions(+) create mode 100755 scripts/telegram_notify.sh create mode 100755 test/test_telegram_notify.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d6a3b89a..e801692c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -187,3 +187,13 @@ jobs: source: SHASUM_UBUNTU_UNATTENDED.txt,./images/Dappnode-*-ubuntu-*-unattended.iso target: ${{ secrets.ISO_SSH_PATH }} overwrite: true + + - name: Send Telegram notification + if: success() + run: | + chmod +x ./scripts/telegram_notify.sh + RELEASE_URL="https://github.com/dappnode/DAppNode/releases/tag/${{ github.event.inputs.core }}" + ./scripts/telegram_notify.sh "${{ github.event.inputs.core }}" "${RELEASE_URL}" + env: + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} diff --git a/README.md b/README.md index 89817f1c..e7bbab67 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,8 @@ The release will contain: - Changes section - SHASUMs for unattended and attended ISOs - Default credentials +- Notifications: + - Automatic Telegram notification to the configured chat (requires `TELEGRAM_BOT_TOKEN` and `TELEGRAM_CHAT_ID` repository secrets) ## Testing with artifacts diff --git a/installer_instructions/INSTALLER.md b/installer_instructions/INSTALLER.md index 626dadb0..1e39e390 100644 --- a/installer_instructions/INSTALLER.md +++ b/installer_instructions/INSTALLER.md @@ -44,3 +44,33 @@ The release action will generate all the assets required as well as the release- 2. Set inputs for the release ![](inputs-release.png) + +### Telegram Release Notifications + +DAppNode can automatically send Telegram notifications when new releases are created. This requires setting up the following repository secrets: + +#### Setup Instructions + +1. **Create a Telegram Bot**: + - Message `@BotFather` on Telegram + - Use `/newbot` command and follow the instructions + - Save the bot token (format: `123456789:ABCdefGHIjklMNOpqrsTUVwxyz`) + +2. **Get the Chat ID**: + - Add your bot to the desired chat/channel + - Send a message to the chat + - Visit `https://api.telegram.org/bot/getUpdates` + - Find the `chat.id` in the response + +3. **Configure Repository Secrets**: + - Go to repository Settings → Secrets and variables → Actions + - Add the following secrets: + - `TELEGRAM_BOT_TOKEN`: Your bot token from BotFather + - `TELEGRAM_CHAT_ID`: The chat ID where notifications should be sent + +#### Message Format + +The notification message includes: +- Release version +- Direct link to the GitHub release page +- Formatted message with emojis and hashtags for easy identification diff --git a/scripts/telegram_notify.sh b/scripts/telegram_notify.sh new file mode 100755 index 00000000..61f5b582 --- /dev/null +++ b/scripts/telegram_notify.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# Telegram notification script for DAppNode releases +# This script sends a notification to a Telegram chat when a new release is created + +set -e + +# Function to display usage +show_usage() { + echo "Usage: $0 " + echo "Example: $0 v0.2.51 https://github.com/dappnode/DAppNode/releases/tag/v0.2.51" + exit 1 +} + +# Function to send telegram message +send_telegram_message() { + local message="$1" + local bot_token="$TELEGRAM_BOT_TOKEN" + local chat_id="$TELEGRAM_CHAT_ID" + + if [ -z "$bot_token" ]; then + echo "Error: TELEGRAM_BOT_TOKEN environment variable is not set" + exit 1 + fi + + if [ -z "$chat_id" ]; then + echo "Error: TELEGRAM_CHAT_ID environment variable is not set" + exit 1 + fi + + # Send the message using curl + curl -s -X POST "https://api.telegram.org/bot${bot_token}/sendMessage" \ + -H "Content-Type: application/json" \ + -d "{ + \"chat_id\": \"${chat_id}\", + \"text\": \"${message}\", + \"parse_mode\": \"Markdown\", + \"disable_web_page_preview\": false + }" > /dev/null + + local exit_code=$? + if [ $exit_code -eq 0 ]; then + echo "Telegram notification sent successfully" + else + echo "Failed to send Telegram notification (exit code: $exit_code)" + exit 1 + fi +} + +# Check if required arguments are provided +if [ $# -ne 2 ]; then + echo "Error: Missing required arguments" + show_usage +fi + +RELEASE_VERSION="$1" +RELEASE_URL="$2" + +# Validate release version format +if [[ ! $RELEASE_VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: Release version must be in format vX.Y.Z (e.g., v0.2.51)" + exit 1 +fi + +# Validate release URL +if [[ ! $RELEASE_URL =~ ^https://github\.com/dappnode/DAppNode/releases/tag/.+ ]]; then + echo "Error: Invalid release URL format" + exit 1 +fi + +# Create the message +MESSAGE="🚀 *New DAppNode Release Available!* + +📦 **Version:** \`${RELEASE_VERSION}\` +🔗 **Download:** [${RELEASE_VERSION}](${RELEASE_URL}) + +The latest DAppNode release is now available with updated core packages and improvements. Visit the release page to download the installation ISOs and view the complete changelog. + +#DAppNode #Release #Decentralized" + +# Send the notification +echo "Sending Telegram notification for release ${RELEASE_VERSION}..." +send_telegram_message "$MESSAGE" \ No newline at end of file diff --git a/test/test_telegram_notify.sh b/test/test_telegram_notify.sh new file mode 100755 index 00000000..1e781fbe --- /dev/null +++ b/test/test_telegram_notify.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# Test script for telegram_notify.sh +# Tests the validation logic and message formatting + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +TELEGRAM_SCRIPT="${SCRIPT_DIR}/../scripts/telegram_notify.sh" + +echo "Testing Telegram notification script..." + +# Test 1: No arguments +echo "Test 1: No arguments" +if $TELEGRAM_SCRIPT 2>/dev/null; then + echo "❌ FAILED: Should have failed with no arguments" + exit 1 +else + echo "✅ PASSED: Correctly failed with no arguments" +fi + +# Test 2: Invalid version format +echo "Test 2: Invalid version format" +if $TELEGRAM_SCRIPT "0.2.51" "https://github.com/dappnode/DAppNode/releases/tag/v0.2.51" 2>/dev/null; then + echo "❌ FAILED: Should have failed with invalid version format" + exit 1 +else + echo "✅ PASSED: Correctly failed with invalid version format" +fi + +# Test 3: Invalid URL format +echo "Test 3: Invalid URL format" +if $TELEGRAM_SCRIPT "v0.2.51" "https://invalid-url.com" 2>/dev/null; then + echo "❌ FAILED: Should have failed with invalid URL format" + exit 1 +else + echo "✅ PASSED: Correctly failed with invalid URL format" +fi + +# Test 4: Valid arguments but missing environment variables +echo "Test 4: Valid arguments but missing environment variables" +if $TELEGRAM_SCRIPT "v0.2.51" "https://github.com/dappnode/DAppNode/releases/tag/v0.2.51" 2>/dev/null; then + echo "❌ FAILED: Should have failed with missing environment variables" + exit 1 +else + echo "✅ PASSED: Correctly failed with missing environment variables" +fi + +# Test 5: Valid arguments with mock environment variables (dry run) +echo "Test 5: Valid arguments with test environment variables" +export TELEGRAM_BOT_TOKEN="test_token_123456" +export TELEGRAM_CHAT_ID="test_chat_id" + +# Create a mock curl command that doesn't actually send anything +create_mock_curl() { + cat > /tmp/mock_curl.sh << 'EOF' +#!/bin/bash +# Mock curl command for testing +if [[ "$*" == *"sendMessage"* ]]; then + echo "Mock: Telegram message would be sent" + exit 0 +fi +exec /usr/bin/curl "$@" +EOF + chmod +x /tmp/mock_curl.sh +} + +# Test the script with a dry run by temporarily replacing curl +create_mock_curl +export PATH="/tmp:$PATH" + +# Temporarily modify the telegram script to use our mock curl +sed 's|curl -s|/tmp/mock_curl.sh -s|g' $TELEGRAM_SCRIPT > /tmp/telegram_notify_test.sh +chmod +x /tmp/telegram_notify_test.sh + +if /tmp/telegram_notify_test.sh "v0.2.51" "https://github.com/dappnode/DAppNode/releases/tag/v0.2.51" 2>/dev/null; then + echo "✅ PASSED: Script executed successfully with valid arguments" +else + echo "❌ FAILED: Script should have succeeded with valid arguments and environment variables" + exit 1 +fi + +# Clean up +rm -f /tmp/mock_curl.sh /tmp/telegram_notify_test.sh +unset TELEGRAM_BOT_TOKEN TELEGRAM_CHAT_ID + +echo "" +echo "🎉 All tests passed! The Telegram notification script is working correctly." \ No newline at end of file From f551fe293ceb50cd00f22d55726242d258ff80c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor?= <47385090+hcastc00@users.noreply.github.com> Date: Thu, 25 Sep 2025 16:31:28 +0200 Subject: [PATCH 3/5] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index e7bbab67..89817f1c 100644 --- a/README.md +++ b/README.md @@ -203,8 +203,6 @@ The release will contain: - Changes section - SHASUMs for unattended and attended ISOs - Default credentials -- Notifications: - - Automatic Telegram notification to the configured chat (requires `TELEGRAM_BOT_TOKEN` and `TELEGRAM_CHAT_ID` repository secrets) ## Testing with artifacts From f291bf8c5f0fc24ae27d4e68fbd13575b53fcf44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor?= <47385090+hcastc00@users.noreply.github.com> Date: Thu, 25 Sep 2025 16:32:06 +0200 Subject: [PATCH 4/5] Update INSTALLER.md --- installer_instructions/INSTALLER.md | 30 ----------------------------- 1 file changed, 30 deletions(-) diff --git a/installer_instructions/INSTALLER.md b/installer_instructions/INSTALLER.md index 1e39e390..626dadb0 100644 --- a/installer_instructions/INSTALLER.md +++ b/installer_instructions/INSTALLER.md @@ -44,33 +44,3 @@ The release action will generate all the assets required as well as the release- 2. Set inputs for the release ![](inputs-release.png) - -### Telegram Release Notifications - -DAppNode can automatically send Telegram notifications when new releases are created. This requires setting up the following repository secrets: - -#### Setup Instructions - -1. **Create a Telegram Bot**: - - Message `@BotFather` on Telegram - - Use `/newbot` command and follow the instructions - - Save the bot token (format: `123456789:ABCdefGHIjklMNOpqrsTUVwxyz`) - -2. **Get the Chat ID**: - - Add your bot to the desired chat/channel - - Send a message to the chat - - Visit `https://api.telegram.org/bot/getUpdates` - - Find the `chat.id` in the response - -3. **Configure Repository Secrets**: - - Go to repository Settings → Secrets and variables → Actions - - Add the following secrets: - - `TELEGRAM_BOT_TOKEN`: Your bot token from BotFather - - `TELEGRAM_CHAT_ID`: The chat ID where notifications should be sent - -#### Message Format - -The notification message includes: -- Release version -- Direct link to the GitHub release page -- Formatted message with emojis and hashtags for easy identification From c78b31341002dd72812a94e8d44a4b0cca55b2b0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:45:30 +0000 Subject: [PATCH 5/5] Add Telegram test to CI workflow Co-authored-by: hcastc00 <47385090+hcastc00@users.noreply.github.com> --- .github/workflows/test.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d7c85e1b..bd7d0343 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,7 @@ jobs: sudo /bin/bash ./scripts/dappnode_install.sh - name: Show installation logs run: | - cat /usr/src/dappnode/logs/install.log + cat /usr/src/dappnode/logs/install.log cat /usr/src/dappnode/logs/dappnode_install.log - name: Uninstall DAppNode run: | @@ -64,3 +64,16 @@ jobs: - name: verify Ubuntu ISO run: | ls -lrt images/Dappnode-ubuntu-*.iso + + telegram: + name: test Telegram notification + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run Telegram notification tests + run: | + chmod +x ./test/test_telegram_notify.sh + ./test/test_telegram_notify.sh