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
78 lines (71 loc) · 2.61 KB
/
sync.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
name: Sync Fork
on:
schedule:
- cron: '1 0-14 * * *'
workflow_dispatch:
jobs:
sync:
name: Sync
runs-on: ubuntu-latest
steps:
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Prepare Python packages
run: |
pip install -U wheel
pip install -U pyrogram tgcrypto
- name: Get repo name
run: echo "REPO_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
- name: Sync fork
id: sync
uses: zjns/repo-sync@master
with:
token: ${{ secrets.HUB_TOKEN }}
up_repo: 'yujincheng08/BiliRoaming'
up_branch: master
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
- name: Report via Telegram
shell: python
if: always()
env:
API_ID: ${{ secrets.TELEGRAM_API_ID }}
API_HASH: ${{ secrets.TELEGRAM_API_HASH }}
BOT_TOKEN: ${{ secrets.TELEGRAM_BOT }}
CHANNEL_ID: ${{ secrets.TELEGRAM_TO_ME }}
SUCCESS: ${{ job.status == 'success' }}
run: |
import asyncio
import os
from pyrogram import Client
commit_count=${{ steps.sync.outputs.commit_count }}
diff_commits=${{ toJSON(fromJSON(steps.sync.outputs.commits).*.message) }}
if not commit_count:
exit(0)
async def main():
bot = Client(
"client",
in_memory=True,
api_id=os.environ["API_ID"],
api_hash=os.environ["API_HASH"],
bot_token=os.environ["BOT_TOKEN"],
)
async with bot:
channel_id = int(os.environ["CHANNEL_ID"])
repo = os.environ["REPO_NAME"]
repo_url = f"https://github.com/{os.environ['GITHUB_REPOSITORY']}"
success = True if (os.environ["SUCCESS"] == "true") else False
text = f"🎉 Fork sync success!\nRepo: [{repo}]({repo_url})" if (success) else f"😿 Fork sync failed!\nRepo: [{repo}]({repo_url})"
if success:
commits = "\n".join([f"∙ {commit}" for commit in diff_commits[:10]])
text += f"\n\nSynced commits:\n<pre>{commits}</pre>"
await bot.send_message(chat_id=channel_id, text=text, disable_web_page_preview=True)
async def wait():
try:
await asyncio.wait_for(main(), timeout=60)
except asyncio.TimeoutError:
print("message send timeout!!!")
exit(1)
asyncio.run(wait())