From 409d63ef5268cc3300ac2b08601786def7049b62 Mon Sep 17 00:00:00 2001 From: fxliang Date: Sat, 27 Jul 2024 20:05:04 +0800 Subject: [PATCH] add workflow_dispatch for manually rerun the action, with testing/weasel/appcast.xml updated. (#1630) --- .github/workflows/gh-pages.yml | 3 ++ blog/weasel_testing_appcast.py | 69 ++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 blog/weasel_testing_appcast.py diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 274020198..c985882d3 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -1,6 +1,7 @@ name: GitHub Pages on: + workflow_dispatch: push: branches: - ci @@ -43,6 +44,8 @@ jobs: - run: npm ci + - run: python ./weasel_testing_appcast.py + - run: | hexo clean hexo generate diff --git a/blog/weasel_testing_appcast.py b/blog/weasel_testing_appcast.py new file mode 100644 index 000000000..911337e08 --- /dev/null +++ b/blog/weasel_testing_appcast.py @@ -0,0 +1,69 @@ +import requests +import time +from datetime import datetime, timedelta, timezone + +datas = [] +for url in ["https://api.github.com/repos/rime/weasel/releases/tags/latest", "https://api.github.com/repos/rime/weasel/releases/latest"]: + response = requests.get(url) + if response.ok: + datas.append(response.json()) +filenames = [] +urls = [] +update_time = [] +tags_name = [] +for data in datas: + for asset in data['assets']: + if asset['name'].endswith('.exe'): + filenames.append(asset['name']) + urls.append(asset['browser_download_url']) + update_time.append(data['published_at']) + tags_name.append(data['tag_name']) +# compare update_time and get the latest one +latest_time = update_time[0] +latest_index = 0 +for i in range(1, len(update_time)): + if update_time[i] > latest_time: + latest_time = update_time[i] + latest_index = i +# get version number +version = filenames[latest_index].replace("-installer.exe", "") +version = version.replace("weasel-", "") +# download url +download_url = urls[latest_index] +# get local time in format like "Thu, 01 Jan 1970 00:00:00 +0000" +utc_offset_sec = -time.timezone if time.localtime().tm_isdst == 0 else -time.altzone +utc_offset = timedelta(seconds=utc_offset_sec) +current_tz = timezone(utc_offset) +utc_time = datetime.strptime(update_time[latest_index], "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc) +local_time = utc_time.astimezone(current_tz) +formatted_time = local_time.strftime("%a, %d %b %Y %H:%M:%S %z") +# get release notes link +if tags_name[latest_index] == "latest": + releaseNotesLink = "https://github.com/rime/weasel/releases/tag/latest" +else: + releaseNotesLink = "http://rime.github.io/testing/weasel/release-notes.html" +# format xml file content +template = f""" + + + 【小狼毫】輸入法測試頻道 + http://rime.github.io/testing/weasel/appcast.xml + 小狼毫測試版 Appcast 更新頻道 + zh + + 小狼毫 {version} + {releaseNotesLink} + {formatted_time} + + + + +""" +print("output appcast.xml content:") +print(template) +# write template to ./source/testing/weasel/appcast.xml +with open("./source/testing/weasel/appcast.xml", "w", encoding='utf-8') as f: + f.write(template) + f.close()