From 32312b7e60829e33ee7f2950de171c61b4a11b5c Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Tue, 3 Sep 2024 20:04:51 +0900 Subject: [PATCH 1/2] Clean up workflow --- .github/workflows/build.yml | 41 +++-- .github/workflows/forum_update.yml | 36 ---- scripts/ForumHelper.py | 287 +++++++++++------------------ scripts/ForumUpdate.py | 157 ---------------- 4 files changed, 132 insertions(+), 389 deletions(-) delete mode 100644 .github/workflows/forum_update.yml delete mode 100644 scripts/ForumUpdate.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7597012a4..265229fa0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,11 @@ name: 插件构建发布 -on: [push, pull_request] - +on: + push: + tags-ignore: + - V1.0.0.0 + pull_request: + jobs: Build: runs-on: ubuntu-latest @@ -93,10 +97,10 @@ jobs: body: | # 插件下载和更新日志 ### 📅 每次仓库更新,我们都会在这里发布最新的Release。请注意,这个仓库只有一个Release,所以你总是能在这里找到最新的版本。 - ### 📖文档已经以PDF的形式附在插件包中。更推荐你直接在仓库主页中的[插件列表](https://github.com/UnrealMultiple/TShockPlugin?tab=readme-ov-file#%E5%B7%B2%E6%94%B6%E9%9B%86%E6%8F%92%E4%BB%B6),点击插件名跳转到每个插件的详细文档。 + ### 📖介绍已经以MD的形式附在插件包中,可以使用文本编辑器打开。更推荐你直接在仓库主页中的[插件列表](https://github.com/UnrealMultiple/TShockPlugin?tab=readme-ov-file#%E5%B7%B2%E6%94%B6%E9%9B%86%E6%8F%92%E4%BB%B6),点击插件名跳转。 ### 📦 你可以在页面的`最底部↓↓↓`找到插件包的下载链接。下载完成后,你需要使用`ZIP压缩工具`进行解压。 > [!CAUTION] - >**请你`详细`的看`上面的说明`,不要到处问`插件怎么用`、`ZIP如何解压`、`PDF怎么打开`** + >**请你`仔细`地阅读`上面的说明`,不要到处问`插件怎么用`、`ZIP如何解压`**
更新日志 @@ -117,17 +121,20 @@ jobs: git config --local user.name "GitHub Action" $Changed = [System.Object[]]::new(0) foreach ($p in @(Get-ChildItem src/**/*.csproj)) { - $pot = [System.IO.Path]::Combine($p.DirectoryName, "i18n", "template.pot") - New-Item -Path $p.DirectoryName -Name i18n -ItemType Directory - dotnet tool run GetText.Extractor -u -o -s $p.FullName -t $pot - $d = $(git diff --numstat $pot).Split() - if ($d[0] -le 2 -and $d[1] -le 2) { - git checkout $pot - } else { - foreach ($t in @(Get-ChildItem $($p.DirectoryName)i18n/*.po)) { - msgmerge --previous --update $t $pot - } + $pot = [System.IO.Path]::Combine($p.DirectoryName, "i18n", "template.pot") + New-Item -Path $p.DirectoryName -Name i18n -ItemType Directory -Force + dotnet tool run GetText.Extractor -u -o -s $p.FullName -t $pot + } + foreach ($p in @((git diff --numstat).Split([System.Environment]::NewLine))) { + if (!$p.EndsWith(".pot")) { continue } + $d = $p.Split("`t") + if ($d[0] -le 2 -and $d[1] -le 2) { + git checkout $d[2] + } else { + foreach ($t in @(Get-ChildItem $([System.IO.Path]::GetDirectoryName($d[2]))*.po)) { + msgmerge --previous --update $t $d[2] } + } } git diff --quiet if ($LastExitCode -ne 0) { @@ -145,9 +152,11 @@ jobs: git push } - - name: 同步Gitee + - name: 同步其他平台 continue-on-error: true shell: pwsh if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'UnrealMultiple/TShockPlugin' run: | - python scripts/GiteeSync.py ${{ secrets.CAI_GITEE_TOKEN }} \ No newline at end of file + sudo pip install beautifulsoup4 + python scripts/GiteeSync.py ${{ secrets.CAI_GITEE_TOKEN }} + sudo python scripts/ForumHelper.py Cai ${{ secrets.MONIKA_TR_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/forum_update.yml b/.github/workflows/forum_update.yml deleted file mode 100644 index 4b703747e..000000000 --- a/.github/workflows/forum_update.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: 论坛同步PR日志 -on: - push: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'UnrealMultiple/TShockPlugin' - steps: - - name: 签出代码 - uses: actions/checkout@v4 - - - name: 初始化Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - - name: 安装beautifulsoup4 - run: | - sudo pip install beautifulsoup4 - - - name: 更新论坛 - continue-on-error: true - env: - PYTHONIOENCODING: 'utf-8' - run: - sudo python scripts/ForumUpdate.py Cai ${{ secrets.MONIKA_TR_PASSWORD }} - - - name: 更新论坛主文档 - continue-on-error: true - env: - PYTHONIOENCODING: 'utf-8' - run: - sudo python scripts/ForumHelper.py Cai ${{ secrets.MONIKA_TR_PASSWORD }} \ No newline at end of file diff --git a/scripts/ForumHelper.py b/scripts/ForumHelper.py index a7583a9d2..629ccb872 100644 --- a/scripts/ForumHelper.py +++ b/scripts/ForumHelper.py @@ -2,201 +2,128 @@ import re import sys import requests as rq +import datetime from bs4 import BeautifulSoup -# 读取用户名 密码 name = sys.argv[1] password = sys.argv[2] print(f"论坛自动更新脚本 (by Cai😘)") print(f"登录名: {name}") -# tr.monika.love -# 创建会话 session = rq.Session() -resp = session.get("https://tr.monika.love/") -# 获取xf_token -soup = BeautifulSoup(resp.text, 'html.parser') -data_csrf = soup.html['data-csrf'] - -# 模拟登录 -data = { - "_xfToken": data_csrf, - "login":name, - "password": password, - "remember": 0, - "_xfRedirect": "https://tr.monika.love/", -} -session.post("https://tr.monika.love/login/login",data=data,allow_redirects=True) +try: + recent_pr = rq.get("https://api.github.com/repos/UnrealMultiple/TShockPlugin/pulls?state=closed&per_page=1&page=1").json() + pr_msg = f'{recent_pr[0]["title"]} ({datetime.datetime.strptime(recent_pr[0]["closed_at"], "%Y-%m-%dT%H:%M:%SZ").date()})' +except: + print(f"获取最新PR失败!") + exit() -# 使用GithubAPI转换MD到Html -with open('README.md', 'r',encoding='utf-8') as file: +with open('README.md', 'r', encoding='utf-8') as file: md = file.read() -headers = { +md = re.sub(r'\b[^(\[]*\/README.md\b', lambda x: "https://gitee.com/kksjsj/TShockPlugin/blob/master/" + x.group(), md) +rendered = rq.post("https://api.github.com/markdown", headers = { "Accept": "application/vnd.github+json", - #"Authorization": "Bearer ", "X-GitHub-Api-Version": "2022-11-28" -} - -# 修复插件列表路径 -md = re.sub(r'\b[^(\[]*\/README.md\b', lambda x: "https://gitee.com/kksjsj/TShockPlugin/blob/master/" + x.group(), md) - -data = { +}, data = json.dumps({ "text": md -} -html = rq.post("https://api.github.com/markdown", headers=headers, data=json.dumps(data)).text - +})).text + +def login(session: Session, url: str): + resp = session.get(url) + soup = BeautifulSoup(resp.text, 'html.parser') + data_csrf = soup.html['data-csrf'] + session.post(url + "login/login", data = { + "login": name, + "password": password, + "remember": 0, + "_xfToken": data_csrf, + "_xfRedirect": url, + }, allow_redirects = True) + return data_csrf -# 编辑论坛仓库帖子 -data = { - "_xfToken": data_csrf, - "prefix_id[]": 7, - "title": "TShock插件收集仓库(自动更新版)", - "tag_line": "此帖会自动更新插件列表", - "version_string": "总是最新", - "external_download_url": "https://github.moeyy.xyz/https://github.com/UnrealMultiple/TShockPlugin/releases/download/V1.0.0.0/Plugins.zip", - "description_html": f"{html}", - # "attachment_hash": "291d0c03815801596ec54fa208a79bfb", # 附件相关 - # "attachment_hash_combined": { - # "type": "resource_update", - # "context": { - # "resource_update_id": 130 - # }, - # "hash": "291d0c03815801596ec54fa208a79bfb" - # }, - "external_url": "", - "icon_action": "custom", - "_xfRequestUri": "/resources/104/edit", - "_xfWithData": 1, - "_xfResponseType": "json" -} try: - resp = session.post("https://tr.monika.love/resources/104/edit",data=data) - res = resp.json() - if res['status'] == 'ok': - print(f"[MONIKA]修改成功: {res}") - else: - print(f"[MONIKA]修改失败: {res}") -except: - print(f"[MONIKA]修改失败!{resp.text}") - -# trhub.cn -# 创建会话 -session = rq.Session() -resp = session.get("https://trhub.cn/") - -# 获取xf_token -soup = BeautifulSoup(resp.text, 'html.parser') -data_csrf = soup.html['data-csrf'] + data_csrf = login(session, "https://tr.monika.love/") + + try: + resp = session.post("https://tr.monika.love/resources/104/edit", data = { + "prefix_id[]": 7, + "title": "TShock插件收集仓库(自动更新版)", + "tag_line": "此帖会自动更新插件列表", + "version_string": "总是最新", + "external_download_url": "https://github.moeyy.xyz/https://github.com/UnrealMultiple/TShockPlugin/releases/download/V1.0.0.0/Plugins.zip", + "description_html": f"{rendered}", + "external_url": "", + "icon_action": "custom", + "_xfRequestUri": "/resources/104/edit", + "_xfWithData": 1, + "_xfToken": data_csrf, + "_xfResponseType": "json" + }) + res = resp.json() + if res['status'] == 'ok': + print(f"[MONIKA] 更新资源成功: {res}") + else: + raise Exception(f"{res}") + except Exception as e: + print(f"[MONIKA] 更新资源失败! {resp.text} {e}") + + try: + resp = session.post("https://tr.monika.love/resources/104/post-update", data = { + "new_update": "1", + "update_title": "同步仓库更新", + "update_message_html": pr_msg, + "_xfRequestUri": "/resources/104/post-update", + "_xfWithData": "1", + "_xfToken": data_csrf, + "_xfResponseType": "json" + }) + res = resp.json() + if res['status'] == 'ok': + print(f"[MONIKA] 添加回复成功: {res}") + else: + raise Exception(f"{res}") + except Exception as e: + print(f"[MONIKA] 添加回复失败! {resp.text} {e}") +except Exception as e: + print(f"[MONIKA] 同步仓库更新失败! {e}") -# 模拟登录 -data = { - "_xfToken": data_csrf, - "login":name, - "password": password, - "remember": 0, - "_xfRedirect": "https://trhub.cn/", -} -session.post("https://trhub.cn/login/login",data=data,allow_redirects=True) - - -# 编辑论坛仓库帖子 -data = { - "_xfToken": data_csrf, - "prefix_id": 0, - "title": "TShock插件收集仓库(自动更新版)", - "message_html": f"{html}", - # "attachment_hash": "291d0c03815801596ec54fa208a79bfb", - # "attachment_hash_combined": { - # "type": "resource_update", - # "context": { - # "resource_update_id": 130 - # }, - # "hash": "291d0c03815801596ec54fa208a79bfb" - # }, - "_xfRequestUri": "/threads/github-action-test.43/", - "_xfWithData": 1, - "_xfResponseType": "json" -} try: - resp = session.post("https://trhub.cn/posts/107/edit",data=data) - res = resp.json() - if res['status'] == 'ok': - print(f"[TRHUB]修改成功: {res}") - else: - print(f"[TRHUB]修改失败: {res}") -except: - print(f"[TRHUB]修改失败!{resp.text}") - - -''' -proxies = {'http': "220.248.70.237:9002", - 'https': "220.248.70.237:9002"} - -# BBSTR -name = "Cai233" -# 创建会话 -session = rq.Session() -resp = session.get("https://www.bbstr.net/",timeout=10,proxies=proxies) - -# 获取xf_token -soup = BeautifulSoup(resp.text, 'html.parser') -data_csrf = soup.html['data-csrf'] - - -# 模拟登录 -data = { - "_xfToken": data_csrf, - "login":name, - "password": password, - "remember": 0, - "_xfRedirect": "https://www.bbstr.net/", -} -session.post("https://www.bbstr.net/login/login",data=data,allow_redirects=True,proxies=proxies) - - -# 编辑论坛仓库帖子 -data = { - "title": "TShock插件收集仓库(自动更新版)", - "tag_line": "此帖会自动更新插件列表(BBSTR高概率同步失败)", - "custom_fields[1]": "TShock Chinese Plugins Collection", - "custom_fields[2]": "TShock插件收集仓库", - "custom_fields[3]": "2", - "custom_fields[4]": "0", - "custom_fields[5][]": "0", - "custom_fields[5][]": "1", - "custom_fields[5][]": "2", - "custom_fields[5][]": "3", - "custom_fields[5][]": "4", - "custom_fields[5][]": "5", - "custom_fields[5][]": "6", - "custom_fields[5][]": "7", - "custom_fields[6][]": "0", - "custom_fields[7][]": "6", - "custom_fields[8]": "看情况", - "custom_fields[9]": "https://github.com/UnrealMultiple/TShockPlugin/", - "custom_fields[10]": "https://github.com/UnrealMultiple/TShockPlugin/", - "custom_fields[11]": "TShock最新版本", - "description_html": html, - "external_url": "https://github.moeyy.xyz/https://github.com/UnrealMultiple/TShockPlugin/releases/download/V1.0.0.0/Plugins.zip", - "alt_support_url": "", - "icon_action": "custom", - "_xfToken": data_csrf, - "_xfRequestUri": "/resources/167/edit", - "_xfWithData": "1", - "_xfResponseType": "json" -} - - - -try: - resp = session.post("https://www.bbstr.net/resources/167/edit",data=data,timeout=10,proxies=proxies) - res = resp.json() - if res['status'] == 'ok': - print(f"[BBSTR]修改成功: {res}") - else: - print(f"[BBSTR]修改失败: {res}") -except: - print(f"[BBSTR]修改失败!{resp.text}") -''' - + data_csrf = login(session, "https://trhub.cn/") + + try: + resp = session.post("https://trhub.cn/posts/107/edit", data = { + "prefix_id": 0, + "title": "TShock插件收集仓库(自动更新版)", + "message_html": f"{rendered}", + "_xfRequestUri": "/threads/github-action-test.43/", + "_xfWithData": 1, + "_xfToken": data_csrf, + "_xfResponseType": "json" + }) + res = resp.json() + if res['status'] == 'ok': + print(f"[TRHUB] 更新帖子成功: {res}") + else: + raise Exception(f"{res}") + except Exception as e: + print(f"[TRHUB] 更新帖子失败! {resp.text} {e}") + + try: + resp = session.post("https://trhub.cn/threads/tshock.43/add-reply", data = { + "message_html": pr_msg, + "load_extra": 1, + "_xfRequestUri": "/threads/tshock.43/", + "_xfWithData": 1, + "_xfToken": data_csrf, + "_xfResponseType": "json" + }) + res = resp.json() + if res['status'] == 'ok': + print(f"[TRHUB] 添加回复成功: {res}") + else: + raise Exception(f"{res}") + except Exception as e: + print(f"[TRHUB] 添加回复失败! {resp.text} {e}") +except Exception as e: + print(f"[TRHUB] 同步仓库更新失败! {e}") diff --git a/scripts/ForumUpdate.py b/scripts/ForumUpdate.py deleted file mode 100644 index 45d5e2ae3..000000000 --- a/scripts/ForumUpdate.py +++ /dev/null @@ -1,157 +0,0 @@ -import datetime -import json -import sys -from bs4 import BeautifulSoup -import requests as rq - -result = rq.get("https://api.github.com/repos/UnrealMultiple/TShockPlugin/pulls?state=closed&per_page=1&page=1").json() - - -html = f'{result[0]["title"]} ({datetime.datetime.strptime(result[0]["closed_at"], "%Y-%m-%dT%H:%M:%SZ").date()})' -# 读取用户名 密码 -name = sys.argv[1] -password = sys.argv[2] -print(f"论坛自动更新脚本 (by Cai😘)") -print(f"登录名: {name}") - - -# tr.monika.love -# 创建会话 -session = rq.Session() -resp = session.get("https://tr.monika.love/") - -# 获取xf_token -soup = BeautifulSoup(resp.text, 'html.parser') -data_csrf = soup.html['data-csrf'] - -# 模拟登录 -data = { - "_xfToken": data_csrf, - "login":name, - "password": password, - "remember": 0, - "_xfRedirect": "https://tr.monika.love/", -} -session.post("https://tr.monika.love/login/login",data=data,allow_redirects=True) - - -data = { - "new_update": "1", - "update_title": "同步仓库更新", - "update_message_html": f"{html}", - #"attachment_hash": "ed8d3a4157b31fcf4911bfaf14fb7300", - #"attachment_hash_combined": "{\"type\":\"resource_update\",\"context\":{\"resource_id\":115},\"hash\":\"ed8d3a4157b31fcf4911bfaf14fb7300\"}", - "_xfRequestUri": "/resources/104/post-update", - "_xfWithData": "1", - "_xfToken": data_csrf, - "_xfResponseType": "json" -} -try: - resp = session.post("https://tr.monika.love/resources/104/post-update",data=data) - res = resp.json() - if res['status'] == 'ok': - print(f"[MONIKA]修改成功: {res}") - else: - print(f"[MONIKA]修改失败: {res}") -except: - print(f"[MONIKA]修改失败!{resp.text}") - - -# trhub.cn -# 创建会话 -session = rq.Session() -resp = session.get("https://trhub.cn/") - -# 获取xf_token -soup = BeautifulSoup(resp.text, 'html.parser') -data_csrf = soup.html['data-csrf'] - -# 模拟登录 -data = { - "_xfToken": data_csrf, - "login":name, - "password": password, - "remember": 0, - "_xfRedirect": "https://trhub.cn/", -} -session.post("https://trhub.cn/login/login",data=data,allow_redirects=True) - - -data = { - "_xfToken": data_csrf, - "message_html": f"{html}", - # "attachment_hash": "291d0c03815801596ec54fa208a79bfb", # 附件相关 - # "attachment_hash_combined": { - # "type": "resource_update", - # "context": { - # "resource_update_id": 130 - # }, - # "hash": "291d0c03815801596ec54fa208a79bfb" - # }, - "load_extra": 1, - "_xfRequestUri": "/threads/tshock.43/", - "_xfWithData": 1, - "_xfResponseType": "json" -} -try: - resp = session.post("https://trhub.cn/threads/tshock.43/add-reply",data=data) - res = resp.json() - if res['status'] == 'ok': - print(f"[TRHUB]修改成功: {res}") - else: - print(f"[TRHUB]修改失败: {res}") -except: - print(f"[TRHUB]修改失败!{resp.text}") - -''' -# BBSTR -name = "Cai233" -# 创建会话 -session = rq.Session() -resp = session.get("https://www.bbstr.net/",timeout=10) - -# 获取xf_token -soup = BeautifulSoup(resp.text, 'html.parser') -data_csrf = soup.html['data-csrf'] - -proxies = {'http': "220.248.70.237:9002", - 'https': "220.248.70.237:9002"} - -# 模拟登录 -data = { - "_xfToken": data_csrf, - "login":name, - "password": password, - "remember": 0, - "_xfRedirect": "https://www.bbstr.net/", -} -session.post("https://www.bbstr.net/login/login",data=data,allow_redirects=True,proxies=proxies) - -# 模拟登录 - -data = { - "_xfToken": data_csrf, - "message_html": f"{html}", - # "attachment_hash": "291d0c03815801596ec54fa208a79bfb", # 附件相关 - # "attachment_hash_combined": { - # "type": "resource_update", - # "context": { - # "resource_update_id": 130 - # }, - # "hash": "291d0c03815801596ec54fa208a79bfb" - # }, - "load_extra": 1, - "_xfRequestUri": "/threads/2427/", - "_xfWithData": 1, - "_xfResponseType": "json" -} -try: - resp = session.post("https://www.bbstr.net/threads/2427/add-reply",data=data,timeout=10,proxies=proxies) - res = resp.json() - if res['status'] == 'ok': - print(f"[BBSTR]修改成功: {res}") - else: - print(f"[BBSTR]修改失败: {res}") -except: - print(f"[BBSTR]修改失败!{resp.text}") -''' From 69d6aceadf160d5e33f61ac93e1a0faf4bed8a64 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Wed, 4 Sep 2024 09:01:31 +0900 Subject: [PATCH 2/2] Add untracked pot files --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 265229fa0..8845c15c0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -125,6 +125,7 @@ jobs: New-Item -Path $p.DirectoryName -Name i18n -ItemType Directory -Force dotnet tool run GetText.Extractor -u -o -s $p.FullName -t $pot } + git add -N src/**/i18n/*.pot foreach ($p in @((git diff --numstat).Split([System.Environment]::NewLine))) { if (!$p.EndsWith(".pot")) { continue } $d = $p.Split("`t")