ci: 改进文档翻译工作流并添加失败处理

- 添加获取短SHA步骤用于PR标题
- 在翻译脚本中添加失败退出逻辑

Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
longjin 2025-05-22 17:14:36 +08:00
parent 8c7a753d13
commit b7b5ea2c51
2 changed files with 13 additions and 1 deletions

View File

@ -16,6 +16,13 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- id: get-short_sha
uses: actions/github-script@v7.0.1
with:
script: |
const short_sha = context.sha.substring(0, 8)
core.setOutput('short_sha', short_sha)
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
@ -45,7 +52,7 @@ jobs:
uses: peter-evans/create-pull-request@v5 uses: peter-evans/create-pull-request@v5
with: with:
commit-message: "Update translated documentation" commit-message: "Update translated documentation"
title: "docs: Translation update [${{ format('{0:.7}', github.sha) }}]" title: "docs: Translation update [${{steps.get-short_sha.outputs.short_sha}}]"
body: | body: |
Automated translation update triggered by docs changes Automated translation update triggered by docs changes
Commit: ${{ github.sha }} Commit: ${{ github.sha }}

View File

@ -22,6 +22,7 @@ import re
import hashlib import hashlib
import json import json
from pathlib import Path from pathlib import Path
import sys
import threading import threading
from typing import List, Dict, Tuple from typing import List, Dict, Tuple
import openai import openai
@ -456,6 +457,7 @@ class DocumentTranslator:
f"\n翻译完成! Succ: {total_tasks-self.fail_count}, Fail: {self.fail_count}") f"\n翻译完成! Succ: {total_tasks-self.fail_count}, Fail: {self.fail_count}")
if __name__ == "__main__": if __name__ == "__main__":
print("Starting translation process...") print("Starting translation process...")
print("WORKERS: ", CONFIG["max_workers"]) print("WORKERS: ", CONFIG["max_workers"])
@ -465,3 +467,6 @@ if __name__ == "__main__":
translator = DocumentTranslator() translator = DocumentTranslator()
translator.run() translator.run()
if translator.fail_count > 0:
sys.exit(1)