Skip to content

Commit

Permalink
feat: Notify dc & tg (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shebyyy authored Dec 3, 2024
1 parent 17cb1b8 commit 5965eba
Showing 1 changed file with 132 additions and 0 deletions.
132 changes: 132 additions & 0 deletions .github/workflows/Notify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Notify Release

on:
workflow_run:
workflows:
- "Build and Release AnymeX" # Name of the triggering workflow
types:
- completed
workflow_dispatch: # Allow manual triggering of this workflow

jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
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 }}"
- 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
- 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"
elif [[ "${RELEASE_NAME}" == *beta ]]; then
echo "DISCORD_WEBHOOK_URL=${{ secrets.DISCORD_WEBHOOK_BETA }}" >> $GITHUB_ENV
echo "Targeted to Beta channel"
else
echo "DISCORD_WEBHOOK_URL=${{ secrets.DISCORD_WEBHOOK }}" >> $GITHUB_ENV
echo "Targeted to Default channel"
fi
# Telegram - Send Release Notes
- 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}"
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
- 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="🚀 <b>Assets for Release: ${RELEASE_NAME}</b>\n\n<b>Assets:</b>${ASSET_LINKS}"
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
- name: Send Release Notes to Discord
run: |
CLEANED_RELEASE_NOTES=$(echo "${RELEASE_NOTES}" | sed 's/\\n//g')
echo "Cleaned Release Notes: $CLEANED_RELEASE_NOTES"
# Mention the role based on environment
if [[ "${RELEASE_NAME}" == *alpha ]]; then
ROLE_MENTION="<@&1313089691523878942>" # Use the actual Role ID for alpha channel
elif [[ "${RELEASE_NAME}" == *beta ]]; then
ROLE_MENTION="<@&1313087262539518033>" # Use the actual Role ID for beta channel
else
ROLE_MENTION="<@&1234567>" # Use the default role ID
fi
HEADER="${ROLE_MENTION}
## 🚀 New Release: ${RELEASE_NAME}
${CLEANED_RELEASE_NOTES}"
PAYLOAD=$(jq -n --arg content "$HEADER" '{ content: $content }')
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}"
PAYLOAD=$(jq -n --arg content "$MESSAGE" '{ content: $content }')
curl -X POST "${{ env.DISCORD_WEBHOOK_URL }}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"

0 comments on commit 5965eba

Please sign in to comment.