From 47eb826e82a990035696658ac64e8a6c8d4b9b98 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Fri, 6 May 2022 00:59:15 +0800 Subject: [PATCH 01/28] add parser for retweet for weibo, fix #44 --- src/plugins/nonebot_bison/platform/weibo.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/plugins/nonebot_bison/platform/weibo.py b/src/plugins/nonebot_bison/platform/weibo.py index bcd0995..38cd68d 100644 --- a/src/plugins/nonebot_bison/platform/weibo.py +++ b/src/plugins/nonebot_bison/platform/weibo.py @@ -123,7 +123,11 @@ class Weibo(NewMessage): "Mobile Safari/537.36", } info = raw_post["mblog"] - if info["isLongText"] or info["pic_num"] > 9: + retweeted = False + if info.get("retweeted_status"): + retweeted = True + pic_num = info["retweeted_status"]["pic_num"] if retweeted else info["pic_num"] + if info["isLongText"] or pic_num > 9: async with httpx.AsyncClient() as client: res = await client.get( "https://m.weibo.cn/detail/{}".format(info["mid"]), headers=header @@ -140,7 +144,12 @@ class Weibo(NewMessage): ) ) parsed_text = self._get_text(info["text"]) - pic_urls = [img["large"]["url"] for img in info.get("pics", [])] + raw_pics_list = ( + info["retweeted_status"].get("pics", []) + if retweeted + else info.get("pics", []) + ) + pic_urls = [img["large"]["url"] for img in raw_pics_list] detail_url = "https://weibo.com/{}/{}".format(info["user"]["id"], info["bid"]) # return parsed_text, detail_url, pic_urls return Post( From 84e497e65a8437aa216bbbbdee656e0df7c4c6ed Mon Sep 17 00:00:00 2001 From: Azide Date: Wed, 11 May 2022 17:36:16 +0800 Subject: [PATCH 02/28] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E5=91=BD=E4=BB=A4=E7=9A=84=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/nonebot_bison/config_manager.py | 7 +++++-- tests/test_config_manager_add.py | 4 ++-- tests/test_config_manager_query_del.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/nonebot_bison/config_manager.py b/src/plugins/nonebot_bison/config_manager.py index 931bf3e..21438ee 100644 --- a/src/plugins/nonebot_bison/config_manager.py +++ b/src/plugins/nonebot_bison/config_manager.py @@ -269,13 +269,16 @@ def do_del_sub(del_sub: Type[Matcher]): if platform.enable_tag: res += " {}".format(", ".join(sub["tags"])) res += "\n" - res += "请输入要删除的订阅的序号" + res += "请输入要删除的订阅的序号\n输入'取消'中止" await bot.send(event=event, message=Message(await parse_text(res))) @del_sub.receive() async def do_del(event: Event, state: T_State): + user_msg = str(event.get_message()).strip() + if user_msg == "取消": + await del_sub.finish("删除中止") try: - index = int(str(event.get_message()).strip()) + index = int(user_msg) config = Config() user_info = state["target_user_info"] assert isinstance(user_info, User) diff --git a/tests/test_config_manager_add.py b/tests/test_config_manager_add.py index a38a1a8..ae679c0 100644 --- a/tests/test_config_manager_add.py +++ b/tests/test_config_manager_add.py @@ -387,8 +387,8 @@ async def test_add_with_get_id(app: App): True, ) """ - line 362: - 鬼知道为什么要在这里这样写, + 关于Message([MessageSegment(*BotReply.add_reply_on_id_input_search())]): + 异客知道为什么要在这里这样写, 没有[]的话assert不了(should_call_send使用[MessageSegment(...)]的格式进行比较) 不在这里MessageSegment()的话也assert不了(指不能让add_reply_on_id_input_search直接返回一个MessageSegment对象) amen diff --git a/tests/test_config_manager_query_del.py b/tests/test_config_manager_query_del.py index 51dd80d..4cad12f 100644 --- a/tests/test_config_manager_query_del.py +++ b/tests/test_config_manager_query_del.py @@ -67,7 +67,7 @@ async def test_del_sub(app: App): ctx.should_call_send( event, Message( - "订阅的帐号为:\n1 weibo 明日方舟Arknights 6279793937\n [图文] 明日方舟\n请输入要删除的订阅的序号" + "订阅的帐号为:\n1 weibo 明日方舟Arknights 6279793937\n [图文] 明日方舟\n请输入要删除的订阅的序号\n输入'取消'中止" ), True, ) From 227cf0cfc1c5fe373a75604736f72271d2a0e967 Mon Sep 17 00:00:00 2001 From: Azide Date: Wed, 11 May 2022 18:27:47 +0800 Subject: [PATCH 03/28] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=BA=E7=A9=BA=E6=97=B6=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=AE=A2=E9=98=85=E5=91=BD=E4=BB=A4=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=B7=B3=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/nonebot_bison/config_manager.py | 55 +++++++++++---------- tests/test_config_manager_abort.py | 46 +++++++++++++++++ tests/test_config_manager_query_del.py | 27 ++++++++++ 3 files changed, 103 insertions(+), 25 deletions(-) diff --git a/src/plugins/nonebot_bison/config_manager.py b/src/plugins/nonebot_bison/config_manager.py index 21438ee..c284adb 100644 --- a/src/plugins/nonebot_bison/config_manager.py +++ b/src/plugins/nonebot_bison/config_manager.py @@ -244,33 +244,38 @@ def do_del_sub(del_sub: Type[Matcher]): config: Config = Config() user_info = state["target_user_info"] assert isinstance(user_info, User) - sub_list = config.list_subscribe( - # state.get("_user_id") or event.group_id, "group" - user_info.user, - user_info.user_type, - ) - res = "订阅的帐号为:\n" - state["sub_table"] = {} - for index, sub in enumerate(sub_list, 1): - state["sub_table"][index] = { - "target_type": sub["target_type"], - "target": sub["target"], - } - res += "{} {} {} {}\n".format( - index, sub["target_type"], sub["target_name"], sub["target"] + try: + sub_list = config.list_subscribe( + # state.get("_user_id") or event.group_id, "group" + user_info.user, + user_info.user_type, ) - platform = platform_manager[sub["target_type"]] - if platform.categories: - res += " [{}]".format( - ", ".join( - map(lambda x: platform.categories[Category(x)], sub["cats"]) - ) + assert sub_list + except AssertionError: + await del_sub.finish("暂无已订阅账号\n请使用“添加订阅”命令添加订阅") + else: + res = "订阅的帐号为:\n" + state["sub_table"] = {} + for index, sub in enumerate(sub_list, 1): + state["sub_table"][index] = { + "target_type": sub["target_type"], + "target": sub["target"], + } + res += "{} {} {} {}\n".format( + index, sub["target_type"], sub["target_name"], sub["target"] ) - if platform.enable_tag: - res += " {}".format(", ".join(sub["tags"])) - res += "\n" - res += "请输入要删除的订阅的序号\n输入'取消'中止" - await bot.send(event=event, message=Message(await parse_text(res))) + platform = platform_manager[sub["target_type"]] + if platform.categories: + res += " [{}]".format( + ", ".join( + map(lambda x: platform.categories[Category(x)], sub["cats"]) + ) + ) + if platform.enable_tag: + res += " {}".format(", ".join(sub["tags"])) + res += "\n" + res += "请输入要删除的订阅的序号\n输入'取消'中止" + await bot.send(event=event, message=Message(await parse_text(res))) @del_sub.receive() async def do_del(event: Event, state: T_State): diff --git a/tests/test_config_manager_abort.py b/tests/test_config_manager_abort.py index da307f4..65921a1 100644 --- a/tests/test_config_manager_abort.py +++ b/tests/test_config_manager_abort.py @@ -281,3 +281,49 @@ async def test_abort_add_on_tag(app: App): True, ) ctx.should_finished() + + +# 删除订阅阶段中止 +@pytest.mark.asyncio +async def test_abort_del_sub(app: App): + from nonebot.adapters.onebot.v11.bot import Bot + from nonebot.adapters.onebot.v11.message import Message + from nonebot_bison.config import Config + from nonebot_bison.config_manager import del_sub_matcher + from nonebot_bison.platform import platform_manager + + config = Config() + config.user_target.truncate() + config.add_subscribe( + 10000, + "group", + "6279793937", + "明日方舟Arknights", + "weibo", + [platform_manager["weibo"].reverse_category["图文"]], + ["明日方舟"], + ) + async with app.test_matcher(del_sub_matcher) as ctx: + bot = ctx.create_bot(base=Bot) + assert isinstance(bot, Bot) + event = fake_group_message_event( + message=Message("删除订阅"), to_me=True, sender=fake_admin_user + ) + ctx.receive_event(bot, event) + ctx.should_pass_rule() + ctx.should_pass_permission() + ctx.should_call_send( + event, + Message( + "订阅的帐号为:\n1 weibo 明日方舟Arknights 6279793937\n [图文] 明日方舟\n请输入要删除的订阅的序号\n输入'取消'中止" + ), + True, + ) + event_abort = fake_group_message_event( + message=Message("取消"), sender=fake_admin_user + ) + ctx.receive_event(bot, event_abort) + ctx.should_call_send(event_abort, "删除中止", True) + ctx.should_finished() + subs = config.list_subscribe(10000, "group") + assert subs diff --git a/tests/test_config_manager_query_del.py b/tests/test_config_manager_query_del.py index 4cad12f..f995a9c 100644 --- a/tests/test_config_manager_query_del.py +++ b/tests/test_config_manager_query_del.py @@ -85,3 +85,30 @@ async def test_del_sub(app: App): ctx.should_finished() subs = config.list_subscribe(10000, "group") assert len(subs) == 0 + + +@pytest.mark.asyncio +async def test_del_empty_sub(app: App): + from nonebot.adapters.onebot.v11.bot import Bot + from nonebot.adapters.onebot.v11.message import Message + from nonebot_bison.config import Config + from nonebot_bison.config_manager import del_sub_matcher + from nonebot_bison.platform import platform_manager + + config = Config() + config.user_target.truncate() + async with app.test_matcher(del_sub_matcher) as ctx: + bot = ctx.create_bot(base=Bot) + assert isinstance(bot, Bot) + event = fake_group_message_event( + message=Message("删除订阅"), to_me=True, sender=fake_admin_user + ) + ctx.receive_event(bot, event) + ctx.should_pass_rule() + ctx.should_pass_permission() + ctx.should_finished() + ctx.should_call_send( + event, + "暂无已订阅账号\n请使用“添加订阅”命令添加订阅", + True, + ) From ee2a807ebf8360ebedd96982bc3d5e47133bf2bf Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Sun, 15 May 2022 01:00:53 +0800 Subject: [PATCH 04/28] add terra-historicus --- .../nonebot_bison/platform/arknights.py | 44 +++++++++++++++++++ tests/platforms/static/terra-hist-0.json | 1 + tests/platforms/static/terra-hist-1.json | 1 + tests/platforms/test_arknights.py | 16 ++++++- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/platforms/static/terra-hist-0.json create mode 100644 tests/platforms/static/terra-hist-1.json diff --git a/src/plugins/nonebot_bison/platform/arknights.py b/src/plugins/nonebot_bison/platform/arknights.py index 0b3c21f..4a5c523 100644 --- a/src/plugins/nonebot_bison/platform/arknights.py +++ b/src/plugins/nonebot_bison/platform/arknights.py @@ -189,3 +189,47 @@ class MonsterSiren(NewMessage): compress=True, override_use_pic=False, ) + + +class TerraHistoricusComic(NewMessage): + + categories = {4: "泰拉记事社漫画"} + platform_name = "arknights" + name = "明日方舟游戏信息" + enable_tag = False + enabled = True + is_common = False + schedule_type = "interval" + schedule_kw = {"seconds": 30} + has_target = False + + async def get_target_name(self, _: Target) -> str: + return "明日方舟游戏信息" + + async def get_sub_list(self, _) -> list[RawPost]: + async with httpx.AsyncClient() as client: + raw_data = await client.get( + "https://terra-historicus.hypergryph.com/api/recentUpdate" + ) + return raw_data.json()["data"] + + def get_id(self, post: RawPost) -> Any: + return f'{post["comicCid"]}/{post["episodeCid"]}' + + def get_date(self, _) -> None: + return None + + def get_category(self, _) -> Category: + return Category(4) + + async def parse(self, raw_post: RawPost) -> Post: + url = f'https://terra-historicus.hypergryph.com/comic/{raw_post["comicCid"]}/episode/{raw_post["episodeCid"]}' + return Post( + "terra-historicus", + text=f'{raw_post["title"]} - {raw_post["episodeShortTitle"]}', + pics=[raw_post["coverUrl"]], + url=url, + target_name="泰拉记事社漫画", + compress=True, + override_use_pic=False, + ) diff --git a/tests/platforms/static/terra-hist-0.json b/tests/platforms/static/terra-hist-0.json new file mode 100644 index 0000000..4d09cf3 --- /dev/null +++ b/tests/platforms/static/terra-hist-0.json @@ -0,0 +1 @@ +{"code":0,"msg":"","data":[{"coverUrl":"https://web.hycdn.cn/comic/pic/20220507/c4da4fb95587101f1867a30fe85cb557.png","comicCid":"6253","title":"123罗德岛!?","subtitle":"你可能不知道的罗德岛小剧场!","episodeCid":"5771","episodeType":1,"episodeShortTitle":"「流明」篇","updateTime":1652025600},{"coverUrl":"https://web.hycdn.cn/comic/pic/20220505/5c296539f5dc808603f20dda86879c9c.png","comicCid":"0696","title":"A1行动预备组","subtitle":"","episodeCid":"2897","episodeType":1,"episodeShortTitle":"01","updateTime":1651852800},{"coverUrl":"https://web.hycdn.cn/comic/pic/20220428/f4dc1e91420d18eccb80d60bba322d42.png","comicCid":"6253","title":"123罗德岛!?","subtitle":"你可能不知道的罗德岛小剧场!","episodeCid":"6346","episodeType":1,"episodeShortTitle":"「艾丽妮」篇","updateTime":1651507200}]} diff --git a/tests/platforms/static/terra-hist-1.json b/tests/platforms/static/terra-hist-1.json new file mode 100644 index 0000000..a70358b --- /dev/null +++ b/tests/platforms/static/terra-hist-1.json @@ -0,0 +1 @@ +{"code":0,"msg":"","data":[{"coverUrl":"https://web.hycdn.cn/comic/pic/20220507/ab8a2ff408ec7d587775aed70b178ec0.png","comicCid":"6253","title":"123罗德岛!?","subtitle":"你可能不知道的罗德岛小剧场!","episodeCid":"4938","episodeType":1,"episodeShortTitle":"「掠风」篇","updateTime":1652112000},{"coverUrl":"https://web.hycdn.cn/comic/pic/20220507/c4da4fb95587101f1867a30fe85cb557.png","comicCid":"6253","title":"123罗德岛!?","subtitle":"你可能不知道的罗德岛小剧场!","episodeCid":"5771","episodeType":1,"episodeShortTitle":"「流明」篇","updateTime":1652025600},{"coverUrl":"https://web.hycdn.cn/comic/pic/20220505/5c296539f5dc808603f20dda86879c9c.png","comicCid":"0696","title":"A1行动预备组","subtitle":"","episodeCid":"2897","episodeType":1,"episodeShortTitle":"01","updateTime":1651852800},{"coverUrl":"https://web.hycdn.cn/comic/pic/20220428/f4dc1e91420d18eccb80d60bba322d42.png","comicCid":"6253","title":"123罗德岛!?","subtitle":"你可能不知道的罗德岛小剧场!","episodeCid":"6346","episodeType":1,"episodeShortTitle":"「艾丽妮」篇","updateTime":1651507200}]} \ No newline at end of file diff --git a/tests/platforms/test_arknights.py b/tests/platforms/test_arknights.py index 7b3f386..ba81db0 100644 --- a/tests/platforms/test_arknights.py +++ b/tests/platforms/test_arknights.py @@ -61,6 +61,7 @@ async def test_fetch_new( "https://ak-conf.hypergryph.com/config/prod/announce_meta/IOS/preannouncement.meta.json" ) monster_siren_router = respx.get("https://monster-siren.hypergryph.com/api/news") + terra_list = respx.get("https://terra-historicus.hypergryph.com/api/recentUpdate") ak_list_router.mock(return_value=Response(200, json=arknights_list__1)) detail_router.mock( return_value=Response(200, text=get_file("arknights-detail-807")) @@ -72,6 +73,7 @@ async def test_fetch_new( return_value=Response(200, json=get_json("arknights-pre-0.json")) ) monster_siren_router.mock(return_value=Response(200, json=monster_siren_list_0)) + terra_list.mock(return_value=Response(200, json=get_json("terra-hist-0.json"))) target = "" res = await arknights.fetch_new_post(target, [dummy_user_subinfo]) assert ak_list_router.called @@ -90,7 +92,17 @@ async def test_fetch_new( assert len(post.pics) == 1 # assert(post.pics == ['https://ak-fs.hypergryph.com/announce/images/20210623/e6f49aeb9547a2278678368a43b95b07.jpg']) print(res3[0][1]) - r = await post.generate_messages() + await post.generate_messages() + terra_list.mock(return_value=Response(200, json=get_json("terra-hist-1.json"))) + res = await arknights.fetch_new_post(target, [dummy_user_subinfo]) + assert len(res) == 1 + post = res[0][1][0] + assert post.target_type == "terra-historicus" + assert post.text == "123罗德岛!? - 「掠风」篇" + assert post.url == "https://terra-historicus.hypergryph.com/comic/6253/episode/4938" + assert post.pics == [ + "https://web.hycdn.cn/comic/pic/20220507/ab8a2ff408ec7d587775aed70b178ec0.png" + ] @pytest.mark.render @@ -116,6 +128,7 @@ async def test_send_with_render( "https://ak-conf.hypergryph.com/config/prod/announce_meta/IOS/preannouncement.meta.json" ) monster_siren_router = respx.get("https://monster-siren.hypergryph.com/api/news") + terra_list = respx.get("https://terra-historicus.hypergryph.com/api/recentUpdate") ak_list_router.mock(return_value=Response(200, json=arknights_list_0)) detail_router.mock( return_value=Response(200, text=get_file("arknights-detail-805")) @@ -127,6 +140,7 @@ async def test_send_with_render( return_value=Response(200, json=get_json("arknights-pre-0.json")) ) monster_siren_router.mock(return_value=Response(200, json=monster_siren_list_0)) + terra_list.mock(return_value=Response(200, json=get_json("terra-hist-0.json"))) target = "" res = await arknights.fetch_new_post(target, [dummy_user_subinfo]) assert ak_list_router.called From cce4b46ed917b5b66abf1b5a4067f5371aee1a72 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Sun, 15 May 2022 01:04:45 +0800 Subject: [PATCH 05/28] update change log --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e835f2..39d689b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,3 +76,9 @@ - 修复了微博获取全文时接口失效的问题 - 修复了 bilibili 空列表时的报错 + +## [0.5.3] + +- 可以发送转发微博中原微博的图片 +- 优化了删除订阅时的相关问题 +- 添加泰拉记事社的订阅 From d22f97f02f9395e29d13e7bc47296f7f0d11aab3 Mon Sep 17 00:00:00 2001 From: meetwq Date: Wed, 18 May 2022 16:33:25 +0800 Subject: [PATCH 06/28] block=True --- src/plugins/nonebot_bison/config_manager.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins/nonebot_bison/config_manager.py b/src/plugins/nonebot_bison/config_manager.py index 931bf3e..15e8262 100644 --- a/src/plugins/nonebot_bison/config_manager.py +++ b/src/plugins/nonebot_bison/config_manager.py @@ -297,12 +297,13 @@ add_sub_matcher = on_command( rule=configurable_to_me, permission=GROUP_ADMIN | GROUP_OWNER | SUPERUSER, priority=5, + block=True, ) add_sub_matcher.handle()(set_target_user_info) do_add_sub(add_sub_matcher) -query_sub_matcher = on_command("查询订阅", rule=configurable_to_me, priority=5) +query_sub_matcher = on_command("查询订阅", rule=configurable_to_me, priority=5, block=True) query_sub_matcher.handle()(set_target_user_info) do_query_sub(query_sub_matcher) @@ -312,11 +313,14 @@ del_sub_matcher = on_command( rule=configurable_to_me, permission=GROUP_ADMIN | GROUP_OWNER | SUPERUSER, priority=5, + block=True, ) del_sub_matcher.handle()(set_target_user_info) do_del_sub(del_sub_matcher) -group_manage_matcher = on_command("群管理", rule=to_me(), permission=SUPERUSER, priority=4) +group_manage_matcher = on_command( + "群管理", rule=to_me(), permission=SUPERUSER, priority=4, block=True +) @group_manage_matcher.handle() From 2e27f4eddb01b0de2190771e75d1172f87df8aef Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Thu, 19 May 2022 18:53:19 +0800 Subject: [PATCH 07/28] update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b9ed3db..40dd42f 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ - 图文 - 视频 - 纯文字 + - 转发 - Bilibili - 视频 - 图文 @@ -44,6 +45,7 @@ - 塞壬唱片新闻 - 游戏内公告 - 版本更新等通知 + - 泰拉记事社漫画 - 网易云音乐 - 歌手发布新专辑 - 电台更新 From cbdb73b2e3c837a4d4722ff78f180e7042a5be61 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Thu, 19 May 2022 19:06:03 +0800 Subject: [PATCH 08/28] fix #66 --- src/plugins/nonebot_bison/admin_page/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/nonebot_bison/admin_page/__init__.py b/src/plugins/nonebot_bison/admin_page/__init__.py index 0436296..4d0f9f8 100644 --- a/src/plugins/nonebot_bison/admin_page/__init__.py +++ b/src/plugins/nonebot_bison/admin_page/__init__.py @@ -129,7 +129,7 @@ def register_router_fastapi(driver: Driver, socketio): def init(): driver = get_driver() - if driver.type == "fastapi": + if "fastapi" in driver.type: assert isinstance(driver, Driver) register_router_fastapi(driver, socket_app) else: From 12b8111934d06b494f61c0e40c062da0b6e97a17 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Thu, 19 May 2022 21:22:39 +0800 Subject: [PATCH 09/28] use another way to check fastapi --- src/plugins/nonebot_bison/admin_page/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/plugins/nonebot_bison/admin_page/__init__.py b/src/plugins/nonebot_bison/admin_page/__init__.py index 4d0f9f8..4ea89d8 100644 --- a/src/plugins/nonebot_bison/admin_page/__init__.py +++ b/src/plugins/nonebot_bison/admin_page/__init__.py @@ -129,8 +129,7 @@ def register_router_fastapi(driver: Driver, socketio): def init(): driver = get_driver() - if "fastapi" in driver.type: - assert isinstance(driver, Driver) + if isinstance(driver, Driver): register_router_fastapi(driver, socket_app) else: logger.warning(f"Driver {driver.type} not supported") From 12136023cbd7e47ba4bb0e269fa63bf3dc946478 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Fri, 20 May 2022 13:08:51 +0800 Subject: [PATCH 10/28] add respx for weibo target --- tests/platforms/test_weibo.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/platforms/test_weibo.py b/tests/platforms/test_weibo.py index c241408..178debc 100644 --- a/tests/platforms/test_weibo.py +++ b/tests/platforms/test_weibo.py @@ -23,7 +23,14 @@ def weibo_ak_list_1(): @pytest.mark.asyncio +@respx.mock async def test_get_name(weibo): + profile_router = respx.get( + "https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937" + ) + profile_router.mock( + return_value=Response(200, json=get_json("weibo_ak_profile.json")) + ) name = await weibo.get_target_name("6279793937") assert name == "明日方舟Arknights" From 92c8de5de13d1589b08dd1bd6ff50b030ac10b9a Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Sat, 21 May 2022 17:09:15 +0800 Subject: [PATCH 11/28] update changelog --- CHANGELOG.md | 107 ++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d689b..0dc99a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,47 +1,35 @@ # Change Log -## [0.2.11] - 2021-06-17 +## 最近更新 -- 增加了简单的单元测试 -- 增加了管理员直接管理订阅的能力 +- 可以发送转发微博中原微博的图片 +- 优化了删除订阅时的相关问题 +- 添加泰拉记事社的订阅 -## [0.3.0] - 2021-07-06 +## [0.5.2] -- 微博 tag 支持 -- 修复 bug -- 增加微博超话和纯文字支持 -- 更改浏览器配置 -- 将“来源”移动到文末 -- 使用组合来构建新的 platform,新增状态改变类型订阅 +- 修复了微博获取全文时接口失效的问题 +- 修复了 bilibili 空列表时的报错 -## [0.3.1] - 2021-07-10 +## [0.5.1] -- 修复不发送来源 -- 发送 RSS 订阅的 title -- 修复浏览器渲染问题 +- 使用了新的在私聊中进行群管理的方式:从`管理-*`替换为`群管理`命令 +- 默认关闭自动重发功能 +- 添加了 [推送消息合并转发功能](https://nonebot-bison.vercel.app/usage/#%E9%85%8D%E7%BD%AE) +- 添加了`添加订阅`命令事件的中途取消功能 +- 优化了`添加订阅`命令的聊天处理逻辑 -## [0.3.2] - 2021-09-28 +## [0.5.0] -- 增加 NoTargetGroup -- 增加 1x3 拼图的支持 -- 增加网易云 +- 添加了 FF14 +- 去掉了自己维护的 playwright,转向[nonebot-plugin-htmlrender](https://github.com/kexue-z/nonebot-plugin-htmlrender) +- 支持了 nonebot 2.0.0beta -## [0.3.3] - 2021-09-28 +## [0.4.4] -- 修复拼图问题 - -## [0.4.0] - 2021-11-18 - -- 项目更名为 nonebot-bison - -## [0.4.1] - 2021-11-31 - -- 加入了管理后台 - -## [0.4.2] - -并没有做什么只是为了修复前端文件没有正确打包的问题开了个新的版本号 -推上 pypi +- 又双叒叕重构了一下 +- 修复了 Docker 中 Playwright 下载的浏览器版本不正确问题 +- 加入了猴子补丁,使 Windows 里能运行 Playwright ## [0.4.3] @@ -52,33 +40,48 @@ - 前端可以刷新了(之前居然不可以) - 在镜像里塞进了浏览器(导致镜像体积起飞) -## [0.4.4] +## [0.4.2] -- 又双叒叕重构了一下 -- 修复了 Docker 中 Playwright 下载的浏览器版本不正确问题 -- 加入了猴子补丁,使 Windows 里能运行 Playwright +并没有做什么只是为了修复前端文件没有正确打包的问题开了个新的版本号 +推上 pypi -## [0.5.0] +## [0.4.1] - 2021-11-31 -- 添加了 FF14 -- 去掉了自己维护的 playwright,转向[nonebot-plugin-htmlrender](https://github.com/kexue-z/nonebot-plugin-htmlrender) -- 支持了 nonebot 2.0.0beta +- 加入了管理后台 -## [0.5.1] +## [0.4.0] - 2021-11-18 -- 使用了新的在私聊中进行群管理的方式:从`管理-*`替换为`群管理`命令 -- 默认关闭自动重发功能 -- 添加了 [推送消息合并转发功能](https://nonebot-bison.vercel.app/usage/#%E9%85%8D%E7%BD%AE) -- 添加了`添加订阅`命令事件的中途取消功能 -- 优化了`添加订阅`命令的聊天处理逻辑 +- 项目更名为 nonebot-bison -## [0.5.2] +## [0.3.3] - 2021-09-28 - 修复了微博获取全文时接口失效的问题 - 修复了 bilibili 空列表时的报错 +- 修复拼图问题 -## [0.5.3] +## [0.3.2] - 2021-09-28 + +- 增加 NoTargetGroup +- 增加 1x3 拼图的支持 +- 增加网易云 + +## [0.3.1] - 2021-07-10 + +- 修复不发送来源 +- 发送 RSS 订阅的 title +- 修复浏览器渲染问题 + +## [0.3.0] - 2021-07-06 + +- 微博 tag 支持 +- 修复 bug +- 增加微博超话和纯文字支持 +- 更改浏览器配置 +- 将“来源”移动到文末 +- 使用组合来构建新的 platform,新增状态改变类型订阅 + +## [0.2.11] - 2021-06-17 + +- 增加了简单的单元测试 +- 增加了管理员直接管理订阅的能力 -- 可以发送转发微博中原微博的图片 -- 优化了删除订阅时的相关问题 -- 添加泰拉记事社的订阅 From 8b56a1292f06c2c4b210a1995d522336539ee14b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 21 May 2022 14:28:39 +0000 Subject: [PATCH 12/28] auto fix by pre-commit hooks --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dc99a7..7545a8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,4 +84,3 @@ - 增加了简单的单元测试 - 增加了管理员直接管理订阅的能力 - From 2e1aa5f478d9a4051f80939054688afcc107e6fe Mon Sep 17 00:00:00 2001 From: hemengyang Date: Wed, 18 May 2022 10:08:35 +0000 Subject: [PATCH 13/28] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=B8=8E=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/codecov.yml | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 0000000..ecab769 --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,40 @@ +name: Code Coverage + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + name: Test Coverage + runs-on: ${{ matrix.os }} + concurrency: + group: test-coverage-${{ github.ref }}-${{ matrix.os }}-${{ matrix.python-version }} + cancel-in-progress: true + strategy: + matrix: + python-version: ["3.9", "3.10"] + os: [ubuntu-latest, windows-latest, macos-latest] + fail-fast: false + env: + OS: ${{ matrix.os }} + PYTHON_VERSION: ${{ matrix.python-version }} + + steps: + - uses: actions/checkout@v3 + + - name: Setup Python environment + uses: he0119/setup-python@v0.1.0 + with: + python-version: ${{ matrix.python-version }} + + - name: Run Pytest + run: poetry run pytest --cov-report xml --cov=./src/plugins/nonebot_bison -k 'not compare and not render' + - name: Upload coverage report + uses: codecov/codecov-action@v3 + with: + env_vars: OS,PYTHON_VERSION + files: ./tests/coverage.xml + flags: unittests From 50de18f242f7eac0d385c3a56c41c997ed031754 Mon Sep 17 00:00:00 2001 From: hemengyang Date: Wed, 18 May 2022 10:10:48 +0000 Subject: [PATCH 14/28] =?UTF-8?q?fix:=20=E5=8A=A0=E4=B8=8A=E5=BF=98?= =?UTF-8?q?=E8=AE=B0=E7=9A=84=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/codecov.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index ecab769..3969223 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -29,9 +29,13 @@ jobs: uses: he0119/setup-python@v0.1.0 with: python-version: ${{ matrix.python-version }} + + - name: Install prerequisites + run: poetry install - name: Run Pytest run: poetry run pytest --cov-report xml --cov=./src/plugins/nonebot_bison -k 'not compare and not render' + - name: Upload coverage report uses: codecov/codecov-action@v3 with: From cc7d4e958cf7e41ad44e9901d0069c6bcb007164 Mon Sep 17 00:00:00 2001 From: hemengyang Date: Wed, 18 May 2022 10:22:37 +0000 Subject: [PATCH 15/28] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=20codecov=20=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/codecov.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 3969223..9c10516 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -40,5 +40,3 @@ jobs: uses: codecov/codecov-action@v3 with: env_vars: OS,PYTHON_VERSION - files: ./tests/coverage.xml - flags: unittests From aa4c593177ac229bd296faee8fdc27ff5c0131a6 Mon Sep 17 00:00:00 2001 From: hemengyang Date: Wed, 18 May 2022 13:08:25 +0000 Subject: [PATCH 16/28] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=E7=94=9F?= =?UTF-8?q?=E6=88=90=20Frontend=20=E7=9A=84=20Action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions/setup-node/action.yml | 18 ++++++++++++++++++ .github/workflows/codecov.yml | 27 ++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 .github/actions/setup-node/action.yml diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml new file mode 100644 index 0000000..0286424 --- /dev/null +++ b/.github/actions/setup-node/action.yml @@ -0,0 +1,18 @@ +name: Setup Node +description: Setup Node + +runs: + using: "composite" + steps: + - uses: actions/setup-node@v2 + with: + node-version: "16" + + - id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + shell: bash + + - uses: actions/cache@v2 + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 9c10516..f6f3e06 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -29,7 +29,7 @@ jobs: uses: he0119/setup-python@v0.1.0 with: python-version: ${{ matrix.python-version }} - + - name: Install prerequisites run: poetry install @@ -40,3 +40,28 @@ jobs: uses: codecov/codecov-action@v3 with: env_vars: OS,PYTHON_VERSION + + build-frontend: + name: Build Frontend + runs-on: ubuntu-latest + concurrency: + group: build-frontend-${{ github.ref }} + cancel-in-progress: true + + steps: + - uses: actions/checkout@v3 + + - name: Setup Node Environment + uses: ./.github/actions/setup-node + + - name: Build Frontend + run: | + cd ./admin-frontend + yarn install + yarn build + + - name: Upload dist + uses: actions/upload-artifact@v3 + with: + name: frontend + path: ${{ github.workspace }}/admin-frontend/build/ From 57545ce5907e320a88e55995c7d9751bbb99adce Mon Sep 17 00:00:00 2001 From: hemengyang Date: Wed, 18 May 2022 13:22:18 +0000 Subject: [PATCH 17/28] =?UTF-8?q?fix:=20=E9=9C=80=E8=A6=81=E5=85=88?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=89=8D=E7=AB=AF=E5=86=8D=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions/build-frontend/action.yml | 15 +++++++ .github/workflows/codecov.yml | 51 ++++++++++++----------- 2 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 .github/actions/build-frontend/action.yml diff --git a/.github/actions/build-frontend/action.yml b/.github/actions/build-frontend/action.yml new file mode 100644 index 0000000..aa39679 --- /dev/null +++ b/.github/actions/build-frontend/action.yml @@ -0,0 +1,15 @@ +name: Build Frontend +description: Build Frontend + +runs: + using: "composite" + steps: + - name: Setup Node Environment + uses: ./.github/actions/setup-node + + - name: Build Frontend + shell: bash + working-directory: ./admin-frontend + run: | + yarn install + yarn build diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index f6f3e06..8760da4 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -7,9 +7,29 @@ on: pull_request: jobs: + build-frontend: + name: Build Frontend + runs-on: ubuntu-latest + concurrency: + group: build-frontend-${{ github.ref }} + cancel-in-progress: true + + steps: + - uses: actions/checkout@v3 + + - name: Build Frontend + uses: ./.github/actions/build-frontend + + - name: Upload dist + uses: actions/upload-artifact@v3 + with: + name: frontend + path: ./admin-frontend/build/ + test: name: Test Coverage runs-on: ${{ matrix.os }} + needs: build-frontend concurrency: group: test-coverage-${{ github.ref }}-${{ matrix.os }}-${{ matrix.python-version }} cancel-in-progress: true @@ -25,6 +45,12 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Download frontend files + uses: actions/download-artifact@v2 + with: + name: frontend + path: ./src/plugins/nonebot_bison/admin_page/dist + - name: Setup Python environment uses: he0119/setup-python@v0.1.0 with: @@ -40,28 +66,3 @@ jobs: uses: codecov/codecov-action@v3 with: env_vars: OS,PYTHON_VERSION - - build-frontend: - name: Build Frontend - runs-on: ubuntu-latest - concurrency: - group: build-frontend-${{ github.ref }} - cancel-in-progress: true - - steps: - - uses: actions/checkout@v3 - - - name: Setup Node Environment - uses: ./.github/actions/setup-node - - - name: Build Frontend - run: | - cd ./admin-frontend - yarn install - yarn build - - - name: Upload dist - uses: actions/upload-artifact@v3 - with: - name: frontend - path: ${{ github.workspace }}/admin-frontend/build/ From aa6453777a08572499bc5c1cf479bf97bb6dd949 Mon Sep 17 00:00:00 2001 From: hemengyang Date: Wed, 18 May 2022 14:10:06 +0000 Subject: [PATCH 18/28] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20Docker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/codecov.yml | 47 ++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 8760da4..669fadb 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -25,7 +25,6 @@ jobs: with: name: frontend path: ./admin-frontend/build/ - test: name: Test Coverage runs-on: ${{ matrix.os }} @@ -66,3 +65,49 @@ jobs: uses: codecov/codecov-action@v3 with: env_vars: OS,PYTHON_VERSION + docker: + name: Docker + runs-on: ubuntu-latest + needs: [build-frontend, test] + + steps: + - uses: actions/checkout@v3 + + - name: Download frontend files + uses: actions/download-artifact@v2 + with: + name: frontend + path: ./src/plugins/nonebot_bison/admin_page/dist + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./docker/Dockerfile_with_frontend + push: ${{ github.event_name != 'pull_request' }} + tags: felinae98/nonebot-bison:main + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build Sentry and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./docker/Dockerfile_with_frontend_sentry + push: ${{ github.event_name != 'pull_request' }} + tags: felinae98/nonebot-bison:main-sentry + cache-from: type=gha + cache-to: type=gha,mode=max From abab332d01dc7993952574d28aaf9ee8d28e052b Mon Sep 17 00:00:00 2001 From: hemengyang Date: Wed, 18 May 2022 14:34:03 +0000 Subject: [PATCH 19/28] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E8=87=B3=20PyPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions/setup-python/action.yml | 40 +++++++++++++++++++++ .github/workflows/{codecov.yml => main.yml} | 4 +-- .github/workflows/release.yml | 38 ++++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 .github/actions/setup-python/action.yml rename .github/workflows/{codecov.yml => main.yml} (98%) create mode 100644 .github/workflows/release.yml diff --git a/.github/actions/setup-python/action.yml b/.github/actions/setup-python/action.yml new file mode 100644 index 0000000..9c14210 --- /dev/null +++ b/.github/actions/setup-python/action.yml @@ -0,0 +1,40 @@ +name: Setup Python +description: Setup Python + +inputs: + python-version: + description: Python version + required: false + default: "3.9" + +runs: + using: "composite" + steps: + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ inputs.python-version }} + + - name: Install poetry + uses: Gr1N/setup-poetry@v7 + + - name: Cache Windows dependencies + uses: actions/cache@v2 + if: ${{ runner.os == 'Windows' }} + with: + path: ~/AppData/Local/pypoetry/Cache/virtualenvs + key: ${{ runner.os }}-poetry-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + + - name: Cache Linux dependencies + uses: actions/cache@v2 + if: ${{ runner.os == 'Linux' }} + with: + path: ~/.cache/pypoetry/virtualenvs + key: ${{ runner.os }}-poetry-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + + - name: Cache macOS dependencies + uses: actions/cache@v2 + if: ${{ runner.os == 'macOS' }} + with: + path: ~/Library/Caches/pypoetry/virtualenvs + key: ${{ runner.os }}-poetry-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }} \ No newline at end of file diff --git a/.github/workflows/codecov.yml b/.github/workflows/main.yml similarity index 98% rename from .github/workflows/codecov.yml rename to .github/workflows/main.yml index 669fadb..f37f954 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Code Coverage +name: CI on: push: @@ -51,7 +51,7 @@ jobs: path: ./src/plugins/nonebot_bison/admin_page/dist - name: Setup Python environment - uses: he0119/setup-python@v0.1.0 + uses: ./.github/actions/setup-python with: python-version: ${{ matrix.python-version }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d5990e1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,38 @@ +name: Release + +on: + release: + types: [published] + +jobs: + build-frontend: + name: Build Frontend + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Build Frontend + uses: ./.github/actions/build-frontend + + - name: Upload dist + uses: actions/upload-artifact@v3 + with: + name: frontend + path: ./admin-frontend/build/ + publish-pypi: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Download frontend files + uses: actions/download-artifact@v2 + with: + name: frontend + path: ./src/plugins/nonebot_bison/admin_page/dist + + - name: Setup Python environment + uses: ./.github/actions/setup-python + + - name: Publish PyPI + run: poetry publish --build -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} || echo "Already pushed to pypi" From 056e88e7efe6cac1655b41c30ad46b3583529674 Mon Sep 17 00:00:00 2001 From: hemengyang Date: Thu, 19 May 2022 12:18:59 +0000 Subject: [PATCH 20/28] =?UTF-8?q?ci:=20=E5=8A=A0=E4=B8=8A=20Docker=20?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d5990e1..756d95a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,6 +21,7 @@ jobs: path: ./admin-frontend/build/ publish-pypi: runs-on: ubuntu-latest + needs: build-frontend steps: - uses: actions/checkout@v3 @@ -36,3 +37,50 @@ jobs: - name: Publish PyPI run: poetry publish --build -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} || echo "Already pushed to pypi" + publish-docker: + runs-on: ubuntu-latest + needs: build-frontend + + steps: + - uses: actions/checkout@v3 + + - name: Download frontend files + uses: actions/download-artifact@v2 + with: + name: frontend + path: ./src/plugins/nonebot_bison/admin_page/dist + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./docker/Dockerfile_with_frontend + push: true + tags: | + felinae98/nonebot-bison:latest + felinae98/nonebot-bison:${{ github.event.release.tag_name }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build Sentry and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./docker/Dockerfile_with_frontend_sentry + push: true + tags: felinae98/nonebot-bison:${{ github.event.release.tag_name }}-sentry + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file From f9b142f369364f7b56e46e33ec679e5d17fbede7 Mon Sep 17 00:00:00 2001 From: hemengyang Date: Thu, 19 May 2022 12:33:10 +0000 Subject: [PATCH 21/28] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E6=96=87=E6=A1=A3=E7=BD=91=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 26 +++++++++++++++++- .github/workflows/website-preview.yml | 39 +++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/website-preview.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 756d95a..b715966 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -83,4 +83,28 @@ jobs: push: true tags: felinae98/nonebot-bison:${{ github.event.release.tag_name }}-sentry cache-from: type=gha - cache-to: type=gha,mode=max \ No newline at end of file + cache-to: type=gha,mode=max + deploy-web: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Node Environment + uses: ./.github/actions/setup-node + + - name: Build Docs + run: yarn docs:build + + - name: Deploy to Netlify + uses: nwtgck/actions-netlify@v1 + with: + publish-dir: "./docs/.vuepress/dist" + production-deploy: true + github-token: ${{ secrets.GITHUB_TOKEN }} + deploy-message: "Deploy ${{ github.event.release.tag_name }}" + enable-commit-comment: false + alias: ${{ github.event.release.tag_name }} + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} diff --git a/.github/workflows/website-preview.yml b/.github/workflows/website-preview.yml new file mode 100644 index 0000000..f6fcbff --- /dev/null +++ b/.github/workflows/website-preview.yml @@ -0,0 +1,39 @@ +name: Site Deploy(Preview) + +on: + pull_request_target: + +jobs: + preview: + runs-on: ubuntu-latest + concurrency: + group: pull-request-preview-${{ github.event.number }} + cancel-in-progress: true + + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Setup Node Environment + uses: ./.github/actions/setup-node + + - name: Build Docs + run: yarn docs:build + + - name: Get Deploy Name + run: | + echo "DEPLOY_NAME=deploy-preview-${{ github.event.number }}" >> $GITHUB_ENV + + - name: Deploy to Netlify + uses: nwtgck/actions-netlify@v1 + with: + publish-dir: "./docs/.vuepress/dist" + production-deploy: false + github-token: ${{ secrets.GITHUB_TOKEN }} + deploy-message: "Deploy ${{ env.DEPLOY_NAME }}@${{ github.sha }}" + enable-commit-comment: false + alias: ${{ env.DEPLOY_NAME }} + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} From f37c30ba8981651b9ceefcd21705bb11a91797f6 Mon Sep 17 00:00:00 2001 From: hemengyang Date: Thu, 19 May 2022 12:39:17 +0000 Subject: [PATCH 22/28] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E5=BF=98?= =?UTF-8?q?=E8=AE=B0=E7=9A=84=20install?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions/build-docs/action.yml | 14 ++++++++++++++ .github/workflows/release.yml | 5 +---- .github/workflows/website-preview.yml | 5 +---- 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 .github/actions/build-docs/action.yml diff --git a/.github/actions/build-docs/action.yml b/.github/actions/build-docs/action.yml new file mode 100644 index 0000000..5a296a3 --- /dev/null +++ b/.github/actions/build-docs/action.yml @@ -0,0 +1,14 @@ +name: Build Docs +description: Build Docs + +runs: + using: "composite" + steps: + - name: Setup Node Environment + uses: ./.github/actions/setup-node + + - name: Build Frontend + shell: bash + run: | + yarn install + yarn docs:build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b715966..8f56ca9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -90,11 +90,8 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Setup Node Environment - uses: ./.github/actions/setup-node - - name: Build Docs - run: yarn docs:build + uses: ./.github/actions/build-docs - name: Deploy to Netlify uses: nwtgck/actions-netlify@v1 diff --git a/.github/workflows/website-preview.yml b/.github/workflows/website-preview.yml index f6fcbff..d6946b3 100644 --- a/.github/workflows/website-preview.yml +++ b/.github/workflows/website-preview.yml @@ -15,11 +15,8 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - name: Setup Node Environment - uses: ./.github/actions/setup-node - - name: Build Docs - run: yarn docs:build + uses: ./.github/actions/build-docs - name: Get Deploy Name run: | From a9b0d570508e1f605fe19ac36e739e534050f534 Mon Sep 17 00:00:00 2001 From: hemengyang Date: Thu, 19 May 2022 12:47:05 +0000 Subject: [PATCH 23/28] =?UTF-8?q?ci:=20=E8=B0=83=E6=95=B4=20main=20?= =?UTF-8?q?=E7=9A=84=E5=B9=B6=E5=8F=91=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f37f954..b5cc8e0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,13 +6,14 @@ on: - main pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build-frontend: name: Build Frontend runs-on: ubuntu-latest - concurrency: - group: build-frontend-${{ github.ref }} - cancel-in-progress: true steps: - uses: actions/checkout@v3 @@ -29,9 +30,6 @@ jobs: name: Test Coverage runs-on: ${{ matrix.os }} needs: build-frontend - concurrency: - group: test-coverage-${{ github.ref }}-${{ matrix.os }}-${{ matrix.python-version }} - cancel-in-progress: true strategy: matrix: python-version: ["3.9", "3.10"] From 603be8eaf6c4e1fa32badeef31ebba0699e0ed1e Mon Sep 17 00:00:00 2001 From: hemengyang Date: Thu, 19 May 2022 12:50:12 +0000 Subject: [PATCH 24/28] =?UTF-8?q?ci:=20=E5=8F=91=E5=B8=83=E6=97=B6?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E4=B8=8A=E4=BC=A0=E8=87=B3=20Release=20Asset?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8f56ca9..323c67b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,6 +37,13 @@ jobs: - name: Publish PyPI run: poetry publish --build -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} || echo "Already pushed to pypi" + + - name: Upload Release Assets + uses: alexellis/upload-assets@0.2.3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + asset_paths: '["./dist/*"]' publish-docker: runs-on: ubuntu-latest needs: build-frontend From 50bf3b642e2d98ca9f1e431fe8ae8da54e8018b6 Mon Sep 17 00:00:00 2001 From: hemengyang Date: Fri, 20 May 2022 04:04:21 +0000 Subject: [PATCH 25/28] =?UTF-8?q?ci:=20=E5=B0=9D=E8=AF=95=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20matrix=20=E7=AE=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b5cc8e0..c6d4e5f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,6 +67,13 @@ jobs: name: Docker runs-on: ubuntu-latest needs: [build-frontend, test] + strategy: + matrix: + include: + - file: ./docker/Dockerfile_with_frontend + tags: felinae98/nonebot-bison:main + - file: ./docker/Dockerfile_with_frontend_sentry + tags: felinae98/nonebot-bison:main-sentry steps: - uses: actions/checkout@v3 @@ -94,18 +101,8 @@ jobs: uses: docker/build-push-action@v2 with: context: . - file: ./docker/Dockerfile_with_frontend + file: ${{ matrix.file }} push: ${{ github.event_name != 'pull_request' }} - tags: felinae98/nonebot-bison:main - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build Sentry and push - uses: docker/build-push-action@v2 - with: - context: . - file: ./docker/Dockerfile_with_frontend_sentry - push: ${{ github.event_name != 'pull_request' }} - tags: felinae98/nonebot-bison:main-sentry + tags: ${{ matrix.tags }} cache-from: type=gha cache-to: type=gha,mode=max From bf5960e0000b79a151cf239aad254ed7700586c4 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Sat, 21 May 2022 21:05:18 +0800 Subject: [PATCH 26/28] update --- .github/workflows/release-trigger.yml | 35 +++++++++++++++++++++++++++ .github/workflows/release.yml | 24 ++++++++++++------ 2 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/release-trigger.yml diff --git a/.github/workflows/release-trigger.yml b/.github/workflows/release-trigger.yml new file mode 100644 index 0000000..8073fb0 --- /dev/null +++ b/.github/workflows/release-trigger.yml @@ -0,0 +1,35 @@ +name: Trigger Release + +on: + workflow_dispatch: + +jobs: + archive: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + ref: main + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Python environment + uses: ./.github/actions/setup-python + + - run: echo "TAG_NAME=v$(poetry version -s)" >> $GITHUB_ENV + + - name: Archive Changelog + uses: docker://ghcr.io/nonebot/auto-changelog:master + with: + archive_regex: '(?<=## )最近更新(?=\n)' + archive_title: ${{ env.TAG_NAME }} + commit_and_push: false + + - name: Push Tag + run: | + git config user.name github-actions[bot] + git config user.email github-actions[bot]@users.noreply.github.com + git add . + git commit -m ":bookmark: Release $(poetry version -s)" + git tag ${{ env.TAG_NAME }} + git push && git push --tags diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 323c67b..bc3177f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,9 @@ name: Release on: - release: - types: [published] + push: + tags: + - v* jobs: build-frontend: @@ -19,7 +20,7 @@ jobs: with: name: frontend path: ./admin-frontend/build/ - publish-pypi: + publish-pypi-github: runs-on: ubuntu-latest needs: build-frontend @@ -38,12 +39,21 @@ jobs: - name: Publish PyPI run: poetry publish --build -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} || echo "Already pushed to pypi" - - name: Upload Release Assets - uses: alexellis/upload-assets@0.2.3 + - run: | + echo "TAG_NAME=${GITHUB_REF#refs/tags/} >> $GITHUB_ENV" + + - uses: release-drafter/release-drafter@v5 + with: + name: Release ${{ env.TAG_NAME }} + tag: ${{ env.TAG_NAME }} + publish: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - asset_paths: '["./dist/*"]' + + - run: | + gh release upload --clobber ${{ env.TAG_NAME }} dist/* + + publish-docker: runs-on: ubuntu-latest needs: build-frontend From 1192101182398fe930eb04622f9c3e01074d204e Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Sat, 21 May 2022 21:24:08 +0800 Subject: [PATCH 27/28] add release drafter --- .github/workflows/release-drafter.yml | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/release-drafter.yml diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..ed5192e --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,39 @@ +name: Release Drafter + +on: + pull_request_target: + branches: + - main + types: + - closed + +jobs: + update-release-drafter: + runs-on: ubuntu-latest + concurrency: + group: pull-request-changelog + cancel-in-progress: true + steps: + - uses: actions/checkout@v3 + + - uses: release-drafter/release-drafter@v5 + id: release-drafter + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Update Changelog + uses: docker://ghcr.io/nonebot/auto-changelog:master + with: + latest_changes_position: '# Change Log\n\n' + latest_changes_title: '## 最近更新' + replace_regex: '(?<=## 最近更新\n)[\s\S]*?(?=\n## )' + changelog_body: ${{ steps.release-drafter.outputs.body }} + commit_and_push: false + + - name: Commit and Push + run: | + git config user.name github-actions[bot] + git config user.email github-actions[bot]@users.noreply.github.com + git add . + git diff-index --quiet HEAD || git commit -m ":memo: Update changelog" + git push From d6420106d4f4cb9e21099d1b66d0e2c6970bc068 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Sat, 21 May 2022 22:11:19 +0800 Subject: [PATCH 28/28] comment pypi --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bc3177f..1e806be 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,8 +36,8 @@ jobs: - name: Setup Python environment uses: ./.github/actions/setup-python - - name: Publish PyPI - run: poetry publish --build -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} || echo "Already pushed to pypi" + # - name: Publish PyPI + # run: poetry publish --build -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} || echo "Already pushed to pypi" - run: | echo "TAG_NAME=${GITHUB_REF#refs/tags/} >> $GITHUB_ENV"