modified scripts for github action

master
Martin Scheidt 2022-02-09 01:49:11 +01:00
parent 10408acab5
commit d762a9bc8e
4 changed files with 87 additions and 90 deletions

3
.github/texlive/requirements.txt vendored Normal file
View File

@ -0,0 +1,3 @@
tikz
xkeyval
etoolbox

View File

@ -34,7 +34,7 @@ jobs:
- name: "install tikz-trackschematic" - name: "install tikz-trackschematic"
run: | run: |
chmod +x dev-install.sh chmod +x dev-install.sh
./dev-install.sh --silent ./dev-install.sh -q
- name: "test tikz-trackschematic" - name: "test tikz-trackschematic"
run: | run: |

View File

@ -3,37 +3,27 @@
# Copyright (c) 2018 - 2022, Martin Scheidt (ISC license) # Copyright (c) 2018 - 2022, Martin Scheidt (ISC license)
# Permission to use, copy, modify, and/or distribute this file for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. # Permission to use, copy, modify, and/or distribute this file for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
## -- log functions
# Halt on error # Halt on error
set -e set -e
ECHO=`which echo` ## -- pass getopts
error_occured=0 usage() { echo "Usage: dev-install.sh [-q]"; }
exec 3>&2 # logging stream (file descriptor 3) defaults to STDERR verbose=1
verbosity=2 # default to show warnings
silent_lvl=0
err_lvl=1
wrn_lvl=2
inf_lvl=3
dbg_lvl=4
log_n() { log $silent_lvl "NOTE: $1"; } # Always prints while getopts ":q" opt; do
log_e() { log $err_lvl "ERROR: $1"; } case ${opt} in
log_w() { log $wrn_lvl "WARNING: $1"; } q ) verbose=0
log_i() { log $inf_lvl "INFO: $1"; } # "info" is already a command ;;
log_d() { log $dbg_lvl "DEBUG: $1"; } \? ) usage
log() { exit 1
if [ $verbosity -ge $1 ]; then ;;
# Expand escaped characters, wrap at 70 chars, indent wrapped lines esac
$ECHO "$2" | fold -w80 -s >&3 || true done
fi
$ECHO "$2" | fold -w80 -s >> $logfile || true
}
## -- commands ## -- commands
TEXlsr=`which mktexlsr` TEXlsr=`which mktexlsr`
check_texlive() { check_texlive() {
@ -41,12 +31,14 @@ check_texlive() {
status=0 status=0
command -v kpsewhich >/dev/null 2>&1 || status=1 command -v kpsewhich >/dev/null 2>&1 || status=1
if [ $status = 0 ]; then if [ $status = 0 ]; then
log_d "kpsewhich found" if [ "$verbose" -eq 1 ]; then
echo "kpsewhich found"
fi
return 0 return 0
fi fi
log_e "Program 'kpsewhich' not found." echo "Program 'kpsewhich' not found."
log_e "Be sure to use texlive or mactex!" echo "Be sure to use texlive or mactex!"
exit 1 exit 1
} }
@ -55,38 +47,43 @@ check_sudo() {
rootrun="" rootrun=""
# If we are root, we do note require sudo # If we are root, we do note require sudo
if [ "$EUID" = 0 ]; then if [ "$EUID" = 0 ]; then
log_d "you are root" if [ "$verbose" -eq 1 ]; then
echo "you are root"
fi
return 0 return 0
fi fi
if sudo -v >/dev/null 2>&1; then if sudo -v >/dev/null 2>&1; then
log_d "sudo ok" if [ "$verbose" -eq 1 ]; then
echo "sudo ok"
fi
rootrun="sudo" rootrun="sudo"
else else
log_d "sudo failed" echo "sudo failed"
# Check if user is root (might be unnecessary) # Check if user is root (might be unnecessary)
if ! [ $(id -u) = 0 ]; then if ! [ $(id -u) = 0 ]; then
log_e "This script must be run as root" 1>&2 echo "This script must be run as root" 1>&2
exit 1 exit 1
fi fi
fi fi
} }
#------------------------------------------------------------------------------- ## -- checking system
check_texlive check_texlive
check_sudo check_sudo
TEXMFLOCAL=$(kpsewhich --var-value TEXMFLOCAL) TEXMFLOCAL=$(kpsewhich --var-value TEXMFLOCAL)
DEVDIR="tikz-trackschematic-dev" DEVDIR="tex/latex/tikz-trackschematic-dev"
PROJECTDIR=$(pwd -P) PROJECTDIR=$(pwd -P)
if [ "$verbose" -eq 1 ]; then
echo "" echo ""
echo "Do you wish to link this package from" echo "Do you wish to link this package from"
echo "$PROJECTDIR/src to" echo "$PROJECTDIR/src to"
echo "$TEXMFLOCAL/tex/latex/$DEVDIR?" echo "$TEXMFLOCAL/$DEVDIR?"
echo "(y/n)" echo "(y/n)"
while true; do while true; do
read -p "" answer read -p "" answer
@ -96,20 +93,16 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
if [ ! -d "$TEXMFLOCAL/tex/latex/$DEVDIR" ]; then
$rootrun mkdir -p $TEXMFLOCAL/tex/latex/$DEVDIR
fi fi
## -- copying files
$rootrun ln -sfn $PROJECTDIR/src/tikz-trackschematic.sty $TEXMFLOCAL/tex/latex/$DEVDIR/tikz-trackschematic-dev.sty if [ ! -d "$TEXMFLOCAL/$DEVDIR" ]; then
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.code.tex $rootrun mkdir -p $TEXMFLOCAL/$DEVDIR
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.constructions.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.constructions.code.tex fi
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.electrics.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.electrics.code.tex
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.measures.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.measures.code.tex for SRC in src/*; do
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.topology.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.topology.code.tex $rootrun ln -sfn $PROJECTDIR/$SRC $TEXMFLOCAL/$DEVDIR/${SRC##*/}
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.trafficcontrol.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.trafficcontrol.code.tex done
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.vehicles.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.vehicles.code.tex
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.symbology.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.symbology.code.tex
$rootrun $TEXlsr --quiet $rootrun $TEXlsr --quiet

