Fix pdf compilation in workflow

This commit is contained in:
2023-11-17 10:51:45 +01:00
parent 02f75ae849
commit 5042f21539
5 changed files with 389 additions and 43 deletions

View File

@ -27,52 +27,17 @@ jobs:
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
ref: pdfs ref: pdfs
path: src/.compiled path: .compiled
- name: Copy basic files to pdfs branch - name: Copy basic files to pdfs branch
run: | run: |
cp README.md src/.compiled cp README.md .compiled
cp LICENSE src/.compiled cp LICENSE .compiled
- name: Compile - name: Compile
run: | run: |
shopt -s globstar bash ./compile.sh .compiled
cd src
work_dir=$(pwd)
[[ -f .compiled/.hash.cls ]] && old_class_hash="$(cat .compiled/.hash.cls)" || old_class_hash=''
curr_class_hash="$(git log -n 1 --format='%h' ./ainotes.cls)"
for f in **/[!_]*.tex; do
f_dir=$(dirname $f)
f_base=$(basename $f)
f_nameonly="${f_base%.*}"
[[ -f .compiled/${f_dir}/.hash ]] && old_hash="$(cat .compiled/${f_dir}/.hash)" || old_hash=''
curr_hash="$(git log -n 1 --format='%h' $f_dir)"
# Nothing to update
if [[ $old_hash == $curr_hash && $old_class_hash == $curr_class_hash ]]; then
continue
fi
# Update hash
echo "$curr_hash" > .compiled/${f_dir}/.hash
cd ${f_dir};
# Insert last update date
last_update=$(git log -1 --pretty="format:%ad" --date="format:%d %B %Y" .)
cp --remove-destination $(readlink ainotes.cls) ainotes.cls
sed -i "s/PLACEHOLDER-LAST-UPDATE/${last_update}/" ainotes.cls
latexmk -pdf -jobname=${f_nameonly} ${f_base}
mkdir -p .compiled/${f_dir}
mv ${f_nameonly}.pdf .compiled/${f_dir}/.
cd $work_dir
done
echo "$curr_class_hash" > .compiled/.hash.cls
- name: Move to pdfs branch - name: Move to pdfs branch
@ -80,7 +45,7 @@ jobs:
env: env:
REPO: self REPO: self
BRANCH: pdfs BRANCH: pdfs
FOLDER: src/.compiled FOLDER: .compiled
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_NAME: "github-actions[bot]" COMMIT_NAME: "github-actions[bot]"
COMMIT_EMAIL: "github-actions[bot]@users.noreply.github.com" COMMIT_EMAIL: "github-actions[bot]@users.noreply.github.com"

69
compile.sh Normal file
View File

@ -0,0 +1,69 @@
#! /bin/bash
#
# Commit based .tex compiling
#
if [ $# -eq 0 ]; then
echo "Missing output directory"
exit -1
fi
shopt -s globstar
out_dir=`realpath $1`
hash_file="$out_dir/.hash"
work_dir=`realpath src`
mkdir -p $out_dir
touch $hash_file
# $1: path of the directory
getDirLastHash () {
path="$1"
echo `awk -F"," "\\$1 == \"$path\" { print \\$2 } " $hash_file`
}
updateHashes() {
cd $work_dir
echo "ainotes.cls,`git log -n 1 --format='%h' ./ainotes.cls`" > $hash_file
for f in **/[!_]*.tex; do
f_dir=$(dirname $f)
echo "$f_dir,`git log -n 1 --format='%h' $f_dir`" >> $hash_file
done
}
cd $work_dir
old_class_hash=`getDirLastHash "ainotes.cls"`
curr_class_hash="$(git log -n 1 --format='%h' ./ainotes.cls)"
for f in **/[!_]*.tex; do
f_dir=$(dirname $f)
f_base=$(basename $f)
f_nameonly="${f_base%.*}"
old_hash=`getDirLastHash "$f_dir"`
curr_hash="$(git log -n 1 --format='%h' $f_dir)"
# Nothing to update
if [[ $old_hash == $curr_hash && $old_class_hash == $curr_class_hash ]]; then
echo "Skipping $f_dir"
continue
fi
cd ${f_dir};
# Insert last update date
last_update=$(git log -1 --pretty="format:%ad" --date="format:%d %B %Y" .)
cp --remove-destination $(readlink ainotes.cls) ainotes.cls
sed -i "s/PLACEHOLDER-LAST-UPDATE/${last_update}/" ainotes.cls
latexmk -pdf -jobname=${f_nameonly} ${f_base}
mkdir -p $out_dir/$f_dir
mv ${f_nameonly}.pdf $out_dir/${f_dir}/.
cd $work_dir
done
updateHashes

View File

@ -1 +0,0 @@
../../ainotes.cls

View File

@ -0,0 +1,105 @@
\NeedsTeXFormat{LaTeX2e}[]
\ProvidesClass{ainotes}
\LoadClass{scrreprt}
\usepackage{geometry}
\usepackage{graphicx, xcolor}
\usepackage{amsmath, amsfonts, amssymb, amsthm, mathtools, bm, upgreek, cancel}
\usepackage[pdfusetitle]{hyperref}
\usepackage[nameinlink]{cleveref}
\usepackage[all]{hypcap} % Links hyperref to object top and not caption
\usepackage[inline]{enumitem}
\usepackage{marginnote}
\usepackage[bottom]{footmisc}
\usepackage{scrlayer-scrpage}
\usepackage{scrhack, algorithm, listings}
\usepackage{array, makecell, multirow}
\usepackage{acro}
\usepackage{subcaption}
\usepackage{eurosym}
\usepackage{bussproofs} % Deductive tree
\geometry{ margin=3cm, lmargin=1.5cm, rmargin=4.5cm, marginparwidth=3cm }
\hypersetup{ colorlinks, citecolor=black, filecolor=black, linkcolor=black, urlcolor=black, linktoc=all }
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
commentstyle = \color{codegreen},
keywordstyle = \color{magenta},
numberstyle = \tiny\color{codegray},
stringstyle = \color{codepurple},
basicstyle = \footnotesize\ttfamily,
breakatwhitespace = false,
breaklines = true,
captionpos = b,
keepspaces = true,
numbers = none,
showspaces = false,
showstringspaces = true,
showtabs = false,
tabsize = 3
}
\lstset{style=mystyle}
\lstset{language=Python}
\NewDocumentEnvironment{descriptionlist}{}{%
\begin{description}[labelindent=1em]
}{
\end{description}%
}
\setlength{\parindent}{0pt}
\renewcommand*{\marginfont}{\color{gray}\footnotesize}
\renewcommand*\chapterpagestyle{scrheadings} % Header in chapter pages
\theoremstyle{definition}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem*{example}{Example}
\theoremstyle{definition}
\newtheorem*{definition}{Def}
\newcommand{\ubar}[1]{\text{\b{$#1$}}}
\renewcommand{\vec}[1]{{\bm{\mathbf{#1}}}}
\newcommand{\nullvec}[0]{\bar{\vec{0}}}
\newcommand{\matr}[1]{{\bm{#1}}}
\newcommand{\prob}[1]{{\mathcal{P}\left({#1}\right)}}
\renewcommand*{\maketitle}{%
\begin{titlepage}
\newgeometry{margin=3cm}
\centering
\vspace*{\fill}
\huge
\textbf{\@title}\\
{\Large Last update: {10 novembre 2023}}
\vspace*{\fill}
\Large
Academic Year \@date\\
Alma Mater Studiorum $\cdot$ University of Bologna
\vspace*{1cm}
\restoregeometry
\end{titlepage}
\newpage
}
\newcommand*{\makenotesfront}{%
\newgeometry{margin=3cm}
\maketitle
\pagenumbering{roman}
\tableofcontents
\restoregeometry
\newpage
\pagenumbering{arabic}
}
\newcommand{\eoc}[0]{\begin{flushright}\texttt{\raggedleft\small <end of course>}\end{flushright}}

View File

@ -1 +0,0 @@
../ainotes.cls

View File

@ -0,0 +1,105 @@
\NeedsTeXFormat{LaTeX2e}[]
\ProvidesClass{ainotes}
\LoadClass{scrreprt}
\usepackage{geometry}
\usepackage{graphicx, xcolor}
\usepackage{amsmath, amsfonts, amssymb, amsthm, mathtools, bm, upgreek, cancel}
\usepackage[pdfusetitle]{hyperref}
\usepackage[nameinlink]{cleveref}
\usepackage[all]{hypcap} % Links hyperref to object top and not caption
\usepackage[inline]{enumitem}
\usepackage{marginnote}
\usepackage[bottom]{footmisc}
\usepackage{scrlayer-scrpage}
\usepackage{scrhack, algorithm, listings}
\usepackage{array, makecell, multirow}
\usepackage{acro}
\usepackage{subcaption}
\usepackage{eurosym}
\usepackage{bussproofs} % Deductive tree
\geometry{ margin=3cm, lmargin=1.5cm, rmargin=4.5cm, marginparwidth=3cm }
\hypersetup{ colorlinks, citecolor=black, filecolor=black, linkcolor=black, urlcolor=black, linktoc=all }
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
commentstyle = \color{codegreen},
keywordstyle = \color{magenta},
numberstyle = \tiny\color{codegray},
stringstyle = \color{codepurple},
basicstyle = \footnotesize\ttfamily,
breakatwhitespace = false,
breaklines = true,
captionpos = b,
keepspaces = true,
numbers = none,
showspaces = false,
showstringspaces = true,
showtabs = false,
tabsize = 3
}
\lstset{style=mystyle}
\lstset{language=Python}
\NewDocumentEnvironment{descriptionlist}{}{%
\begin{description}[labelindent=1em]
}{
\end{description}%
}
\setlength{\parindent}{0pt}
\renewcommand*{\marginfont}{\color{gray}\footnotesize}
\renewcommand*\chapterpagestyle{scrheadings} % Header in chapter pages
\theoremstyle{definition}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem*{example}{Example}
\theoremstyle{definition}
\newtheorem*{definition}{Def}
\newcommand{\ubar}[1]{\text{\b{$#1$}}}
\renewcommand{\vec}[1]{{\bm{\mathbf{#1}}}}
\newcommand{\nullvec}[0]{\bar{\vec{0}}}
\newcommand{\matr}[1]{{\bm{#1}}}
\newcommand{\prob}[1]{{\mathcal{P}\left({#1}\right)}}
\renewcommand*{\maketitle}{%
\begin{titlepage}
\newgeometry{margin=3cm}
\centering
\vspace*{\fill}
\huge
\textbf{\@title}\\
{\Large Last update: {12 novembre 2023}}
\vspace*{\fill}
\Large
Academic Year \@date\\
Alma Mater Studiorum $\cdot$ University of Bologna
\vspace*{1cm}
\restoregeometry
\end{titlepage}
\newpage
}
\newcommand*{\makenotesfront}{%
\newgeometry{margin=3cm}
\maketitle
\pagenumbering{roman}
\tableofcontents
\restoregeometry
\newpage
\pagenumbering{arabic}
}
\newcommand{\eoc}[0]{\begin{flushright}\texttt{\raggedleft\small <end of course>}\end{flushright}}

View File

@ -1 +0,0 @@
../ainotes.cls

View File

@ -0,0 +1,105 @@
\NeedsTeXFormat{LaTeX2e}[]
\ProvidesClass{ainotes}
\LoadClass{scrreprt}
\usepackage{geometry}
\usepackage{graphicx, xcolor}
\usepackage{amsmath, amsfonts, amssymb, amsthm, mathtools, bm, upgreek, cancel}
\usepackage[pdfusetitle]{hyperref}
\usepackage[nameinlink]{cleveref}
\usepackage[all]{hypcap} % Links hyperref to object top and not caption
\usepackage[inline]{enumitem}
\usepackage{marginnote}
\usepackage[bottom]{footmisc}
\usepackage{scrlayer-scrpage}
\usepackage{scrhack, algorithm, listings}
\usepackage{array, makecell, multirow}
\usepackage{acro}
\usepackage{subcaption}
\usepackage{eurosym}
\usepackage{bussproofs} % Deductive tree
\geometry{ margin=3cm, lmargin=1.5cm, rmargin=4.5cm, marginparwidth=3cm }
\hypersetup{ colorlinks, citecolor=black, filecolor=black, linkcolor=black, urlcolor=black, linktoc=all }
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
commentstyle = \color{codegreen},
keywordstyle = \color{magenta},
numberstyle = \tiny\color{codegray},
stringstyle = \color{codepurple},
basicstyle = \footnotesize\ttfamily,
breakatwhitespace = false,
breaklines = true,
captionpos = b,
keepspaces = true,
numbers = none,
showspaces = false,
showstringspaces = true,
showtabs = false,
tabsize = 3
}
\lstset{style=mystyle}
\lstset{language=Python}
\NewDocumentEnvironment{descriptionlist}{}{%
\begin{description}[labelindent=1em]
}{
\end{description}%
}
\setlength{\parindent}{0pt}
\renewcommand*{\marginfont}{\color{gray}\footnotesize}
\renewcommand*\chapterpagestyle{scrheadings} % Header in chapter pages
\theoremstyle{definition}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem*{example}{Example}
\theoremstyle{definition}
\newtheorem*{definition}{Def}
\newcommand{\ubar}[1]{\text{\b{$#1$}}}
\renewcommand{\vec}[1]{{\bm{\mathbf{#1}}}}
\newcommand{\nullvec}[0]{\bar{\vec{0}}}
\newcommand{\matr}[1]{{\bm{#1}}}
\newcommand{\prob}[1]{{\mathcal{P}\left({#1}\right)}}
\renewcommand*{\maketitle}{%
\begin{titlepage}
\newgeometry{margin=3cm}
\centering
\vspace*{\fill}
\huge
\textbf{\@title}\\
{\Large Last update: {18 ottobre 2023}}
\vspace*{\fill}
\Large
Academic Year \@date\\
Alma Mater Studiorum $\cdot$ University of Bologna
\vspace*{1cm}
\restoregeometry
\end{titlepage}
\newpage
}
\newcommand*{\makenotesfront}{%
\newgeometry{margin=3cm}
\maketitle
\pagenumbering{roman}
\tableofcontents
\restoregeometry
\newpage
\pagenumbering{arabic}
}
\newcommand{\eoc}[0]{\begin{flushright}\texttt{\raggedleft\small <end of course>}\end{flushright}}