[feat] add action to generate pdf of textbook #2
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: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: 3.1 | |
bundler-cache: true | |
- name: Install Jekyll dependencies | |
run: | | |
bundle install | |
- name: Install Google Chrome | |
run: | | |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb | |
sudo apt-get update | |
sudo apt-get install -y ./google-chrome-stable_current_amd64.deb | |
rm google-chrome-stable_current_amd64.deb | |
- name: Install PDF tools (poppler for pdfunite) | |
run: | | |
sudo apt-get install -y poppler-utils | |
- name: Convert HTML to PDF and merge them | |
run: | | |
site_folder="_site" | |
output_folder="pdf_output" | |
combined_pdf="combined_output.pdf" | |
mkdir -p "$output_folder" | |
file_list=( | |
"index.html" | |
"principles/index.html" | |
"principles/principles.html" | |
"memory-safety/index.html" | |
"memory-safety/x86.html" | |
"memory-safety/vulnerabilities.html" | |
"memory-safety/mitigations.html" | |
"crypto/index.html" | |
"crypto/intro.html" | |
"crypto/symmetric.html" | |
"crypto/hashes.html" | |
"crypto/macs.html" | |
"crypto/prng.html" | |
"crypto/key-exchange.html" | |
"crypto/public-key.html" | |
"crypto/signatures.html" | |
"crypto/certificates.html" | |
"crypto/passwords.html" | |
"crypto/case-studies.html" | |
"crypto/bitcoin.html" | |
"web/index.html" | |
"web/sqli.html" | |
"web/intro.html" | |
"web/sop.html" | |
"web/cookies.html" | |
"web/csrf.html" | |
"web/xss.html" | |
"web/ui-attacks.html" | |
"web/captchas.html" | |
"network/index.html" | |
"network/intro.html" | |
"network/arp.html" | |
"network/dhcp.html" | |
"network/wpa.html" | |
"network/bgp.html" | |
"network/transport.html" | |
"network/tls.html" | |
"network/dns.html" | |
"network/dnssec.html" | |
"network/dos.html" | |
"network/firewalls.html" | |
"network/intrusion-detection.html" | |
"network/abusing-instrusion-detection.html" | |
"network/malware.html" | |
"network/tor.html" | |
"glossary.html" | |
) | |
for html_file in "${file_list[@]}"; do | |
full_path="$site_folder/$html_file" | |
output_pdf="$output_folder/$(basename "$html_file" .html).pdf" | |
google-chrome --headless --disable-gpu --disable-software-rasterizer --no-sandbox --no-pdf-header-footer --print-to-pdf="$output_pdf" "file://$PWD/$full_path" | |
done | |
pdfunite "$output_folder"/*.pdf "$site_folder/$combined_pdf" | |
- name: Upload PDF to site | |
uses: actions/upload-artifact@v3 | |
with: | |
name: site-pdf | |
path: _site/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 _site/index.html _site/combined_output.pdf | |
git commit -m "Update PDF document on site" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |