Notify Release #61
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Notify Release | |
| on: | |
| workflow_run: | |
| workflows: | |
| - "changelog" | |
| types: | |
| - completed | |
| workflow_dispatch: | |
| jobs: | |
| notify: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Cloning repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Fetch Repository Tags by Date and Time | |
| id: fetch_tags | |
| run: | | |
| curl -s "https://api.github.com/repos/${{github.repository}}/tags" -o tags.json | |
| TAGS=$(jq -r '.[].name' tags.json) | |
| declare -a TAGS_WITH_DATES=() | |
| for TAG in $TAGS; do | |
| TAG_DETAILS=$(curl -s "https://api.github.com/repos/${{github.repository}}/git/refs/tags/$TAG") | |
| OBJECT_URL=$(echo "$TAG_DETAILS" | jq -r '.object.url // empty') | |
| if [ -n "$OBJECT_URL" ]; then | |
| OBJECT_DETAILS=$(curl -s "$OBJECT_URL") | |
| DATE=$(echo "$OBJECT_DETAILS" | jq -r '.tagger.date // .committer.date // empty') | |
| if [ -n "$DATE" ]; then | |
| TAGS_WITH_DATES+=("$DATE $TAG") | |
| fi | |
| fi | |
| done | |
| LATEST_TAG="" | |
| LATEST_DATE="" | |
| for TAG_DATE in "${TAGS_WITH_DATES[@]}"; do | |
| TAG_DATE_TIME=$(echo "$TAG_DATE" | awk '{print $1}') | |
| TAG_NAME=$(echo "$TAG_DATE" | awk '{print $2}') | |
| if [[ -z "$LATEST_DATE" || "$TAG_DATE_TIME" > "$LATEST_DATE" ]]; then | |
| LATEST_DATE="$TAG_DATE_TIME" | |
| LATEST_TAG="$TAG_NAME" | |
| fi | |
| done | |
| echo "$LATEST_TAG" | |
| echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV | |
| - name: Get Latest Release Notes | |
| id: get_release_notes | |
| run: | | |
| RELEASE_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.LATEST_TAG }}") | |
| RELEASE_NOTES=$(echo "$RELEASE_DATA" | jq -r '.body') | |
| echo "Release Notes: $RELEASE_NOTES" | |
| # Write to file to handle multiline content safely | |
| echo "$RELEASE_NOTES" > release_notes.txt | |
| - name: Format Release Notes | |
| id: format_notes | |
| run: | | |
| # Clean || markers | |
| sed 's/||//g' release_notes.txt > clean_release_notes.txt | |
| echo "" > formatted_notes.txt | |
| extract_section() { | |
| local title="$1" | |
| local emoji="$2" | |
| local start=$(grep -n "^### $emoji $title" clean_release_notes.txt | cut -d: -f1) | |
| if [ -z "$start" ]; then return; fi | |
| local next=$(tail -n +$((start + 1)) clean_release_notes.txt | grep -n '^### ' | head -n1 | cut -d: -f1) | |
| if [ -z "$next" ]; then | |
| content=$(tail -n +$((start + 1)) clean_release_notes.txt | grep '^-' | head -n 5) | |
| else | |
| end=$((start + next - 1)) | |
| content=$(sed -n "$((start + 1)),$((end - 1))p" clean_release_notes.txt | grep '^-' | head -n 5) | |
| fi | |
| if [ -n "$content" ]; then | |
| echo "### $emoji $title" >> formatted_notes.txt | |
| echo "$content" >> formatted_notes.txt | |
| echo "" >> formatted_notes.txt | |
| fi | |
| } | |
| extract_section "Features" "🌟" | |
| extract_section "Bug Fixes & Improvements" "🔧" | |
| extract_section "Refactors" "🔧" | |
| extract_section "Style Changes" "🎨" | |
| extract_section "Performance Improvements" "🚀" | |
| extract_section "Chores & Documentation" "🧹" | |
| echo "FORMATTED_NOTES<<EOF" >> $GITHUB_ENV | |
| cat formatted_notes.txt >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| echo "Preview of formatted notes:" | |
| cat formatted_notes.txt | |
| # You can now use ${{ env.FORMATTED_NOTES }} in your next Telegram/Discord steps | |
| - name: Get and Categorize Assets with Sizes | |
| id: categorize_assets | |
| run: | | |
| # Fetch release assets based on the latest tag | |
| curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.LATEST_TAG }}" -o release.json | |
| # Initialize environment variables | |
| for VAR in apk_arm64 apk_armeabi apk_universal apk_x86_64 windows linux ios setup macos linuximg linuxrmp; do | |
| echo "${VAR}_message=" >> $GITHUB_ENV | |
| done | |
| # Process each asset | |
| jq -r '.assets[] | "\(.browser_download_url) \(.size)"' release.json | while read -r LINE; do | |
| ASSET_URL=$(echo "$LINE" | awk '{print $1}') | |
| ASSET_SIZE=$(echo "$LINE" | awk '{print $2}') | |
| SIZE_HR=$(awk -v size="$ASSET_SIZE" 'BEGIN{ | |
| split("B KB MB GB TB", unit); | |
| for (i=1; size>=1024 && i<5; i++) size/=1024; | |
| printf "%.2f %s", size, unit[i] | |
| }') | |
| FILE_NAME=$(basename "$ASSET_URL") | |
| # Categorize and set variables | |
| if [[ "$FILE_NAME" == *"-arm64-v8a.apk" ]]; then | |
| echo "apk_arm64_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV | |
| elif [[ "$FILE_NAME" == *"-armeabi-v7a.apk" ]]; then | |
| echo "apk_armeabi_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV | |
| elif [[ "$FILE_NAME" == *"-universal.apk" ]]; then | |
| echo "apk_universal_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV | |
| elif [[ "$FILE_NAME" == *"-x86_64.apk" ]]; then | |
| echo "apk_x86_64_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV | |
| elif [[ "$FILE_NAME" == *.ipa ]]; then | |
| echo "ios_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV | |
| elif [[ "$FILE_NAME" == *"Linux.AppImage" ]]; then | |
| echo "linuximg_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV | |
| elif [[ "$FILE_NAME" == *"Linux.rpm" ]]; then | |
| echo "linuxrmp_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV | |
| elif [[ "$FILE_NAME" == *"Linux.zip" ]]; then | |
| echo "linux_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV | |
| elif [[ "$FILE_NAME" == *"Installer.exe" ]]; then | |
| echo "setup_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV | |
| elif [[ "$FILE_NAME" == *"Windows.zip" ]]; then | |
| echo "windows_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV | |
| elif [[ "$FILE_NAME" == *".dmg" ]]; then | |
| echo "macos_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV | |
| fi | |
| done | |
| - name: Determine Webhook | |
| id: determine_webhook | |
| run: | | |
| if [[ "${{ env.LATEST_TAG }}" == *"alpha"* ]]; then | |
| echo "DISCORD_WEBHOOK_URL=${{ secrets.DISCORD_WEBHOOK_ALPHA }}" >> $GITHUB_ENV | |
| else | |
| echo "DISCORD_WEBHOOK_URL=${{ secrets.DISCORD_WEBHOOK_BETA }}" >> $GITHUB_ENV | |
| fi | |
| - name: Send message to Telegram | |
| env: | |
| TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
| TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | |
| TELEGRAM_TOPIC: ${{ secrets.TELEGRAM_THREAD_ID }} | |
| run: | | |
| # Start with release header | |
| echo "<b>🚀 New Release: ${{ env.LATEST_TAG }}</b>" > header.txt | |
| # Clean release notes | |
| sed 's/||//g' release_notes.txt > clean_release_notes.txt | |
| # Function to extract section content | |
| extract_section_content() { | |
| local section_name="$1" | |
| local output_file="$2" | |
| local title_file="$3" | |
| local limit="${4:-5}" | |
| # Create title file | |
| echo "$title_file" > "T${section_name}.txt" | |
| # Find the section and extract content until next section or end | |
| awk -v section="$section_name" -v limit="$limit" ' | |
| BEGIN { found=0; count=0 } | |
| $0 ~ "^### .*" section { found=1; next } | |
| found && /^### / && $0 !~ section { found=0 } | |
| found && /^- \[/ && count < limit { | |
| print $0; count++ | |
| } | |
| ' clean_release_notes.txt > "$output_file" | |
| } | |
| # Extract each section with titles | |
| extract_section_content "Features" "feat.txt" "**🚀 Features**" 5 | |
| extract_section_content "Bug Fixes & Improvements" "fixes.txt" "**🐛 Fixes**" 5 | |
| extract_section_content "Refactors" "refactors.txt" "**🔧 Refactors**" 3 | |
| extract_section_content "Style Changes" "style.txt" "**💅 Style**" 3 | |
| extract_section_content "Performance Improvements" "perf.txt" "**⚡ Performance**" 3 | |
| extract_section_content "Chores & Documentation" "chores.txt" "**🛠 Chores**" 3 | |
| # Process each file through the parser if it exists | |
| if [ -f scripts/tel_commit_parser.sed ]; then | |
| chmod +x scripts/tel_commit_parser.sed | |
| # Process files directly through your parser (preserving original format) | |
| ./scripts/tel_commit_parser.sed feat.txt > feat_clean.txt || cp feat.txt feat_clean.txt | |
| ./scripts/tel_commit_parser.sed fixes.txt > fixes_clean.txt || cp fixes.txt fixes_clean.txt | |
| ./scripts/tel_commit_parser.sed refactors.txt > refactors_clean.txt || cp refactors.txt refactors_clean.txt | |
| ./scripts/tel_commit_parser.sed style.txt > style_clean.txt || cp style.txt style_clean.txt | |
| ./scripts/tel_commit_parser.sed perf.txt > perf_clean.txt || cp perf.txt perf_clean.txt | |
| ./scripts/tel_commit_parser.sed chores.txt > chores_clean.txt || cp chores.txt chores_clean.txt | |
| echo "**🚀 Features**" | ./scripts/tel_commit_parser.sed > TFeaturesT.txt | |
| echo "**🐛 Fixes**" | ./scripts/tel_commit_parser.sed > TFixesT.txt | |
| echo "**🔧 Refactors**" | ./scripts/tel_commit_parser.sed > TRefactorsT.txt | |
| echo "**💅 Style**" | ./scripts/tel_commit_parser.sed > TStyleT.txt | |
| echo "**⚡ Performance**" | ./scripts/tel_commit_parser.sed > TPerformanceT.txt | |
| echo "**🛠 Chores**" | ./scripts/tel_commit_parser.sed > TChoresT.txt | |
| else | |
| # If no parser script, just convert format manually | |
| sed -E 's/^- \[֍\]\(([^)]+)\)\s+(.+)/● <a href="\1">֍<\/a> \2/g' feat.txt > feat_clean.txt | |
| sed -E 's/^- \[֍\]\(([^)]+)\)\s+(.+)/● <a href="\1">֍<\/a> \2/g' fixes.txt > fixes_clean.txt | |
| sed -E 's/^- \[֍\]\(([^)]+)\)\s+(.+)/● <a href="\1">֍<\/a> \2/g' refactors.txt > refactors_clean.txt | |
| sed -E 's/^- \[֍\]\(([^)]+)\)\s+(.+)/● <a href="\1">֍<\/a> \2/g' style.txt > style_clean.txt | |
| sed -E 's/^- \[֍\]\(([^)]+)\)\s+(.+)/● <a href="\1">֍<\/a> \2/g' perf.txt > perf_clean.txt | |
| sed -E 's/^- \[֍\]\(([^)]+)\)\s+(.+)/● <a href="\1">֍<\/a> \2/g' chores.txt > chores_clean.txt | |
| echo "<strong>🚀 Features</strong>" > TFeaturesT.txt | |
| echo "<strong>🐛 Fixes</strong>" > TFixesT.txt | |
| echo "<strong>🔧 Refactors</strong>" > TRefactorsT.txt | |
| echo "<strong>💅 Style</strong>" > TStyleT.txt | |
| echo "<strong>⚡ Performance</strong>" > TPerformanceT.txt | |
| echo "<strong>🛠 Chores</strong>" > TChoresT.txt | |
| fi | |
| # Check and remove empty categories | |
| if [ ! -s feat_clean.txt ] || [ "$(tr -d '[:space:]' < feat_clean.txt)" = "" ]; then | |
| rm -f feat_clean.txt TFeaturesT.txt | |
| fi | |
| if [ ! -s fixes_clean.txt ] || [ "$(tr -d '[:space:]' < fixes_clean.txt)" = "" ]; then | |
| rm -f fixes_clean.txt TFixesT.txt | |
| fi | |
| if [ ! -s refactors_clean.txt ] || [ "$(tr -d '[:space:]' < refactors_clean.txt)" = "" ]; then | |
| rm -f refactors_clean.txt TRefactorsT.txt | |
| fi | |
| if [ ! -s style_clean.txt ] || [ "$(tr -d '[:space:]' < style_clean.txt)" = "" ]; then | |
| rm -f style_clean.txt TStyleT.txt | |
| fi | |
| if [ ! -s perf_clean.txt ] || [ "$(tr -d '[:space:]' < perf_clean.txt)" = "" ]; then | |
| rm -f perf_clean.txt TPerformanceT.txt | |
| fi | |
| if [ ! -s chores_clean.txt ] || [ "$(tr -d '[:space:]' < chores_clean.txt)" = "" ]; then | |
| rm -f chores_clean.txt TChoresT.txt | |
| fi | |
| # Combine categories into final output | |
| { | |
| cat header.txt | |
| echo "" | |
| [ -f TFeaturesT.txt ] && [ -f feat_clean.txt ] && echo -n "$(cat TFeaturesT.txt) <blockquote>$(cat feat_clean.txt)</blockquote> " | |
| [ -f TFixesT.txt ] && [ -f fixes_clean.txt ] && echo -n "$(cat TFixesT.txt) <blockquote>$(cat fixes_clean.txt)</blockquote> " | |
| [ -f TRefactorsT.txt ] && [ -f refactors_clean.txt ] && echo -n "$(cat TRefactorsT.txt) <blockquote>$(cat refactors_clean.txt)</blockquote> " | |
| [ -f TStyleT.txt ] && [ -f style_clean.txt ] && echo -n "$(cat TStyleT.txt) <blockquote>$(cat style_clean.txt)</blockquote> " | |
| [ -f TPerformanceT.txt ] && [ -f perf_clean.txt ] && echo -n "$(cat TPerformanceT.txt) <blockquote>$(cat perf_clean.txt)</blockquote> " | |
| [ -f TChoresT.txt ] && [ -f chores_clean.txt ] && echo -n "$(cat TChoresT.txt) <blockquote>$(cat chores_clean.txt)</blockquote> " | |
| echo "" | |
| echo "❓<a href='https://github.com/${{ github.repository }}/blob/main/INSTALLATION.md'>Don't know which version to download? Click here!</a>" | |
| echo "" | |
| echo "📌 <a href='https://github.com/${{github.repository}}/releases/tag/${{ env.LATEST_TAG }}'>Full changelog</a>" | |
| } > output.txt | |
| if [ ! -s output.txt ]; then | |
| echo "No commits found. Skipping Telegram message." | |
| exit 0 | |
| fi | |
| markdown_info_tel=$(< output.txt) | |
| echo "Final Telegram Message:" | |
| echo "$markdown_info_tel" | |
| curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \ | |
| -d "chat_id=$TELEGRAM_CHAT_ID" \ | |
| -d "text=$markdown_info_tel" \ | |
| -d "parse_mode=HTML" \ | |
| -d "disable_web_page_preview=true" | |
| - name: Send Assets to Telegram | |
| run: | | |
| MESSAGE="🎉 *${{ env.LATEST_TAG }} Released* 🎉 | |
| 🔹 ${{ env.apk_arm64_message }} | **APK (arm64)** | |
| 🔹 ${{ env.apk_armeabi_message }} | **APK (armeabi-v7a)** | |
| 🔹 ${{ env.apk_universal_message }} | **APK (universal)** | |
| 🔹 ${{ env.apk_x86_64_message }} | **APK (x86 & x64)** | |
| 🔹 ${{ env.windows_message }} | **Windows Zip** | |
| 🔹 ${{ env.setup_message }} | **Windows EXE** | |
| 🔹 ${{ env.linuximg_message }} | **Linux appimage** | |
| 🔹 ${{ env.linuxrmp_message }} | **Linux rmp** | |
| 🔹 ${{ env.linux_message }} | **Linux** | |
| 🔹 ${{ env.ios_message }} | **iOS** | |
| 🔹 ${{ env.macos_message }} | **macOS**" | |
| curl -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "chat_id": "${{ secrets.TELEGRAM_CHAT_ID }}", | |
| "text": "'"$MESSAGE"'", | |
| "parse_mode": "Markdown" | |
| }' | |
| - name: Send message to Discord | |
| env: | |
| DISCORD_WEBHOOK_URL: ${{ env.DISCORD_WEBHOOK_URL }} | |
| run: | | |
| FORMATTED_NOTES_CLEAN=$(echo "$FORMATTED_NOTES" | sed -E 's/\): [^:]+:/) :/g') | |
| # Mention the role based on the release name | |
| if [[ "${{ env.LATEST_TAG }}" == *alpha* ]]; then | |
| role_mention="<@&1313089691523878942>" # Role ID for alpha channel | |
| elif [[ "${{ env.LATEST_TAG }}" == *beta* ]]; then | |
| role_mention="<@&1313087262539518033>" # Role ID for beta channel | |
| else | |
| role_mention="<@&1313346791479054456>" # Default role ID | |
| fi | |
| default_color="#1ac4c5" | |
| hex_to_decimal() { printf '%d' "0x${1#"#"}"; } | |
| embed_color=$(hex_to_decimal "$default_color") | |
| # Ensure VERSION is not empty | |
| VERSION=${VERSION:-"${{env.LATEST_TAG}}"} | |
| discord_data=$(jq -nc \ | |
| --arg role_mention "$role_mention" \ | |
| --arg field_value "$FORMATTED_NOTES_CLEAN | |
| [❓Don't know which version to download? Click here!](https://github.com/${{ github.repository }}/blob/main/INSTALLATION.md) | |
| [📌 Full changelog](https://github.com/${{ github.repository }}/releases/tag/${{ env.LATEST_TAG }})" \ | |
| --arg footer_text "Version $VERSION" \ | |
| --arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" \ | |
| --argjson embed_color "$embed_color" \ | |
| '{ | |
| "content": $role_mention, | |
| "embeds": [ | |
| { | |
| "title": "🚀 New Release: ${{env.LATEST_TAG}}", | |
| "color": $embed_color, | |
| "description": $field_value, | |
| "footer": { | |
| "text": $footer_text | |
| }, | |
| "timestamp": $timestamp | |
| } | |
| ] | |
| }') | |
| echo "Debug: Final Discord payload is: $discord_data" | |
| # Send the message to Discord using the webhook | |
| curl -H "Content-Type: application/json" \ | |
| -X POST \ | |
| -d "$discord_data" \ | |
| "$DISCORD_WEBHOOK_URL" | |
| - name: Send Assets to Discord | |
| run: | | |
| MESSAGE="${{ env.LATEST_TAG }} Released | |
| 🔹 ${{ env.apk_arm64_message }} | **APK (arm64)** | |
| 🔹 ${{ env.apk_armeabi_message }} | **APK (armeabi-v7a)** | |
| 🔹 ${{ env.apk_universal_message }} | **APK (universal)** | |
| 🔹 ${{ env.apk_x86_64_message }} | **APK (x86 & x64)** | |
| 🔹 ${{ env.windows_message }} | **Windows Zip** | |
| 🔹 ${{ env.setup_message }} | **Windows EXE** | |
| 🔹 ${{ env.linuximg_message }} | **Linux appimage** | |
| 🔹 ${{ env.linuxrmp_message }} | **Linux rmp** | |
| 🔹 ${{ env.linux_message }} | **Linux** | |
| 🔹 ${{ env.ios_message }} | **iOS** | |
| 🔹 ${{ env.macos_message }} | **macOS**" | |
| PAYLOAD=$(jq -n --arg content "$MESSAGE" '{ content: $content }') | |
| curl -X POST "${{ env.DISCORD_WEBHOOK_URL }}" \ | |
| -H "Content-Type: application/json" \ | |
| -d "$PAYLOAD" |