This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
forked from yujincheng08/BiliRoaming
-
Notifications
You must be signed in to change notification settings - Fork 20
551 lines (504 loc) · 20.7 KB
/
check-bilibili-version.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
name: Check Bilibili Version
on:
workflow_dispatch:
inputs:
only_cache:
type: boolean
description: Only for cache?
required: true
default: false
force:
type: boolean
description: Force build?
required: true
default: false
schedule:
- cron: '1 1-10 * * 1-5'
# To make cache always available
- cron: '1 23 */5 * *'
# push:
# branches: [me]
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
jobs:
check:
name: Check Version
runs-on: ubuntu-latest
env:
ONLY_CACHE: ${{ github.event.inputs.only_cache == 'true' }}
FORCE: ${{ github.event.inputs.force == 'true' }}
outputs:
new_bili: ${{ steps.check.outputs.new_bili }}
new_my: ${{ steps.check.outputs.new_my }}
changelog: ${{ steps.check.outputs.changelog }}
ver: ${{ steps.check.outputs.ver }}
ver_code: ${{ steps.check.outputs.ver_code }}
url: ${{ steps.check.outputs.url }}
size: ${{ steps.check.outputs.size }}
md5: ${{ steps.check.outputs.md5 }}
sn: ${{ steps.check.outputs.sn }}
iv: ${{ steps.check.outputs.iv }}
cycle: ${{ steps.check.outputs.cycle }}
steps:
- name: Check event
run: |
event_name="${{ github.event_name }}"
time_hour=`date +%k`
if [[ "$event_name" = "schedule" && $time_hour -eq 23 ]]; then
echo "ONLY_CACHE=true" >> $GITHUB_ENV
echo "Only for cache by schedule event."
fi
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python
if: env.ONLY_CACHE != 'true'
uses: actions/setup-python@v4
with:
python-version: '3.9.x'
- name: Generate random number
id: get-random
run: |
random=`date +%s`
echo "random=$random" >> $GITHUB_OUTPUT
- name: Version file cache
uses: actions/cache@v3
with:
path: version
key: cache-version-V40-${{ steps.get-random.outputs.random }}
restore-keys: cache-version-V40
- name: Check version
if: env.ONLY_CACHE != 'true'
id: check
run: |
if [[ "$FORCE" != "true" && -f "version" ]]; then
changelog=`awk -F "=" '$1 == "changelog" {print $2}' version`
ver=`awk -F "=" '$1 == "ver" {print $2}' version`
ver_code=`awk -F "=" '$1 == "ver_code" {print $2}' version`
url=`awk -F "=" '$1 == "url" {print $2}' version`
size=`awk -F "=" '$1 == "size" {print $2}' version`
md5=`awk -F "=" '$1 == "md5" {print $2}' version`
sn=`awk -F "=" '$1 == "sn" {print $2}' version`
iv=`awk -F "=" '$1 == "iv" {print $2}' version`
cycle=`awk -F "=" '$1 == "cycle" {print $2}' version`
my_ver=`awk -F "=" '$1 == "my_ver" {print $2}' version`
else
ver="7.26.0"; ver_code="7260200"; sn="11711174"; iv="7260210"
fi
pip3 install -U pip
pip3 install -U requests
py_get_ver_info=$(cat <<EOM
import re
import requests
url = 'https://app.bilibili.com/x/v2/version/fawkes/upgrade'
params = {
'abi': 'arm64-v8a',
'appid': 'tv.danmaku.bili',
'appkey': '1d8b6e7d45233436',
'build': '$ver_code',
'channel': 'master',
'env': 'prod',
'iv': '$iv',
'mobi_app': 'android',
'nt': '1',
'ov': '31',
'platform': 'android',
'sn': '$sn',
'vn': '$ver',
}
headers = {
'user-agent': 'Mozilla/5.0 BiliDroid/$ver ([email protected])',
'app-key': 'android64',
'env': 'prod',
'buvid': 'XX61AAD69F83AE28E1FA13EDEFCA9431F1C02',
'cache-control': 'no-cache',
}
try:
resp = requests.get(url, params, headers=headers).json()
if resp['code'] == -304:
print('no')
else:
content = resp['data']['content']
ver = resp['data']['version']
ver_code = resp['data']['version_code']
url = resp['data']['url']
size = resp['data']['size']
md5 = resp['data']['md5']
cycle = resp['data']['cycle']
sn = ''
sn_regex = re.compile(r'^https?://dl\.hdslb\.com/mobile/pack/android64/(\d+)/iBiliPlayer-apinkRelease-\d+\.\d+\.\d+-b\d+\.apk$')
if matcher := sn_regex.match(url):
sn = matcher.group(1)
iv = int(ver_code) + 10
result = f'{content}|{ver}|{ver_code}|{url}|{size}|{md5}|{sn}|{iv}|{cycle}'
print(result.replace('\n', r'\n'))
except Exception:
print('')
EOM
)
n_my_ver=`awk -F "=" '$1 == "appVerName" {print $2}' gradle.properties`
push_event="${{ github.event_name == 'push' }}"
ver_info="`python3 -c "$py_get_ver_info"`"
function check_module_version(){
if [ "$n_my_ver" != "$my_ver" ]; then
echo "Found new module: $n_my_ver"
sed -r -i "s/(my_ver)=.*/\1=$n_my_ver/" version
echo "new_my=1" >> $GITHUB_OUTPUT
echo "changelog=$changelog" >> $GITHUB_OUTPUT
echo "ver=$ver" >> $GITHUB_OUTPUT
echo "ver_code=$ver_code" >> $GITHUB_OUTPUT
echo "url=$url" >> $GITHUB_OUTPUT
echo "size=$size" >> $GITHUB_OUTPUT
echo "md5=$md5" >> $GITHUB_OUTPUT
echo "sn=$sn" >> $GITHUB_OUTPUT
echo "iv=$iv" >> $GITHUB_OUTPUT
echo "cycle=$cycle" >> $GITHUB_OUTPUT
else
echo "Not found new module."
echo "new_my=0" >> $GITHUB_OUTPUT
fi
}
if [ -z "$ver_info" ]; then
exit 0
elif [ "$push_event" = "true" ]; then
check_module_version
exit 0
elif [ "$ver_info" = "no" ]; then
echo "Not found new bilibili."
echo "new_bili=0" >> $GITHUB_OUTPUT
check_module_version
exit 0
fi
OLD_IFS="$IFS"
IFS="|"
infos=($ver_info)
IPS="$OLD_IFS"
n_changelog="${infos[0]}"
n_ver="${infos[1]}"
n_ver_code="${infos[2]}"
n_url="${infos[3]}"
n_size="${infos[4]}"
n_md5="${infos[5]}"
n_sn="${infos[6]}"
n_iv="${infos[7]}"
n_cycle="${infos[8]}"
echo "Found new bilibili: $n_ver ($n_ver_code) b$n_sn"
echo "Changelog: $n_changelog"
echo "Download url: $n_url"
if [[ -n "$my_ver" && "$n_my_ver" != "$my_ver" ]]; then
echo "Found new module: $n_my_ver"
echo "new_my=1" >> $GITHUB_OUTPUT
fi
echo "changelog=$n_changelog" > version
echo "ver=$n_ver" >> version
echo "ver_code=$n_ver_code" >> version
echo "url=$n_url" >> version
echo "size=$n_size" >> version
echo "md5=$n_md5" >> version
echo "sn=$n_sn" >> version
echo "iv=$n_iv" >> version
echo "cycle=$n_cycle" >> version
echo "my_ver=$n_my_ver" >> version
echo "new_bili=1" >> $GITHUB_OUTPUT
echo "changelog=$n_changelog" >> $GITHUB_OUTPUT
echo "ver=$n_ver" >> $GITHUB_OUTPUT
echo "ver_code=$n_ver_code" >> $GITHUB_OUTPUT
echo "url=$n_url" >> $GITHUB_OUTPUT
echo "size=$n_size" >> $GITHUB_OUTPUT
echo "md5=$n_md5" >> $GITHUB_OUTPUT
echo "sn=$n_sn" >> $GITHUB_OUTPUT
echo "iv=$n_iv" >> $GITHUB_OUTPUT
echo "cycle=$n_cycle" >> $GITHUB_OUTPUT
module:
name: Build Module
runs-on: ubuntu-latest
needs: check
if: needs.check.outputs.new_bili == '1' || needs.check.outputs.new_my == '1'
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache
CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion"
CCACHE_NOHASHDIR: true
CCACHE_MAXSIZE: 1G
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
cache: 'gradle'
- name: Retrieve version
run: |
version=`awk -F "=" '$1 == "appVerName" {print $2}' gradle.properties`
if [[ "${{ needs.check.outputs.new_bili }}" = "1" && "${{ needs.check.outputs.new_my }}" != "1" ]]; then
commit_count=`git rev-list HEAD --count`
version="${version}.r${commit_count}"
fi
echo "VERSION=$version" >> $GITHUB_ENV
- name: Set up ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ runner.os }}-${{ github.sha }}
restore-keys: ${{ runner.os }}
- name: Generate signing config
run: |
key_base64="${{ secrets.SIGNING_KEY }}"
echo -n "$key_base64" | base64 -d > app/signing.jks
echo "releaseStoreFile=signing.jks" >> gradle.properties
echo "releaseStorePassword=android" >> gradle.properties
echo "releaseKeyAlias=androiddebugkey" >> gradle.properties
echo "releaseKeyPassword=android" >> gradle.properties
- name: Build with Gradle
run: ./gradlew --no-daemon --build-cache -PappVerName=$VERSION assembleRelease
- name: Upload built release apk
if: success()
uses: actions/upload-artifact@v3
with:
name: release
path: ${{ github.workspace }}/app/release/BiliRoamingX-v${{ env.VERSION }}.apk
patch:
name: Patch APK
runs-on: ubuntu-latest
needs: [ check, module ]
if: needs.check.outputs.new_bili == '1' || needs.check.outputs.new_my == '1'
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- name: Set up Android SDK
run: |
echo "ANDROID_HOME=/usr/local/lib/android/sdk" >> $GITHUB_ENV
echo "/usr/local/lib/android/sdk/build-tools/32.0.0" >> $GITHUB_PATH
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Prepare Python packages
run: |
pip install -U pip
pip install -U wheel
pip install pyrogram==2.0.59 tgcrypto==1.2.4
pip install -U requests
- name: Download release artifact
uses: actions/download-artifact@v3
with:
name: release
- name: Get xposed module path
run: |
module_apk=`echo BiliRoamingX-*.apk`
echo "MODULE_APK=$module_apk" >> $GITHUB_ENV
- name: Download bilibili apk
run: wget -nv -O Bilibili.apk ${{ needs.check.outputs.url }}
- name: Get app info
run: |
echo "VER_CODE=`aapt dump badging Bilibili.apk | awk -F "[ =']" '$6 == "versionCode" {print $8}'`" >> $GITHUB_ENV
echo "VER_NAME=`aapt dump badging Bilibili.apk | awk -F "[ =']" '$10 == "versionName" {print $12}'`" >> $GITHUB_ENV
echo "M_VER_CODE=`aapt dump badging $MODULE_APK | awk -F "[ =']" '$6 == "versionCode" {print $8}'`" >> $GITHUB_ENV
echo "M_VER_NAME=`aapt dump badging $MODULE_APK | awk -F "[ =']" '$10 == "versionName" {print $12}'`" >> $GITHUB_ENV
- name: Append version
run: |
sn="${{ needs.check.outputs.sn }}"
mkdir patched
mv Bilibili.apk patched/Bili-v$VER_NAME-b$sn-official.apk
echo "BILIBILI_NAME=Bili-v$VER_NAME-b$sn" >> $GITHUB_ENV
echo "BILIBILI_APK=patched/Bili-v$VER_NAME-b$sn-official.apk" >> $GITHUB_ENV
- name: Download jar patcher
run: wget -nv -O lspatch.jar https://github.com/LSPosed/LSPatch/releases/download/v0.5.1/lspatch.jar
- name: Apply patch
run: |
echo "Patch with builtin module."
java -jar lspatch.jar -m $MODULE_APK --sigbypasslv 2 $BILIBILI_APK
patched_apk=`echo $BILIBILI_NAME-*.apk`
renamed=patched/$BILIBILI_NAME-m$M_VER_CODE-with-module.apk
mv $patched_apk $renamed
echo "PATCHED_APK=$renamed" >> $GITHUB_ENV
- name: Calculate size and md5
id: extra-info
run: |
size=`du -b $PATCHED_APK | awk '{print $1}'`
md5=`md5sum $PATCHED_APK | awk '{print $1}'`
build_time=`date +%s`
echo "size=$size" >> $GITHUB_OUTPUT
echo "md5=$md5" >> $GITHUB_OUTPUT
echo "build_time=$build_time" >> $GITHUB_OUTPUT
- name: Release patched-builtin apk
uses: zjns/action-gh-release@v2
with:
token: ${{ secrets.HUB_TOKEN }}
tag_name: ${{ format('bili-v{0}-b{1}-m{2}', env.VER_NAME, needs.check.outputs.sn, env.M_VER_CODE) }}
name: ${{ format('{0} {1} {2} {3} {4} {5} {6} {7}', env.VER_NAME, env.VER_CODE, env.M_VER_NAME, env.M_VER_CODE, needs.check.outputs.sn, steps.extra-info.outputs.size, steps.extra-info.outputs.md5, steps.extra-info.outputs.build_time) }}
body: ${{ needs.check.outputs.changelog }}
prerelease: false
draft: false
files: ${{ env.PATCHED_APK }}
- name: Fetch upstream changelog
if: needs.check.outputs.new_my == '1'
run: |
py_get_up_changelog=$(cat <<EOM
import requests
url = 'https://api.github.com/repos/yujincheng08/BiliRoaming/releases/tags/v$M_VER_NAME'
headers = {
'Authorization': 'token ${{ secrets.HUB_TOKEN }}'
}
changelog = '可直接更新,原版更新日志请看 https://github.com/yujincheng08/BiliRoaming/releases/tag/v$M_VER_NAME'
try:
resp = requests.get(url, headers=headers).json()
changelog = resp['body'].split('更新日志\r\n', 1)[1].replace('\r', '')
changelog = f'可直接更新,原版更新日志:\n{changelog}'
print(changelog)
except Exception:
print(changelog)
EOM
)
up_changelog="`python -c "$py_get_up_changelog"`"
echo -n "$up_changelog" > up_changelog.txt
- name: Release module apk
if: needs.check.outputs.new_my == '1'
uses: zjns/action-gh-release@v2
with:
token: ${{ secrets.HUB_TOKEN }}
tag_name: ${{ format('v{0}', env.M_VER_NAME) }}
name: ${{ env.M_VER_NAME }}
body: ${{ format('可直接更新,原版更新日志请看 https://github.com/yujincheng08/BiliRoaming/releases/tag/v{0}', env.M_VER_NAME) }}
body_path: up_changelog.txt
prerelease: false
draft: false
files: ${{ env.MODULE_APK }}
- name: Release module apk (CI)
#if: needs.check.outputs.new_my != '1'
if: ${{ 'A' == 'B' }}
uses: zjns/action-gh-release@v2
with:
token: ${{ secrets.HUB_TOKEN }}
tag_name: ${{ format('v{0}', env.M_VER_NAME) }}
name: ${{ env.M_VER_NAME }}
body: 'CI版本'
prerelease: false
draft: false
files: ${{ env.MODULE_APK }}
- name: Send to Telegram (New Bilibili)
shell: python
#if: needs.check.outputs.new_bili == '1'
if: ${{ 'A' == 'B' }}
env:
API_ID: ${{ secrets.TELEGRAM_API_ID }}
API_HASH: ${{ secrets.TELEGRAM_API_HASH }}
CHANNEL_ID: ${{ secrets.TELEGRAM_TO }}
CHANNEL_ID_ME: ${{ secrets.TELEGRAM_TO_ME }}
SESSION: ${{ secrets.TELEGRAM_SESSION }}
RUN_URL: ${{ format('{0}/{1}/actions/runs/{2}', github.server_url, github.repository, github.run_id) }}
run: |
import asyncio
import inspect
import os
from pyrogram import Client
from pyrogram.types import InputMediaDocument
async def main():
session = os.environ["SESSION"]
bot = Client(
"client",
session_string=session,
)
async with bot:
ver_name = os.environ["VER_NAME"]
ver_code = os.environ["VER_CODE"]
m_ver_name = os.environ["M_VER_NAME"]
m_ver_code = os.environ["M_VER_CODE"]
channel_id = int(os.environ["CHANNEL_ID"])
channel_id_me = int(os.environ["CHANNEL_ID_ME"])
changelog = "${{ needs.check.outputs.changelog }}"
cycle = "${{ needs.check.outputs.cycle }}"
msg_p1 = "#Bilibili #BiliRoaming"
msg_p2 = f"发现新版本哔哩哔哩!\n\n更新日志:\n<pre>{changelog}</pre>"
msg_p3 = inspect.cleandoc("""
文件说明:
- 以<b>official</b>结尾的为官方原版
- 以<b>with-module</b>结尾的为内置模块LSPatch版本
- <b>内置版</b>可在<b>应用内</b>收到新的内置修改版更新
""")
msg_p4 = f"Bilibili: {ver_name} ({ver_code}) 64位 本版第{cycle}次迭代\nBiliRoamingX: {m_ver_name} ({m_ver_code})"
msg_p5 = f"Auto generated by [me]({os.environ['RUN_URL']})."
caption = "{}\n{}\n\n{}\n\n{}\n{}".format(msg_p1, msg_p2, msg_p3, msg_p4, msg_p5)
official = InputMediaDocument(media=os.environ["BILIBILI_APK"], caption="")
patched = InputMediaDocument(media=os.environ["PATCHED_APK"], caption="")
module = InputMediaDocument(media=os.environ["MODULE_APK"], caption=caption)
result = await bot.send_media_group(
chat_id=channel_id_me,
media=[official, patched, module],
)
file_ids = [m.document.file_id for m in result]
official.media = file_ids[0]
patched.media = file_ids[1]
module.media = file_ids[2]
await bot.send_media_group(
chat_id=channel_id,
media=[official, patched, module],
)
async def wait():
try:
await asyncio.wait_for(main(), timeout=600)
except asyncio.TimeoutError:
print("message send timeout!!!")
exit(1)
asyncio.run(wait())
- name: Send to Telegram (New module)
shell: python
#if: needs.check.outputs.new_my == '1'
if: ${{ 'A' == 'B' }}
env:
API_ID: ${{ secrets.TELEGRAM_API_ID }}
API_HASH: ${{ secrets.TELEGRAM_API_HASH }}
CHANNEL_ID: ${{ secrets.TELEGRAM_TO }}
CHANNEL_ID_ME: ${{ secrets.TELEGRAM_TO_ME }}
SESSION: ${{ secrets.TELEGRAM_SESSION }}
RUN_URL: ${{ format('{0}/{1}/actions/runs/{2}', github.server_url, github.repository, github.run_id) }}
run: |
import asyncio
import os
from pyrogram import Client
from pyrogram.types import InputMediaDocument
async def main():
session = os.environ["SESSION"]
bot = Client(
"client",
session_string=session,
)
async with bot:
ver_name = os.environ["VER_NAME"]
ver_code = os.environ["VER_CODE"]
m_ver_name = os.environ["M_VER_NAME"]
m_ver_code = os.environ["M_VER_CODE"]
channel_id = int(os.environ["CHANNEL_ID"])
channel_id_me = int(os.environ["CHANNEL_ID_ME"])
msg_p1 = "#Bilibili #BiliRoaming"
msg_p2 = "发现新版本漫游!"
msg_p3 = "可在<b>应用内</b>收到新的内置修改版更新"
msg_p4 = f"Bilibili: {ver_name} ({ver_code}) 64位\nBiliRoamingX: {m_ver_name} ({m_ver_code})"
msg_p5 = f"Auto generated by [me]({os.environ['RUN_URL']})."
caption = "{}\n{}\n\n{}\n\n{}\n{}".format(msg_p1, msg_p2, msg_p3, msg_p4, msg_p5)
module = InputMediaDocument(media=os.environ["MODULE_APK"], caption="")
patched = InputMediaDocument(media=os.environ["PATCHED_APK"], caption=caption)
result = await bot.send_media_group(
chat_id=channel_id_me,
media=[module, patched],
)
file_ids = [m.document.file_id for m in result]
module.media = file_ids[0]
patched.media = file_ids[1]
await bot.send_media_group(
chat_id=channel_id,
media=[module, patched],
)
async def wait():
try:
await asyncio.wait_for(main(), timeout=600)
except asyncio.TimeoutError:
print("message send timeout!!!")
exit(1)
asyncio.run(wait())