[feat] add action to generate pdf of textbook #42
Workflow file for this run
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 | |
run: sudo apt-get install -y pandoc texlive texlive-latex-extra poppler-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=( | |
"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" | |
"glossary.md" | |
) | |
for md_file in "${file_list[@]}"; do | |
pdf_file_name="pdf_output/$(echo "$md_file" | sed 's/\//_/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/network_index.md.pdf" \ | |
"pdf_output/network_intro.md.pdf" \ | |
"pdf_output/network_arp.md.pdf" \ | |
"pdf_output/network_dhcp.md.pdf" \ | |
"pdf_output/network_wpa.md.pdf" \ | |
"pdf_output/network_bgp.md.pdf" \ | |
"pdf_output/network_transport.md.pdf" \ | |
"pdf_output/network_tls.md.pdf" \ | |
"pdf_output/network_dns.md.pdf" \ | |
"pdf_output/network_dnssec.md.pdf" \ | |
"pdf_output/network_dos.md.pdf" \ | |
"pdf_output/network_firewalls.md.pdf" \ | |
"pdf_output/network_intrusion-detection.md.pdf" \ | |
"pdf_output/network_abusing-intrusion-detection.md.pdf" \ | |
"pdf_output/network_malware.md.pdf" \ | |
"pdf_output/network_tor.md.pdf" \ | |
"pdf_output/glossary.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 }} |