-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://gitee.com/zero--two/obsidian-i18n-tr…
- Loading branch information
Showing
17 changed files
with
1,082 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: 将GItee的最新release同步到Github | ||
|
||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
reason: | ||
description: '触发原因' | ||
required: false | ||
default: '将GItee的最新release同步到Github' | ||
|
||
jobs: | ||
run: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Checkout Gitee repository | ||
run: | | ||
git clone https://gitee.com/zero--two/obsidian-i18n-translation.git | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.10' # 您需要的 Python 版本 | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install requests # 安装所需的库 | ||
- name: Run script | ||
env: | ||
ACCESS_TOKEN_GITHUB: ${{ secrets.ACCESS_TOKEN_GITHUB }} | ||
run: | | ||
python ./obsidian-i18n-translation/script/sync-release-gitee2github.py # 执行脚本 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import os | ||
import requests | ||
import zipfile | ||
import io | ||
|
||
# Gitee 和 GitHub 的信息 | ||
GITEE_REPO = 'zero--two/obsidian-i18n-translation' | ||
GITHUB_REPO = '0011000000110010/obsidian-i18n' | ||
GITHUB_TOKEN = os.environ.get('ACCESS_TOKEN_GITHUB') # 用于身份验证 | ||
|
||
# 检查 GitHub 上是否存在同名的 Release | ||
def check_existing_release(release_name): | ||
existing_releases_url = f'https://api.github.com/repos/{GITHUB_REPO}/releases' | ||
existing_releases_response = requests.get(existing_releases_url, headers={'Authorization': f'token {GITHUB_TOKEN}'}) | ||
|
||
try: | ||
existing_releases_response.raise_for_status() | ||
except requests.exceptions.HTTPError as e: | ||
print(f'检查现有 Release 时出错: {e}') | ||
return False # 返回 False 表示检查失败 | ||
|
||
existing_releases = existing_releases_response.json() | ||
|
||
# 检查是否存在同名的 Release | ||
for release in existing_releases: | ||
if release['name'] == release_name: | ||
print(f'错误: 已存在同名的 Release: {release_name},不执行下载操作。') | ||
return True # 返回 True 表示存在同名 Release | ||
|
||
return False # 返回 False 表示不存在同名 Release | ||
|
||
# 下载 Gitee Release | ||
def download_gitee_release(): | ||
url = f'https://gitee.com/api/v5/repos/{GITEE_REPO}/releases/latest' | ||
response = requests.get(url) | ||
response.raise_for_status() # 检查请求是否成功 | ||
release_data = response.json() | ||
|
||
# 获取 Release 名称 | ||
release_name = release_data.get('name', 'Latest Release') | ||
|
||
# 创建子目录以存放下载的文件 | ||
download_dir = f'downloads/{release_name}' | ||
os.makedirs(download_dir, exist_ok=True) # 创建目录,如果已存在则不报错 | ||
|
||
# 获取 Release 中的资产 | ||
assets = release_data.get('assets', []) | ||
downloaded_files = [] # 用于记录下载的文件名 | ||
for asset in assets: | ||
download_url = asset['browser_download_url'] | ||
file_name = asset['name'] | ||
|
||
# 只下载非源代码文件 | ||
if not (file_name.endswith('.zip') or file_name.endswith('.tar.gz')): | ||
print(f'正在下载 {file_name}...') | ||
file_response = requests.get(download_url) | ||
file_response.raise_for_status() | ||
|
||
# 保存文件到子目录 | ||
file_path = os.path.join(download_dir, file_name) | ||
with open(file_path, 'wb') as f: | ||
f.write(file_response.content) | ||
print(f'{file_name} 下载完成。') | ||
downloaded_files.append(file_path) # 记录下载的文件路径 | ||
else: | ||
print(f'跳过源代码文件 {file_name}。') | ||
|
||
return release_name, downloaded_files # 返回 Release 名称和下载的文件路径列表 | ||
|
||
# 上传到 GitHub | ||
def upload_to_github(release_name, downloaded_files): | ||
# 创建新的 GitHub Release | ||
create_release_url = f'https://api.github.com/repos/{GITHUB_REPO}/releases' | ||
release_data = { | ||
'tag_name': release_name, # 使用 Release 名称作为标签 | ||
'name': release_name, | ||
'body': f'Release {release_name} from Gitee', | ||
'draft': False, | ||
'prerelease': False | ||
} | ||
|
||
release_response = requests.post(create_release_url, json=release_data, headers={'Authorization': f'token {GITHUB_TOKEN}'}) | ||
|
||
# 添加错误处理 | ||
try: | ||
release_response.raise_for_status() | ||
except requests.exceptions.HTTPError as e: | ||
print(f'创建 Release 时出错: {e}') | ||
return # 退出函数,避免后续代码执行 | ||
|
||
release_id = release_response.json()['id'] | ||
|
||
# 上传下载的文件 | ||
for file_path in downloaded_files: | ||
file_name = os.path.basename(file_path) # 获取文件名 | ||
print(f'正在上传 {file_name} 到 GitHub...') | ||
with open(file_path, 'rb') as f: | ||
upload_response = requests.post( | ||
f'https://uploads.github.com/repos/{GITHUB_REPO}/releases/{release_id}/assets?name={file_name}', | ||
headers={ | ||
'Authorization': f'token {GITHUB_TOKEN}', | ||
'Content-Type': 'application/octet-stream' | ||
}, | ||
data=f | ||
) | ||
upload_response.raise_for_status() # 检查上传是否成功 | ||
print(f'{file_name} 上传完成。') | ||
|
||
if __name__ == '__main__': | ||
release_name, downloaded_files = download_gitee_release() # 获取 Release 名称和下载的文件路径 | ||
if not check_existing_release(release_name): # 检查是否存在同名 Release | ||
upload_to_github(release_name, downloaded_files) # 上传下载的文件并同步 Release 名称 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
translation/dict/cm-typewriter-scroll-obsidian/zh-cn/0.2.2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"manifest": { | ||
"translationVersion": 1730799373498, | ||
"pluginVersion": "1.0.3" | ||
}, | ||
"description": { | ||
"original": "Display navigation links at the top of the notes.", | ||
"translation": "在笔记顶部显示导航链接。" | ||
}, | ||
"dict": { | ||
"Notice(\"Failed to read the daily note template\")": "Notice(\"无法阅读每日笔记模板\")", | ||
"Notice(\"Unable to create new file.\")": "Notice(\"无法创建新文件。\")", | ||
".log(_)": ".log(_)", | ||
".error(`Failed to read the daily note template '${l}'`,u)": ".error(`无法阅读每日笔记模板 '${l}'`,u)", | ||
".error(`Failed to create file: '${b}'`,x)": ".error(`文件建立失败: '${b}'`,x)", | ||
".error(`Failed to create file: '${h}'`,_)": ".error(`文件建立失败: '${h}'`,_)", | ||
"name:\"Anno Domini\"": "name:\"公元\"", | ||
"name:\"Before Christ\"": "name:\"公元前\"", | ||
"text:\"Create a new note\"": "text:\"创建一个新笔记\"", | ||
"text:`File \"${this.fileTitle}\" does not exist. Are you sure you want to create a new note?`": "text:`文件 \"${this.fileTitle}\" 不存在. 确定新建文件?`", | ||
".setButtonText(\"Create\")": ".setButtonText(\"创建\")", | ||
".setButtonText(\"Create (Don't ask again)\")": ".setButtonText(\"创建(不再询问)\")", | ||
".setButtonText(\"Cancel\")": ".setButtonText(\"取消\")", | ||
".setName(\"Display navigation links in each view\")": ".setName(\"在每个视图中显示导航链接\")", | ||
".setName(\"Display navigation links in page preview\")": ".setName(\"在页面预览中显示导航链接\")", | ||
".setName(\"Enable annotated links\")": ".setName(\"启用注释链接\")", | ||
".setName(\"Annotation strings\")": ".setName(\"注释字符串\")", | ||
".setName(\"Enable daily note links\")": ".setName(\"启用每日笔记链接\")", | ||
".setName(\"Enable weekly note links\")": ".setName(\"启用每周笔记链接\")", | ||
".setName(\"Enable monthly note links\")": ".setName(\"启用每月笔记链接\")", | ||
".setName(\"Enable quarterly note links\")": ".setName(\"启用季度笔记链接\")", | ||
".setName(\"Enable yearly note links\")": ".setName(\"启用年度笔记链接\")", | ||
".setName(\"Display placeholder\")": ".setName(\"显示占位符\")", | ||
".setName(\"Confirm when creating a new file\")": ".setName(\"在创建新文件时确认\")", | ||
".setDesc(\"Display annotated backlinks in the navigation. If one of the annotation strings is placed immediately before a link, the link is recognized as an annotated link. Notes with annotated links appear as backlinks at the top of the destination note. \")": ".setDesc(\"在导航中显示带注释的反向链接。如果其中一个注释字符串放在链接之前,则该链接将被识别为带注释的链接。带有注释链接的注释在目标注释的顶部显示为反向链接。\")", | ||
".setDesc(\"Define the annotation strings. Any string, including emoji, is acceptable as long as the following link is recognized as a backlink. To specify multiple annotations, separate them with commas.\")": ".setDesc(\"定义注释字符串。任何字符串,包括表情符号,只要以下链接被识别为反向链接,都是可以接受的。要指定多个注释,请用逗号分隔它们。\")", | ||
".setDesc(\"Display links to adjacent daily notes.\")": ".setDesc(\"显示链接到相邻的每日笔记。\")", | ||
".setDesc(\"Display links to adjacent weekly notes.\")": ".setDesc(\"显示相邻每周笔记的链接。\")", | ||
".setDesc(\"Display links to adjacent monthly notes.\")": ".setDesc(\"显示相邻月度笔记的链接。\")", | ||
".setDesc(\"Display links to adjacent quarterly notes.\")": ".setDesc(\"显示相邻季度笔记的链接\")", | ||
".setDesc(\"Display links to adjacent yearly notes.\")": ".setDesc(\"显示相邻年度笔记的链接。\")", | ||
".setDesc(\"Display a placeholder when there is nothing to display. This prevents the contents of the view from being rattled when the link is loaded.\")": ".setDesc(\"当没有要显示的内容时显示占位符。这可以防止在加载链接时视图的内容出现抖动。\")" | ||
} | ||
} |
Oops, something went wrong.