Skip to content

add more advanced pdf convert action #2

add more advanced pdf convert action

add more advanced pdf convert action #2

Workflow file for this run

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
cat > README.md << 'EOF'
# Git By Example — PDF Builds
This branch contains auto-generated PDF builds of the book.

Check failure on line 73 in .github/workflows/build-pdf.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build-pdf.yml

Invalid workflow file

You have an error in your yaml syntax on line 73
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 files below.
EOF
git add README.md gitbyexample-*.pdf
git commit -m "pdf: build from ${GITHUB_SHA::6}" || echo "No changes to commit"
git push origin pdf