-
Notifications
You must be signed in to change notification settings - Fork 23
86 lines (76 loc) · 2.7 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
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=(
"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"
)
for md_file in "${file_list[@]}"; do
pdf_file_name="pdf_output/$(echo "$md_file" | sed 's/\//_/g').pdf"
python3 fix-image-paths.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/crypto_index.md.pdf" \
"pdf_output/crypto_intro.md.pdf" \
"pdf_output/crypto_symmetric.md.pdf" \
"pdf_output/crypto_hashes.md.pdf" \
"pdf_output/crypto_macs.md.pdf" \
"pdf_output/crypto_prng.md.pdf" \
"pdf_output/crypto_key-exchange.md.pdf" \
"pdf_output/crypto_public-key.md.pdf" \
"pdf_output/crypto_signatures.md.pdf" \
"pdf_output/crypto_certificates.md.pdf" \
"pdf_output/crypto_passwords.md.pdf" \
"pdf_output/crypto_case-studies.md.pdf" \
"pdf_output/crypto_bitcoin.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 }}