fix layout render #5
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: Build PDF | |
| on: | |
| push: | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| jobs: | |
| build-pdf: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install system fonts | |
| run: | | |
| sudo apt-get update -qq | |
| sudo apt-get install -y -qq fonts-ibm-plex | |
| - name: Install Python dependencies | |
| run: pip install reportlab pygments fonttools | |
| - name: Convert Inter fonts (OTF → TTF for ReportLab) | |
| run: python scripts/convert_fonts.py | |
| - name: Get short commit hash | |
| id: vars | |
| run: echo "short_sha=$(git rev-parse --short=6 HEAD)" >> "$GITHUB_OUTPUT" | |
| - name: Build both PDFs | |
| run: python scripts/build_pdf.py "gitbyexample-${{ steps.vars.outputs.short_sha }}" --both | |
| - name: Publish to pdf branch | |
| run: | | |
| SHORT="${{ steps.vars.outputs.short_sha }}" | |
| LIGHT="gitbyexample-${SHORT}-light.pdf" | |
| DARK="gitbyexample-${SHORT}-dark.pdf" | |
| cp "$LIGHT" /tmp/ | |
| cp "$DARK" /tmp/ | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| if git ls-remote --heads origin pdf | grep -q pdf; then | |
| git fetch origin pdf | |
| git checkout pdf | |
| else | |
| git checkout --orphan pdf | |
| git rm -rf . 2>/dev/null || true | |
| git clean -fd | |
| fi | |
| cp /tmp/"$LIGHT" . | |
| cp /tmp/"$DARK" . | |
| ls -t gitbyexample-*-light.pdf 2>/dev/null | tail -n +11 | xargs -r rm -f | |
| ls -t gitbyexample-*-dark.pdf 2>/dev/null | tail -n +11 | xargs -r rm -f | |
| printf '%s\n' \ | |
| "# Git By Example — PDF Builds" \ | |
| "" \ | |
| "This branch contains auto-generated PDF builds of the book." \ | |
| "" \ | |
| "Each push to main produces two PDFs:" \ | |
| "- gitbyexample-COMMIT-light.pdf — Light edition" \ | |
| "- gitbyexample-COMMIT-dark.pdf — Dark edition" \ | |
| "" \ | |
| "Download the latest: check the most recent file below." \ | |
| > README.md | |
| git add README.md gitbyexample-*.pdf | |
| git commit -m "pdf: build from ${GITHUB_SHA::6}" || echo "No changes to commit" | |
| git push origin pdf |