refactor(scripts): improve update_lang.py logic #695
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: Dry Run Language Files | |
id: dry_run_lang | |
run: | | |
export DEEPSEEK_API_KEY=${{ secrets.DEEPSEEK_API_KEY }} | |
DRY_RUN_OUTPUT=$(python scripts/update_lang.py --dry_run) | |
echo "$DRY_RUN_OUTPUT" | |
if [[ "$DRY_RUN_OUTPUT" == *'Total Markdown files to process: 0'* ]]; then | |
echo "lang_updated=false" >> "$GITHUB_OUTPUT" | |
else | |
echo "lang_updated=true" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Update Language Files | |
if: steps.dry_run_lang.outputs.lang_updated == 'true' | |
run: | | |
export DEEPSEEK_API_KEY=${{ secrets.DEEPSEEK_API_KEY }} | |
python scripts/update_lang.py | |
- name: Clean Up Credentials | |
run: | | |
rm -f ./gha-creds-*.json | |
- name: Commit Language Files | |
if: steps.dry_run_lang.outputs.lang_updated == 'true' | |
run: | | |
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 | |
} | |
env: | |
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: Clean Up Credentials | |
if: steps.dry_run_pdf.outputs.pdf_updated == 'true' | |
run: | | |
rm -f ./gha-creds-*.json | |
- 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 |