Skip to content

Update PDF of textbook on site after a merge to main #40

Update PDF of textbook on site after a merge to main

Update PDF of textbook on site after a merge to main #40

Workflow file for this run

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, and pdftk
run: |
sudo apt-get install -y pandoc texlive texlive-latex-extra poppler-utils texlive-extra-utils pdftk
- 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"
"search/index.md"
"search/agents.md"
"search/state.md"
"search/uninformed.md"
"search/informed.md"
"search/local.md"
"search/summary.md"
"csp/index.md"
"csp/csps.md"
"csp/solving.md"
"csp/filtering.md"
"csp/ordering.md"
"csp/local-search.md"
"csp/summary.md"
"games/index.md"
"games/games.md"
"games/minimax.md"
"games/expectimax.md"
"games/general.md"
"games/monte-carlo.md"
"games/summary.md"
"mdp/index.md"
"mdp/markov-decision-processes.md"
"mdp/solve.md"
"mdp/value-iteration.md"
"mdp/policies-iteration.md"
"mdp/summary.md"
"rl/index.md"
"rl/rl.md"
"rl/mbl.md"
"rl/mfl.md"
"rl/eae.md"
"rl/summary.md"
"bayes-nets/index.md"
"bayes-nets/probability.md"
"bayes-nets/inference.md"
"bayes-nets/representation.md"
"bayes-nets/structure.md"
"bayes-nets/d-separation.md"
"bayes-nets/elimination.md"
"bayes-nets/approximate.md"
"bayes-nets/summary.md"
"vpis/index.md"
"vpis/utilities.md"
"vpis/decision-networks.md"
"vpis/vpi.md"
"hmms/index.md"
"hmms/markov.md"
"hmms/hmm.md"
"hmms/viterbi.md"
"hmms/particle-filtering.md"
"hmms/summary.md"
"ml/index.md"
"ml/machine-learning.md"
"ml/naive-bayes.md"
"ml/perceptrons.md"
"ml/binary.md"
"ml/linear-regression.md"
"ml/optimization.md"
"ml/logistic.md"
"ml/multi-class-logistic.md"
"ml/motivation.md"
"logic/index.md"
"logic/knowledge.md"
"logic/language.md"
"logic/propositional.md"
"logic/inference.md"
"logic/theorem.md"
"logic/forward.md"
"logic/first-order-logic.md"
"logic/first-order-logical-inference.md"
"logic/logical-agents.md"
"logic/summary.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 pdf-generation/generate-pdf-edits.py "$md_file" | pandoc -V geometry:margin=1in -V colorlinks=true -V linkcolor=blue -V urlcolor=blue --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
echo "Completed making PDF files"
pdftk \
"pdf_output/index.pdf" \
"pdf_output/search_index.pdf" \
"pdf_output/search_agents.pdf" \
"pdf_output/search_state.pdf" \
"pdf_output/search_uninformed.pdf" \
"pdf_output/search_informed.pdf" \
"pdf_output/search_local.pdf" \
"pdf_output/search_summary.pdf" \
"pdf_output/csp_index.pdf" \
"pdf_output/csp_csps.pdf" \
"pdf_output/csp_solving.pdf" \
"pdf_output/csp_filtering.pdf" \
"pdf_output/csp_ordering.pdf" \
"pdf_output/csp_local-search.pdf" \
"pdf_output/csp_summary.pdf" \
"pdf_output/games_index.pdf" \
"pdf_output/games_games.pdf" \
"pdf_output/games_minimax.pdf" \
"pdf_output/games_expectimax.pdf" \
"pdf_output/games_general.pdf" \
"pdf_output/games_monte-carlo.pdf" \
"pdf_output/games_summary.pdf" \
"pdf_output/mdp_index.pdf" \
"pdf_output/mdp_markov-decision-processes.pdf" \
"pdf_output/mdp_solve.pdf" \
"pdf_output/mdp_value-iteration.pdf" \
"pdf_output/mdp_policies-iteration.pdf" \
"pdf_output/mdp_summary.pdf" \
"pdf_output/rl_index.pdf" \
"pdf_output/rl_rl.pdf" \
"pdf_output/rl_mbl.pdf" \
"pdf_output/rl_mfl.pdf" \
"pdf_output/rl_eae.pdf" \
"pdf_output/rl_summary.pdf" \
"pdf_output/bayes-nets_index.pdf" \
"pdf_output/bayes-nets_probability.pdf" \
"pdf_output/bayes-nets_inference.pdf" \
"pdf_output/bayes-nets_representation.pdf" \
"pdf_output/bayes-nets_structure.pdf" \
"pdf_output/bayes-nets_d-separation.pdf" \
"pdf_output/bayes-nets_elimination.pdf" \
"pdf_output/bayes-nets_approximate.pdf" \
"pdf_output/bayes-nets_summary.pdf" \
"pdf_output/vpis_index.pdf" \
"pdf_output/vpis_utilities.pdf" \
"pdf_output/vpis_decision-networks.pdf" \
"pdf_output/vpis_vpi.pdf" \
"pdf_output/hmms_index.pdf" \
"pdf_output/hmms_markov.pdf" \
"pdf_output/hmms_hmm.pdf" \
"pdf_output/hmms_viterbi.pdf" \
"pdf_output/hmms_particle-filtering.pdf" \
"pdf_output/hmms_summary.pdf" \
"pdf_output/ml_index.pdf" \
"pdf_output/ml_machine-learning.pdf" \
"pdf_output/ml_naive-bayes.pdf" \
"pdf_output/ml_perceptrons.pdf" \
"pdf_output/ml_binary.pdf" \
"pdf_output/ml_linear-regression.pdf" \
"pdf_output/ml_optimization.pdf" \
"pdf_output/ml_logistic.pdf" \
"pdf_output/ml_multi-class-logistic.pdf" \
"pdf_output/ml_motivation.pdf" \
"pdf_output/logic_index.pdf" \
"pdf_output/logic_knowledge.pdf" \
"pdf_output/logic_language.pdf" \
"pdf_output/logic_propositional.pdf" \
"pdf_output/logic_inference.pdf" \
"pdf_output/logic_theorem.pdf" \
"pdf_output/logic_forward.pdf" \
"pdf_output/logic_first-order-logic.pdf" \
"pdf_output/logic_first-order-logical-inference.pdf" \
"pdf_output/logic_logical-agents.pdf" \
"pdf_output/logic_summary.pdf" \
cat output "textbook_full_original.pdf"
- name: Inject page numbers back into the pdf
run: |
mkdir -p pdf_numbering_output
num_pages=$(pdftk textbook_full_original.pdf dump_data | grep NumberOfPages | awk '{print $2}')
sed -i "s/161/$num_pages/" pdf-generation/numbering.tex
# Don't continue if the sed failed
if [ $? -ne 0 ]; then
echo "Error: sed command failed" >&2
exit 1
fi
pdflatex pdf-generation/numbering.tex
pdftk numbering.pdf burst output pdf_numbering_output/number_%03d.pdf
pdftk textbook_full_original.pdf burst output pdf_numbering_output/page_%03d.pdf
for i in $(seq -f %03g 1 $num_pages) ; do pdftk pdf_numbering_output/page_$i.pdf background pdf_numbering_output/number_$i.pdf output pdf_numbering_output/new_$i.pdf; done
pdftk pdf_numbering_output/new_???.pdf output textbook_full.pdf
cp textbook_full.pdf textbook_full_cpy.pdf
sed -i "s/$num_pages/161/" pdf-generation/numbering.tex
- name: Upload PDF as an artifact
uses: actions/upload-artifact@v4
with:
name: textbook-full-copy
path: textbook_full_cpy.pdf
- name: Remove temporary files
run: |
rm -rf pdf_output
rm -rf pdf_numbering_output
rm textbook_full_original.pdf
rm textbook_full_cpy.pdf
rm numbering.pdf
rm numbering.aux
- name: Check if PDF files are created
run: |
if [ -f "textbook_full.pdf" ]; then echo "textbook_full.pdf here"; else echo "textbook_full.pdf gone"; fi
- name: Check git status
run: git status
- name: Check git diff
run: git diff --stat
- 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
git add -f textbook_full.pdf
git commit -m "Update PDF of textbook on site after a merge to main"
git push -f origin update-textbook-full-pdf
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check git log on update-textbook-full-pdf branch
if: github.event_name == 'push' && !contains(github.event.head_commit.message, 'Update PDF of textbook')
run: |
git checkout update-textbook-full-pdf
git log