-
Notifications
You must be signed in to change notification settings - Fork 23
133 lines (116 loc) · 3.92 KB
/
generate-pdf.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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: Build Jekyll site
run: |
bundle exec jekyll build
- 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="textbook_full.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"
echo "file://$PWD/$full_path"
if [ -f "$full_path" ]; then
echo "Generating PDF for $html_file"
google-chrome --headless --disable-gpu -no-pdf-header-footer --print-to-pdf="$output_pdf" "file://$PWD/$full_path"
else
echo "Error: File $full_path not found!" >&2
exit 1
fi
done
pdfunite "$output_folder"/*.pdf "$PWD/$combined_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 }}