View File

@ -3,61 +3,56 @@
# Copyright (c) 2018 - 2022, Martin Scheidt (ISC license) # Copyright (c) 2018 - 2022, Martin Scheidt (ISC license)
# Permission to use, copy, modify, and/or distribute this file for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. # Permission to use, copy, modify, and/or distribute this file for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
## -- log functions
# Halt on error # Halt on error
set -e set -e
ECHO=`which echo` ## -- pass getopts
error_occured=0 usage() { echo "Usage: dev-install.sh [-q]"; }
exec 3>&2 # logging stream (file descriptor 3) defaults to STDERR verbose=1
verbosity=2 # default to show warnings
silent_lvl=0
err_lvl=1
wrn_lvl=2
inf_lvl=3
dbg_lvl=4
log_n() { log $silent_lvl "NOTE: $1"; } # Always prints while getopts ":q" opt; do
log_e() { log $err_lvl "ERROR: $1"; } case ${opt} in
log_w() { log $wrn_lvl "WARNING: $1"; } q ) verbose=0
log_i() { log $inf_lvl "INFO: $1"; } # "info" is already a command ;;
log_d() { log $dbg_lvl "DEBUG: $1"; } \? ) usage
log() { exit 1
if [ $verbosity -ge $1 ]; then ;;
# Expand escaped characters, wrap at 70 chars, indent wrapped lines esac
$ECHO "$2" | fold -w80 -s >&3 || true done
fi
$ECHO "$2" | fold -w80 -s >> $logfile || true
}
## -- commands ## -- commands
check_tex_distro() { check_tex_distro() {
# check for latexmk # check for latexmk
status=0 status=0
command -v pdflatex >/dev/null 2>&1 || status=1 command -v pdflatex >/dev/null 2>&1 || status=1
if [ $status = 0 ]; then if [ $status = 0 ]; then
log_d "pdflatex found" if [ "$verbose" -eq 1 ]; then
echo "pdflatex found"
fi
return 0 return 0
fi fi
log_e "Program 'pdflatex' not found." echo "Program 'pdflatex' not found."
log_e "Be sure to have texlive or mactex installed!" echo "Be sure to have texlive or mactex installed!"
exit 1 exit 1
} }
check_imagemagick() { check_imagemagick() {
# check for latexmk # check for ImageMagick
status=0 status=0
command -v compare >/dev/null 2>&1 || status=1 command -v compare >/dev/null 2>&1 || status=1
if [ $status = 0 ]; then if [ $status = 0 ]; then
log_d "compare found" if [ "$verbose" -eq 1 ]; then
echo "compare found"
fi
return 0 return 0
fi fi
log_e "Program 'compare' not found." echo "Program 'compare' not found."
log_e "Be sure to have imagemagick installed!" echo "Be sure to have imagemagick installed!"
exit 1 exit 1
} }
@ -69,10 +64,16 @@ check_imagemagick
mkdir -p .testing mkdir -p .testing
for TEST in $1*.tex; do for TEST in $1*.tex; do
if [ "$verbose" -eq 1 ]; then
echo "Testing: ${TEST%.*}" echo "Testing: ${TEST%.*}"
fi
pdflatex -output-directory=.testing -interaction=batchmode -halt-on-error $TEST 2>&1 > /dev/null pdflatex -output-directory=.testing -interaction=batchmode -halt-on-error $TEST 2>&1 > /dev/null
compare -metric DSSIM -colorspace RGB .testing/${TEST%.*}.pdf ${TEST%.*}_expected.pdf .testing/${TEST%.*}_diff.png compare -metric DSSIM -colorspace RGB .testing/${TEST%.*}.pdf ${TEST%.*}_expected.pdf .testing/${TEST%.*}_diff.png
if [ "$verbose" -eq 1 ]; then
echo "% difference" echo "% difference"
fi
done done
log_n "tests passed!" if [ "$verbose" -eq 1 ]; then
echo "tests passed!"
fi