Skip to content

Generate PDF, Word & EPUB Documents #43

Generate PDF, Word & EPUB Documents

Generate PDF, Word & EPUB Documents #43

Workflow file for this run

name: Generate PDF, Word & EPUB Documents
on:
push:
branches: [main]
paths:
- 'WP-Operations-Runbook.md'
- '.github/workflows/generate-docs.yml'
- '.github/pandoc/**'
workflow_dispatch:
permissions:
contents: write
concurrency:
group: generate-docs
cancel-in-progress: true
jobs:
generate-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Pandoc
run: |
PANDOC_VER=3.6.3
wget -q "https://github.com/jgm/pandoc/releases/download/${PANDOC_VER}/pandoc-${PANDOC_VER}-1-amd64.deb"
sudo dpkg -i "pandoc-${PANDOC_VER}-1-amd64.deb"
rm "pandoc-${PANDOC_VER}-1-amd64.deb"
- name: Install LaTeX and fonts
run: |
sudo apt-get update -qq
sudo apt-get install -y \
texlive-xetex \
texlive-latex-recommended \
texlive-fonts-recommended \
texlive-fonts-extra \
texlive-latex-extra \
lmodern \
fonts-noto-core \
fonts-noto-extra \
epubcheck \
poppler-utils
- name: Install eisvogel template
run: |
mkdir -p ~/.pandoc/templates
TMPDIR_EIS=$(mktemp -d)
curl -sL "https://github.com/Wandmalfarbe/pandoc-latex-template/releases/latest/download/Eisvogel.tar.gz" \
| tar -xz -C "$TMPDIR_EIS"
find "$TMPDIR_EIS" -name "*.latex" -exec cp {} ~/.pandoc/templates/ \;
rm -rf "$TMPDIR_EIS"
ls ~/.pandoc/templates/
- name: Bootstrap reference.docx
run: |
mkdir -p .github/pandoc
if [ ! -f .github/pandoc/reference.docx ]; then
pandoc --print-default-data-file reference.docx > .github/pandoc/reference.docx
echo "Created default reference.docx (customise via Word to restyle DOCX output)"
fi
- name: Update date in frontmatter
run: |
md_file="WP-Operations-Runbook.md"
today=$(date '+%B %-d, %Y')
if head -1 "$md_file" | grep -q '^---$'; then
sed -i "s/^date: .*/date: \"$today\"/" "$md_file"
echo " Updated date -> $today in $md_file"
fi
- name: Convert primary document
run: |
md_file="WP-Operations-Runbook.md"
base="${md_file%.md}"
docx_file="${base}.docx"
# Read version from YAML frontmatter
version=$(sed -n '/^---$/,/^---$/{ s/^version: *"\{0,1\}\([^"]*\)"\{0,1\}/\1/p }' "$md_file")
display_date="Version ${version} — $(date '+%B %-d, %Y')"
echo "▶ $md_file (${display_date})"
# 1) Markdown -> DOCX (intermediary template layer)
pandoc "$md_file" \
--reference-doc=".github/pandoc/reference.docx" \
--toc --toc-depth=3 \
-o "$docx_file"
echo " ✓ DOCX"
# 2) DOCX -> PDF
pandoc "$docx_file" \
--from docx \
--template eisvogel \
--pdf-engine xelatex \
--defaults ".github/pandoc/pdf-defaults.yaml" \
--metadata "date=${display_date}" \
--toc --toc-depth=3 \
-o "${base}.pdf"
echo " ✓ PDF"
# 3) DOCX -> EPUB
pandoc "$docx_file" \
--from docx \
--toc --toc-depth=3 \
--epub-title-page=false \
--metadata "lang=en-US" \
-o "${base}.epub"
echo " ✓ EPUB"
- name: Validate generated outputs
run: |
md_file="WP-Operations-Runbook.md"
base="${md_file%.md}"
for artifact in "${base}.docx" "${base}.pdf" "${base}.epub"; do
if [ ! -s "$artifact" ]; then
echo "Missing or empty artifact: $artifact"
exit 1
fi
done
echo "Running EPUB validation..."
epubcheck "${base}.epub"
echo "Running PDF validation..."
pdfinfo_out=$(pdfinfo "${base}.pdf")
echo "$pdfinfo_out"
echo "$pdfinfo_out" | grep -Eq '^Pages:[[:space:]]+[1-9][0-9]*$'
echo "$pdfinfo_out" | grep -Eq '^PDF version:[[:space:]]+[0-9.]+$'
- name: Commit generated documents
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add WP-Operations-Runbook.md WP-Operations-Runbook.pdf WP-Operations-Runbook.docx WP-Operations-Runbook.epub .github/pandoc/reference.docx 2>/dev/null || true
if ! git diff --staged --quiet; then
git commit -m "docs: regenerate PDF, Word, and EPUB documents [skip ci]"
git pull --rebase origin main
git push
else
echo "No changes to commit"
fi