[feat] add action to generate pdf of textbook (#85) #54
This file contains 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: 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, Latex necessities | |
run: sudo apt-get install -y pandoc texlive texlive-latex-extra poppler-utils texlive-extra-utils | |
- name: Install Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: Generate PDFs from the textbook Markdown files | |
run: | | |
mkdir -p pdf_output | |
file_list=( | |
"index.md" | |
"principles/index.md" | |
"principles/principles.md" | |
"memory-safety/index.md" | |
"memory-safety/x86.md" | |
"memory-safety/vulnerabilities.md" | |
"memory-safety/mitigations.md" | |
"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" | |
"web/index.md" | |
"web/sqli.md" | |
"web/intro.md" | |
"web/sop.md" | |
"web/cookies.md" | |
"web/csrf.md" | |
"web/xss.md" | |
"web/ui-attacks.md" | |
"web/captchas.md" | |
"network/index.md" | |
"network/intro.md" | |
"network/arp.md" | |
"network/dhcp.md" | |
"network/wpa.md" | |
"network/bgp.md" | |
"network/transport.md" | |
"network/tls.md" | |
"network/dns.md" | |
"network/dnssec.md" | |
"network/dos.md" | |
"network/firewalls.md" | |
"network/intrusion-detection.md" | |
"network/abusing-intrusion-detection.md" | |
"network/malware.md" | |
"network/tor.md" | |
) | |
for md_file in "${file_list[@]}"; do | |
pdf_file_name="pdf_output/$(echo "$md_file" | sed 's/\//_/g' | sed 's/.md//g').pdf" | |
python3 generate-pdf-edits.py "$md_file" | pandoc -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/index.pdf" \ | |
"pdf_output/principles_index.pdf" \ | |
"pdf_output/principles_principles.pdf" \ | |
"pdf_output/memory-safety_index.pdf" \ | |
"pdf_output/memory-safety_x86.pdf" \ | |
"pdf_output/memory-safety_vulnerabilities.pdf" \ | |
"pdf_output/memory-safety_mitigations.pdf" \ | |
"pdf_output/crypto_index.pdf" \ | |
"pdf_output/crypto_intro.pdf" \ | |
"pdf_output/crypto_symmetric.pdf" \ | |
"pdf_output/crypto_hashes.pdf" \ | |
"pdf_output/crypto_macs.pdf" \ | |
"pdf_output/crypto_prng.pdf" \ | |
"pdf_output/crypto_key-exchange.pdf" \ | |
"pdf_output/crypto_public-key.pdf" \ | |
"pdf_output/crypto_signatures.pdf" \ | |
"pdf_output/crypto_certificates.pdf" \ | |
"pdf_output/crypto_passwords.pdf" \ | |
"pdf_output/crypto_case-studies.pdf" \ | |
"pdf_output/crypto_bitcoin.pdf" \ | |
"pdf_output/web_index.pdf" \ | |
"pdf_output/web_sqli.pdf" \ | |
"pdf_output/web_intro.pdf" \ | |
"pdf_output/web_sop.pdf" \ | |
"pdf_output/web_cookies.pdf" \ | |
"pdf_output/web_csrf.pdf" \ | |
"pdf_output/web_xss.pdf" \ | |
"pdf_output/web_ui-attacks.pdf" \ | |
"pdf_output/web_captchas.pdf" \ | |
"pdf_output/network_index.pdf" \ | |
"pdf_output/network_intro.pdf" \ | |
"pdf_output/network_arp.pdf" \ | |
"pdf_output/network_dhcp.pdf" \ | |
"pdf_output/network_wpa.pdf" \ | |
"pdf_output/network_bgp.pdf" \ | |
"pdf_output/network_transport.pdf" \ | |
"pdf_output/network_tls.pdf" \ | |
"pdf_output/network_dns.pdf" \ | |
"pdf_output/network_dnssec.pdf" \ | |
"pdf_output/network_dos.pdf" \ | |
"pdf_output/network_firewalls.pdf" \ | |
"pdf_output/network_intrusion-detection.pdf" \ | |
"pdf_output/network_abusing-intrusion-detection.pdf" \ | |
"pdf_output/network_malware.pdf" \ | |
"pdf_output/network_tor.pdf" \ | |
"textbook_full_tmp.pdf" | |
- name: Inject page numbers back into the pdf | |
run: pdfjam --pagecommand '\pagestyle{plain}' --outfile textbook_full.pdf textbook_full_tmp.pdf | |
- name: Upload PDF as an artifact | |
uses: actions/upload-artifact@v4 | |
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 }} |