From 2880c91f7c3d1ef6a40ceb10176894ec09bc87a2 Mon Sep 17 00:00:00 2001 From: NotXia <35894453+NotXia@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:55:55 +0100 Subject: [PATCH] Update compilation workflow --- .github/workflows/compile.yml | 21 ++++++++++----------- compile.sh | 15 ++++++++++----- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 98caf53..9b950dc 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -17,29 +17,28 @@ jobs: with: fetch-depth: 0 + - name: Checkout current pdfs branch + uses: actions/checkout@v3 + with: + ref: pdfs + path: .currpdfs + + - name: Install LaTeX run: | sudo apt update sudo apt install -y latexmk texlive texlive-science texlive-latex-extra - - name: Checkout old pdfs - uses: actions/checkout@v3 - with: - ref: pdfs - path: .compiled - - - name: Copy basic files to pdfs branch + - name: Prepare output directory run: | + mkdir .compiled cp README.md .compiled cp LICENSE .compiled - - name: Compile run: | - export LANG="en_GB.UTF-8" - export LC_ALL="en_GB.UTF-8" - bash ./compile.sh .compiled + bash ./compile.sh .compiled .currpdfs - name: Move to pdfs branch diff --git a/compile.sh b/compile.sh index af156d2..e1f9cb8 100644 --- a/compile.sh +++ b/compile.sh @@ -2,6 +2,8 @@ # # Commit based .tex compiling +# $1 is the output directory. +# $2 is the directory of the current state of the files. # if [ $# -eq 0 ]; then @@ -12,7 +14,9 @@ fi shopt -s globstar out_dir=`realpath $1` -hash_file="$out_dir/.hash" +old_out_dir=`realpath $2` +hash_file="$old_out_dir/.hash" +new_hash_file="$out_dir/.hash" work_dir=`realpath src` mkdir -p $out_dir @@ -26,10 +30,10 @@ getDirLastHash () { updateHashes() { cd $work_dir - echo "ainotes.cls,`git log -n 1 --format='%h' ./ainotes.cls`" > $hash_file + echo "ainotes.cls,`git log -n 1 --format='%h' ./ainotes.cls`" > $new_hash_file for f in **/[!_]*.tex; do f_dir=$(dirname $f) - echo "$f_dir,`git log -n 1 --format='%h' $f_dir`" >> $hash_file + echo "$f_dir,`git log -n 1 --format='%h' $f_dir`" >> $new_hash_file done } @@ -46,13 +50,15 @@ for f in **/[!_]*.tex; do old_hash=`getDirLastHash "$f_dir"` curr_hash="$(git log -n 1 --format='%h' $f_dir)" + mkdir -p $out_dir/$f_dir + # Nothing to update if [[ $old_hash == $curr_hash && $old_class_hash == $curr_class_hash ]]; then echo "Skipping $f_dir" + cp -r $old_out_dir/$f_dir/. $out_dir/$f_dir continue fi - cd ${f_dir}; # Insert last update date @@ -61,7 +67,6 @@ for f in **/[!_]*.tex; do 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