refactor(scripts): update update_lang.py #708
This file contains hidden or 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
name: Deploy Jekyll | |
on: | |
push: | |
branches: ["main"] | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
concurrency: | |
group: 'gh-pages' | |
cancel-in-progress: false | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
environment: github-pages | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 5 | |
- name: Setup Python 3 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.x" | |
- name: Install Dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Output Git Diff | |
run: | | |
git diff --name-only HEAD~1 HEAD | |
- name: Clean Up Credentials | |
run: | | |
rm -f ./gha-creds-*.json | |
- name: Update Language Files | |
run: | | |
DRY_RUN_LANG_OUTPUT=$(python scripts/update_lang.py --dry_run) | |
TOTAL_POSTS=$(echo "$DRY_RUN_LANG_OUTPUT" | grep "Total Markdown files to process:" | awk '{print $NF}') | |
echo "Total posts to process: $TOTAL_POSTS" | |
if [[ "$TOTAL_POSTS" -eq 0 ]]; then | |
echo "No language files to update." | |
else | |
for i in $(seq 1 "$TOTAL_POSTS"); do | |
python scripts/update_lang.py --max_files 1 --model mistral | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add _posts/**/*.md | |
git diff --cached --quiet || git commit -m "chore(lang): Update language files" | |
git push || { | |
echo "Push failed, attempting pull and merge" | |
git pull --rebase | |
git push | |
} | |
fi | |
done | |
fi | |
env: | |
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Dry Run Pdf Files | |
id: dry_run_pdf | |
run: | | |
DRY_RUN_PDF_OUTPUT=$(python scripts/update_pdf.py --max_files 1000 --dry_run) | |
echo "$DRY_RUN_PDF_OUTPUT" | |
if [[ "$DRY_RUN_PDF_OUTPUT" == *'Total Markdown files to process: 0'* ]]; then | |
echo "pdf_updated=false" >> "$GITHUB_OUTPUT" | |
else | |
echo "pdf_updated=true" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Install Microsoft Core Fonts | |
if: steps.dry_run_pdf.outputs.pdf_updated == 'true' | |
run: | | |
sudo apt-get install -y ttf-mscorefonts-installer | |
fc-cache -fv | |
- name: Install Noto Fonts | |
if: steps.dry_run_pdf.outputs.pdf_updated == 'true' | |
run: | | |
sudo apt-get install -y fonts-noto | |
- name: Install Noto CJK | |
if: steps.dry_run_pdf.outputs.pdf_updated == 'true' | |
run: | | |
sudo apt-get install -y fonts-noto-cjk | |
- name: Install DejaVu Fonts | |
if: steps.dry_run_pdf.outputs.pdf_updated == 'true' | |
run: | | |
sudo apt-get install -y fonts-dejavu | |
- name: List Installed Fonts | |
if: steps.dry_run_pdf.outputs.pdf_updated == 'true' | |
run: fc-list | |
- name: Setup TeX Live | |
if: steps.dry_run_pdf.outputs.pdf_updated == 'true' | |
uses: teatimeguest/setup-texlive-action@v3 | |
with: | |
packages: | | |
xeCJK | |
etoolbox | |
adjustbox | |
roboto | |
sourcesanspro | |
fontawesome5 | |
tcolorbox | |
setspace | |
unicode-math | |
fancyvrb | |
olyglossia | |
polyglossia | |
bidi | |
booktabs | |
footnote | |
- name: Install Pandoc | |
if: steps.dry_run_pdf.outputs.pdf_updated == 'true' | |
run: sudo apt-get update && sudo apt-get install -y pandoc | |
- name: Run Pdf-Pipeline.py | |
if: steps.dry_run_pdf.outputs.pdf_updated == 'true' | |
run: | | |
python scripts/update_pdf.py --max_files 1000 | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add assets/pdfs/**/*.pdf | |
git diff --cached --quiet || git commit -m "chore(pdf): Update PDF files" | |
git push || { | |
echo "Push failed, attempting pull and merge" | |
git pull --rebase | |
git push | |
} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup Pages | |
uses: actions/configure-pages@v5 | |
- name: Build with Jekyll | |
uses: actions/jekyll-build-pages@v1 | |
with: | |
source: ./ | |
destination: ./_site | |
- name: Upload Artifact | |
uses: actions/upload-pages-artifact@v3 | |
deploy: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |