-
Notifications
You must be signed in to change notification settings - Fork 23
164 lines (153 loc) · 6 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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 changes to a new branch
if: github.event_name == 'push' && !contains(github.event.head_commit.message, 'Update PDF of textbook')
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "GitHub Actions"
git checkout -b update-textbook-full-pdf-$(date +%s)
git add textbook_full.pdf
git commit -m "Update PDF of textbook on site after a merge to main"
git push origin HEAD
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create a Pull Request
if: github.event_name == 'push' && !contains(github.event.head_commit.message, 'Update PDF of textbook')
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update PDF of textbook on site"
branch: update-textbook-full-pdf-$(date +%s)
title: "Update full PDF of textbook"
body: "This PR updates the full PDF of the textbook."
base: main