-
-
Notifications
You must be signed in to change notification settings - Fork 24
245 lines (211 loc) · 10.6 KB
/
Notify.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: Notify Release
on:
workflow_run:
workflows:
- "changelog" # Name of the triggering workflow
types:
- completed
workflow_dispatch: # Allow manual triggering of this workflow
jobs:
notify:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
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
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: |
curl -s "https://api.github.com/repos/RyanYuuki/AnymeX/tags" -o tags.json
TAGS=$(jq -r '.[].name' tags.json | sort -V)
LATEST_TAG=$(echo "$TAGS" | tail -n 1)
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)
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=[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.zip" ]]; then
echo "linux_message=[Download]($ASSET_URL) | $SIZE_HR" >> $GITHUB_ENV
elif [[ "$FILE_NAME" == *"Setup.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 [[ "${RELEASE_NAME}" == *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 Release Notes to Telegram
run: |
# Replace ### with **
commit=$(echo "$RELEASE_NOTES" | sed 's/^### /**/g')
# Replace * with 🔹 (excluding headings)
commit=$(echo "$commit" | sed 's/^* /🔹 /g')
# Replace "):" with ") :"
tel_commit=$(echo "$commit" | sed -E 's/\): [^:]+:/) :/g')
# Count total commits
commit_count=$(echo "$tel_commit" | grep -oE '\b[0-9a-f]{7,}\b' | wc -l)
# Set Telegram message character limit
max_length=3500
# Check if the message exceeds the limit
if [ ${#tel_commit} -gt $max_length ]; then
# Trim the message to the limit and count remaining commits
trimmed_commit=$(echo "$tel_commit" | head -c $max_length)
trimmed_commit=$(echo "$trimmed_commit" | tr -d '`')
trimmed_commit=$(echo "$trimmed_commit" | sed 's/^## /**/g')
remaining_commits=$((commit_count - $(echo "$trimmed_commit" | grep -oE '\b[0-9a-f]{7,}\b' | wc -l)))
# Construct the message with a note about remaining commits
MESSAGE="**🚀 New Release: ${RELEASE_NAME}**
Release Notes:
$trimmed_commit
📌 Note: There are $remaining_commits more commits.
[View Full changelog here](https://github.com/RyanYuuki/AnymeX/releases/tag/${{ env.LATEST_TAG }})"
else
# Use the complete commit message
MESSAGE="**🚀 New Release: ${RELEASE_NAME}**
Release Notes:
$tel_commit"
fi
# Log the MESSAGE for debugging
echo "Telegram Message: $MESSAGE"
# Send the message to Telegram
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",
"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.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 Release Notes to Discord
run: |
# Replace "): <text>" with ") : <text>" and format list items
discord_commit=$(echo "$RELEASE_NOTES" | sed -E 's/\): [^:]+:/) :/g' | sed 's/^* /> /g')
# Count the number of commit IDs
commit_count=$(echo "$discord_commit" | grep -oE '\b[0-9a-f]{7,}\b' | wc -l)
# Define maximum length for Discord messages
max_length=3000
# Check if the message exceeds the limit
if [ ${#discord_commit} -gt $max_length ]; then
# Trim the message to the limit and count remaining commits
trimmed_commit=$(echo "$discord_commit" | head -c $max_length)
remaining_commits=$((commit_count - $(echo "$trimmed_commit" | grep -oE '\b[0-9a-f]{7,}\b' | wc -l)))
# Construct the message with a note about remaining commits
discord_message="Release Notes:
$trimmed_commit
📌 Note: There are $remaining_commits more commits.*
[View Full changelog here](https://github.com/RyanYuuki/AnymeX/releases/tag/${{ env.LATEST_TAG }})"
else
# Use the full message if within the limit
discord_message="Release Notes:
$discord_commit"
fi
# Mention the role based on the release name
if [[ "${RELEASE_NAME}" == *alpha* ]]; then
role_mention="<@&1313089691523878942>" # Role ID for alpha channel
elif [[ "${RELEASE_NAME}" == *beta* ]]; then
role_mention="<@&1313087262539518033>" # Role ID for beta channel
else
role_mention="<@&1313346791479054456>" # Default role ID
fi
# Construct the payload for the Discord webhook
payload=$(jq -n \
--arg content "${role_mention}" \
--arg title "🚀 New Release: $RELEASE_NAME" \
--arg description "$discord_message" \
--argjson color 5814783 \
'{ content: $content, embeds: [{ title: $title, description: $description, color: $color }] }')
# Send the payload to the Discord webhook
curl -X POST "${{ env.DISCORD_WEBHOOK_URL }}" \
-H "Content-Type: application/json" \
-d "$payload"
- 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.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"