Skip to content

Commit 8430611

Browse files
committed
ci(.github/workflows): Update gh-pages workflow and lang script
1 parent 8fc6495 commit 8430611

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

.github/workflows/gh-pages.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,31 @@ jobs:
4545
- name: Update Language Files
4646
if: steps.dry_run_lang.outputs.lang_updated == 'true'
4747
run: |
48-
UPDATE_LANG_OUTPUT=$(python scripts/update_lang.py --max_files 1 --model mistral | grep "Total Markdown files to process:")
49-
echo "$UPDATE_LANG_OUTPUT"
50-
if [[ "$UPDATE_LANG_OUTPUT" == *'Total Markdown files to process: 0'* ]]; then
48+
TOTAL_POSTS=$(python scripts/update_lang.py --dry_run | grep "Total Markdown files to process:" | awk '{print $NF}')
49+
echo "Total posts to process: $TOTAL_POSTS"
50+
51+
if [[ "$TOTAL_POSTS" -eq 0 ]]; then
5152
echo "No language files to update."
5253
else
53-
git config user.name "github-actions[bot]"
54-
git config user.email "github-actions[bot]@users.noreply.github.com"
55-
git add _posts/**/*.md
56-
git diff --cached --quiet || git commit -m "chore(lang): Update language files"
57-
58-
git push || {
59-
echo "Push failed, attempting pull and merge"
60-
git pull --rebase
61-
git push
62-
}
54+
for i in $(seq 1 "$TOTAL_POSTS"); do
55+
UPDATE_LANG_OUTPUT=$(python scripts/update_lang.py --max_files 1 --model mistral | grep "Total Markdown files to process:")
56+
echo "$UPDATE_LANG_OUTPUT"
57+
if [[ "$UPDATE_LANG_OUTPUT" == *'Total Markdown files to process: 0'* ]]; then
58+
echo "No more language files to update."
59+
break
60+
else
61+
git config user.name "github-actions[bot]"
62+
git config user.email "github-actions[bot]@users.noreply.github.com"
63+
git add _posts/**/*.md
64+
git diff --cached --quiet || git commit -m "chore(lang): Update language files"
65+
66+
git push || {
67+
echo "Push failed, attempting pull and merge"
68+
git pull --rebase
69+
git push
70+
}
71+
fi
72+
done
6373
fi
6474
env:
6575
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
@@ -69,7 +79,7 @@ jobs:
6979
id: dry_run_pdf
7080
run: |
7181
DRY_RUN_PDF_OUTPUT=$(python scripts/update_pdf.py --max_files 1000 --dry_run)
72-
echo "$DRY_RUN_PDF_OUTPUT"
82+
echo "$DRY_RUN_PDF_OUTPUT"
7383
7484
if [[ "$DRY_RUN_PDF_OUTPUT" == *'Total Markdown files to process: 0'* ]]; then
7585
echo "pdf_updated=false" >> "$GITHUB_OUTPUT"

scripts/update_lang.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,13 @@ def main():
283283

284284
parser = argparse.ArgumentParser(description="Translate markdown files to a specified language.")
285285
parser.add_argument("--lang", type=str, default="all", help="Target language for translation (e.g., ja, es, all).")
286+
parser.add_argument("--dry_run", action="store_true", help="Perform a dry run without modifying files.")
286287
parser.add_argument("--file", type=str, default=None, help="Specific file to translate.")
287288
parser.add_argument("--max_files", type=int, default=None, help="Maximum number of files to process.")
288289
parser.add_argument("--model", type=str, default="deepseek", help="Model to use for translation (deepseek or mistral).")
289290
args = parser.parse_args()
290291
target_language = args.lang
292+
dry_run = args.dry_run
291293
input_file = args.file
292294
max_files = args.max_files
293295
model = args.model
@@ -306,6 +308,9 @@ def main():
306308
changed_files = changed_files[:max_files]
307309
total_files_to_process = len(changed_files)
308310

311+
if dry_run:
312+
print(f"Total Markdown files to process: {total_files_to_process}")
313+
return
309314

310315
with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_THREADS) as executor:
311316
futures = []

0 commit comments

Comments
 (0)