CI: auto update version list

This commit is contained in:
xtaodada 2022-07-24 18:36:57 +08:00
parent 2746fedf49
commit c11f43e98e
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
3 changed files with 57 additions and 17 deletions

View File

@ -4,6 +4,12 @@ on:
push:
branches:
- v2
paths-ignore:
- '**.md'
- '.github/**'
- 'list.json'
- 'telegram_update.py'
- 'update_list.py'
jobs:
build:
@ -23,13 +29,23 @@ jobs:
# 安装依赖
- name: Install dependencies
run: |
mkdir tmp && cd tmp
python -m pip install --upgrade pip
pip install httpx
# 发送通知
- name: Send notice
run: |
cd tmp
cp ../telegram_update.py ./
python telegram_update.py ${{ secrets.TG_BOT_TOKEN }}
# 更新 list
- name: Update list
run: |
python update_list.py
# Auto commit
- uses: stefanzweifel/git-auto-commit-action@v4
with:
# Optional. Commit message for the created commit.
# Defaults to "Apply automatic changes"
commit_message: "CI: Update version json"
file_pattern: 'list.json'

View File

@ -1,8 +1,10 @@
import json, time, sys
import time
import sys
import contextlib
from httpx import get, post
token = str(sys.argv[1])
main = json.loads(get("https://api.github.com/repos/TeamPGM/PagerMaid_Plugins_Pyro/commits/v2").content)
main = get("https://api.github.com/repos/TeamPGM/PagerMaid_Plugins_Pyro/commits/v2").json()
text = (
(
(
@ -19,17 +21,10 @@ text = (
+ '): '
) + main['commit']['message']
push_content = {'chat_id': '-1001441461877', 'disable_web_page_preview': 'True', 'parse_mode': 'markdown',
'text': text}
url = f'https://api.telegram.org/bot{token}/sendMessage'
try:
for cid in ['-1001441461877', '-1001319957857']:
push_content = {'chat_id': cid, 'disable_web_page_preview': 'True', 'parse_mode': 'markdown', 'text': text}
with contextlib.suppress(Exception):
main_req = post(url, data=push_content)
except:
pass
push_content['chat_id'] = '-1001319957857'
time.sleep(1)
try:
main_req = post(url, data=push_content)
except:
pass
print(main['sha'] + " ok")

29
update_list.py Normal file
View File

@ -0,0 +1,29 @@
import json
import os
from httpx import get
main = get("https://api.github.com/repos/TeamPGM/PagerMaid_Plugins_Pyro/commits/v2").json()
plugins = [i["filename"].split("/")[0] for i in main["files"] if "/main.py" in i["filename"]]
with open("list.json", "r", encoding="utf8") as f:
list_json = json.load(f)
for plugin in plugins:
exist = False
for plug_dict in list_json["list"]:
if plug_dict["name"] == plugin:
exist = True
old_version = float(plug_dict["version"])
list_json["list"][list_json["list"].index(plug_dict)]["version"] = str(old_version + 0.01)
break
if not exist:
list_json["list"].append(
{"name": plugin,
"version": "1.0",
"section": "chat",
"maintainer": main['commit']['author']['name'],
"size": f"{os.path.getsize(f'{plugin}{os.sep}main.py') / 1000} kb",
"supported": True,
"des-short": "这个人很懒,什么都没留下",
"des": "这个人很懒,什么都没有留下。"})
with open("list.json", "w", encoding="utf8") as f:
json.dump(list_json, f, ensure_ascii=False, indent=4)
print(main['sha'] + " ok")