Skip to content

[feat] add action to generate pdf of textbook #31

[feat] add action to generate pdf of textbook

[feat] add action to generate pdf of textbook #31

Workflow file for this run

name: Generate PDF for Textbook
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build_and_generate_pdf:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Pandoc
run: sudo apt-get install -y pandoc texlive texlive-latex-extra poppler-utils
- name: Generate PDFs from the textbook Markdown files
run: |
mkdir -p pdf_output
file_list=(
"crypto/index.md"
"crypto/intro.md"
"crypto/symmetric.md"
"crypto/hashes.md"
"crypto/macs.md"
"crypto/prng.md"
"crypto/key-exchange.md"
"crypto/public-key.md"
"crypto/signatures.md"
"crypto/certificates.md"
"crypto/passwords.md"
"crypto/case-studies.md"
"crypto/bitcoin.md"
)
for md_file in "${file_list[@]}"; do
pdf_file_name="pdf_output/$(echo "$md_file" | sed 's/\//_/g').pdf"
pandoc "$md_file" -V geometry:margin=1in --pdf-engine=pdflatex -o "$pdf_file_name"
if [ ! -f "$pdf_file_name" ]; then
echo "Error: PDF file $pdf_file_name not created!" >&2
exit 1
fi
done
pdfunite \
"pdf_output/crypto_index.md.pdf" \
"pdf_output/crypto_intro.md.pdf" \
"pdf_output/crypto_symmetric.md.pdf" \
"pdf_output/crypto_hashes.md.pdf" \
"pdf_output/crypto_macs.md.pdf" \
"pdf_output/crypto_prng.md.pdf" \
"pdf_output/crypto_key-exchange.md.pdf" \
"pdf_output/crypto_public-key.md.pdf" \
"pdf_output/crypto_signatures.md.pdf" \
"pdf_output/crypto_certificates.md.pdf" \
"pdf_output/crypto_passwords.md.pdf" \
"pdf_output/crypto_case-studies.md.pdf" \
"pdf_output/crypto_bitcoin.md.pdf" \
"textbook_full.pdf"
- name: Upload PDF to site
uses: actions/upload-artifact@v3
with:
name: textbook-full
path: textbook_full.pdf
- name: Commit and push changes only on push
if: github.event_name == 'push'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "GitHub Actions"
git add textbook_full.pdf
git commit -m "Update full PDF of textbook on site"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}