Skip to content

Commit

Permalink
Patch 5 (#31)
Browse files Browse the repository at this point in the history
* git: fix Notify
  • Loading branch information
Shebyyy authored Dec 7, 2024
1 parent 3a5787c commit dfb1e37
Showing 1 changed file with 149 additions and 55 deletions.
204 changes: 149 additions & 55 deletions .github/workflows/Notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ on:
types:
- completed
workflow_dispatch: # Allow manual triggering of this workflow

jobs:
notify:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
#if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
Expand All @@ -21,79 +21,162 @@ jobs:
with:
python-version: '3.x'

- name: Install jq (if needed)
run: sudo apt-get install -y jq
- name: Install jq
run: sudo apt-get install -y jq

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests jq
pip install requests jq
- name: Fetch Repository Tags
id: fetch_tags
run: |
# Fetch all tags from the GitHub API
curl -s "https://api.github.com/repos/RyanYuuki/AnymeX/tags" -o tags.json
# Extract tag names and sort them
TAGS=$(jq -r '.[].name' tags.json | sort -V)
LATEST_TAG=$(echo "$TAGS" | tail -n 1)
echo "Latest Tag: $LATEST_TAG"
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
- name: Use the Latest Tag
run: |
echo "The latest tag is: ${{ env.LATEST_TAG }}"
echo "The latest tag is: ${{ env.LATEST_TAG }}"
- name: Get Release Info
id: release_info
run: |
curl -s "https://api.github.com/repos/RyanYuuki/AnymeX/releases/tags/${{ env.LATEST_TAG }}" -o release.json
RELEASE_NAME=$(jq -r '.name // "No release name"' release.json)
RELEASE_NOTES=$(jq -r '.body // "No release notes"' release.json | sed ':a;N;$!ba;s/\n/\\n/g')
ASSET_URLS=$(jq -r '.assets[]?.browser_download_url // empty' release.json)
echo "RELEASE_NAME=${RELEASE_NAME}" >> $GITHUB_ENV
echo "RELEASE_NOTES=${RELEASE_NOTES}" >> $GITHUB_ENV
echo "${ASSET_URLS}" > assets.txt
# Determine webhook based on release name
RELEASE_NOTES=$(jq -r '.body // "No release notes"' release.json)
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV
# Write release notes as-is with newlines
echo -e "RELEASE_NOTES<<EOF\n$RELEASE_NOTES\nEOF" >> $GITHUB_ENV
- name: Get and Categorize Assets with Sizes
id: categorize_assets
run: |
# Fetch release assets based on the latest tag
curl -s "https://api.github.com/repos/RyanYuuki/AnymeX/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; 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.apk" ]]; then
echo "apk_arm64_message=$SIZE_HR | [Download]($ASSET_URL)" >> $GITHUB_ENV
elif [[ "$FILE_NAME" == *"-armeabi-v7a.apk" ]]; then
echo "apk_armeabi_message=$SIZE_HR | [Download]($ASSET_URL)" >> $GITHUB_ENV
elif [[ "$FILE_NAME" == *"-universal.apk" ]]; then
echo "apk_universal_message=$SIZE_HR | [Download]($ASSET_URL)" >> $GITHUB_ENV
elif [[ "$FILE_NAME" == *"-x86_64.apk" ]]; then
echo "apk_x86_64_message=$SIZE_HR | [Download]($ASSET_URL)" >> $GITHUB_ENV
elif [[ "$FILE_NAME" == *.ipa ]]; then
echo "ios_message=$SIZE_HR | [Download]($ASSET_URL)" >> $GITHUB_ENV
elif [[ "$FILE_NAME" == *"Linux.zip" ]]; then
echo "linux_message=$SIZE_HR | [Download]($ASSET_URL)" >> $GITHUB_ENV
elif [[ "$FILE_NAME" == *"Setup.exe" ]]; then
echo "setup_message=$SIZE_HR | [Download]($ASSET_URL)" >> $GITHUB_ENV
elif [[ "$FILE_NAME" == *"Windows.zip" ]]; then
echo "windows_message=$SIZE_HR | [Download]($ASSET_URL)" >> $GITHUB_ENV
elif [[ "$FILE_NAME" == *".dmg" ]]; then
echo "macos_message=$SIZE_HR | [Download]($ASSET_URL)" >> $GITHUB_ENV
fi
done
- name: Determine Webhook
id: determine_webhook
run: |
if [[ "${RELEASE_NAME}" == *alpha ]]; then
echo "DISCORD_WEBHOOK_URL=${{ secrets.DISCORD_WEBHOOK_ALPHA }}" >> $GITHUB_ENV
echo "Targeted to Alpha channel"
else
echo "DISCORD_WEBHOOK_URL=${{ secrets.DISCORD_WEBHOOK_BETA }}" >> $GITHUB_ENV
echo "Targeted to Default channel"
fi
# Telegram - Send Release Notes
- name: Determine Topic
id: determine_topic
run: |
if [[ "${RELEASE_NAME}" == *alpha ]]; then
echo "TELEGRAM_THREAD_ID=17602" >> $GITHUB_ENV
else
echo "TELEGRAM_THREAD_ID=17665" >> $GITHUB_ENV
fi
- name: Send Release Notes to Telegram
run: |
ROLE_MENTION="<b>@role</b>" # Add the actual role username if needed, or leave this empty if no mention
MESSAGE="🚀 <b>## New Release: ${RELEASE_NAME}</b>\n\n<b>Release Notes:</b>\n${ROLE_MENTION}\n${RELEASE_NOTES}"
# Assuming RELEASE_NOTES contains your original content
tel_commit="${RELEASE_NOTES}"
# Replace ### with **
tel_commit=$(echo "$tel_commit" | sed 's/^### /**/g')
# Replace * with 🔹 (excluding headings)
tel_commit=$(echo "$tel_commit" | sed 's/^* /🔹 /g')
# Replace ): with )
tel_commit=$(echo "$tel_commit" | sed -E 's/\): [^:]+:/) :/g')
# Display or use the modified text
echo "$tel_commit"
MESSAGE=" **🚀 New Release: ${RELEASE_NAME} **
Release Notes: $tel_commit"
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\": \"HTML\"}"
# Telegram - Send Assets
-d '{
"chat_id": "${{ secrets.TELEGRAM_CHAT_ID }}",
"message_thread_id": "${{ env.TELEGRAM_THREAD_ID }}",
"text": "'"$MESSAGE"'",
"parse_mode": "Markdown"
}'
- name: Send Assets to Telegram
run: |
ASSET_LINKS=""
while IFS= read -r ASSET_URL; do
FILE_NAME=$(basename "$ASSET_URL")
ASSET_LINKS="$ASSET_LINKS\n[Download $FILE_NAME:]($ASSET_URL)"
done < assets.txt
MESSAGE="🎉 *${{ env.LATEST_TAG }} Released* 🎉
MESSAGE="🚀 <b>Assets for Release: ${RELEASE_NAME}</b>\n\n<b>Assets:</b>${ASSET_LINKS}"
🔹 ${{ 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.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\": \"HTML\"}"
# Discord - Send Release Notes
-d '{
"chat_id": "${{ secrets.TELEGRAM_CHAT_ID }}",
"message_thread_id": "${{ env.TELEGRAM_THREAD_ID }}",
"text": "'"$MESSAGE"'",
"parse_mode": "Markdown"
}'
- name: Send Release Notes to Discord
run: |
CLEANED_RELEASE_NOTES=$(echo "${RELEASE_NOTES}" | sed 's/\\n//g')
echo "Cleaned Release Notes: $CLEANED_RELEASE_NOTES"
# Replace ): with )
discord_commit=$(echo "$RELEASE_NOTES" | sed -E 's/\): [^:]+:/) :/g')
# Mention the role based on environment
if [[ "${RELEASE_NAME}" == *alpha ]]; then
Expand All @@ -102,28 +185,39 @@ jobs:
ROLE_MENTION="<@&1313087262539518033>" # Use the actual Role ID for beta channel
else
ROLE_MENTION="<@&1313346791479054456>" # Use the default role ID
fi
HEADER="${ROLE_MENTION}
## 🚀 New Release: ${RELEASE_NAME}
${CLEANED_RELEASE_NOTES}"
PAYLOAD=$(jq -n --arg content "$HEADER" '{ content: $content }')
fi
PAYLOAD=$(jq -n \
--arg content "${ROLE_MENTION}" \
--arg title "🚀 New Release: $RELEASE_NAME" \
--arg description "$discord_commit" \
--argjson color 5814783 \
'{ content: $content, embeds: [{ title: $title, description: $description, color: $color }] }')
curl -X POST "${{ env.DISCORD_WEBHOOK_URL }}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"
# Discord - Send Assets
- name: Send Assets to Discord
run: |
ASSET_LINKS=""
while IFS= read -r ASSET_URL; do
FILE_NAME=$(basename "$ASSET_URL")
ASSET_LINKS="$ASSET_LINKS
**[$FILE_NAME]($ASSET_URL)**"
done < assets.txt
MESSAGE="## Assets for Release: ${RELEASE_NAME} ${ASSET_LINKS}"
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.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" \
Expand Down

0 comments on commit dfb1e37

Please sign in to comment.