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"
run: |
chmod +x dev-install.sh
./dev-install.sh --silent
./dev-install.sh -q
- name: "test tikz-trackschematic"
run: |

View File

@ -3,37 +3,27 @@
# 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.
## -- log functions
# Halt on error
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
verbosity=2 # default to show warnings
silent_lvl=0
err_lvl=1
wrn_lvl=2
inf_lvl=3
dbg_lvl=4
verbose=1
log_n() { log $silent_lvl "NOTE: $1"; } # Always prints
log_e() { log $err_lvl "ERROR: $1"; }
log_w() { log $wrn_lvl "WARNING: $1"; }
log_i() { log $inf_lvl "INFO: $1"; } # "info" is already a command
log_d() { log $dbg_lvl "DEBUG: $1"; }
log() {
if [ $verbosity -ge $1 ]; then
# Expand escaped characters, wrap at 70 chars, indent wrapped lines
$ECHO "$2" | fold -w80 -s >&3 || true
fi
$ECHO "$2" | fold -w80 -s >> $logfile || true
}
while getopts ":q" opt; do
case ${opt} in
q ) verbose=0
;;
\? ) usage
exit 1
;;
esac
done
## -- commands
TEXlsr=`which mktexlsr`
check_texlive() {
@ -41,12 +31,14 @@ check_texlive() {
status=0
command -v kpsewhich >/dev/null 2>&1 || status=1
if [ $status = 0 ]; then
log_d "kpsewhich found"
if [ "$verbose" -eq 1 ]; then
echo "kpsewhich found"
fi
return 0
fi
log_e "Program 'kpsewhich' not found."
log_e "Be sure to use texlive or mactex!"
echo "Program 'kpsewhich' not found."
echo "Be sure to use texlive or mactex!"
exit 1
}
@ -55,61 +47,62 @@ check_sudo() {
rootrun=""
# If we are root, we do note require sudo
if [ "$EUID" = 0 ]; then
log_d "you are root"
if [ "$verbose" -eq 1 ]; then
echo "you are root"
fi
return 0
fi
if sudo -v >/dev/null 2>&1; then
log_d "sudo ok"
if [ "$verbose" -eq 1 ]; then
echo "sudo ok"
fi
rootrun="sudo"
else
log_d "sudo failed"
echo "sudo failed"
# Check if user is root (might be unnecessary)
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
fi
fi
}
#-------------------------------------------------------------------------------
## -- checking system
check_texlive
check_sudo
TEXMFLOCAL=$(kpsewhich --var-value TEXMFLOCAL)
DEVDIR="tikz-trackschematic-dev"
DEVDIR="tex/latex/tikz-trackschematic-dev"
PROJECTDIR=$(pwd -P)
echo ""
echo "Do you wish to link this package from"
echo "$PROJECTDIR/src to"
echo "$TEXMFLOCAL/tex/latex/$DEVDIR?"
echo "(y/n)"
while true; do
read -p "" answer
case $answer in
[Yy]* ) break;;
[Nn]* ) exit 1;;
* ) echo "Please answer yes or no.";;
esac
done
if [ ! -d "$TEXMFLOCAL/tex/latex/$DEVDIR" ]; then
$rootrun mkdir -p $TEXMFLOCAL/tex/latex/$DEVDIR
if [ "$verbose" -eq 1 ]; then
echo ""
echo "Do you wish to link this package from"
echo "$PROJECTDIR/src to"
echo "$TEXMFLOCAL/$DEVDIR?"
echo "(y/n)"
while true; do
read -p "" answer
case $answer in
[Yy]* ) break;;
[Nn]* ) exit 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
## -- copying files
$rootrun ln -sfn $PROJECTDIR/src/tikz-trackschematic.sty $TEXMFLOCAL/tex/latex/$DEVDIR/tikz-trackschematic-dev.sty
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.code.tex
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.constructions.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.constructions.code.tex
$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
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.topology.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.topology.code.tex
$rootrun ln -sfn $PROJECTDIR/src/tikzlibrarytrackschematic.trafficcontrol.code.tex $TEXMFLOCAL/tex/latex/$DEVDIR/tikzlibrarytrackschematic-dev.trafficcontrol.code.tex
$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
if [ ! -d "$TEXMFLOCAL/$DEVDIR" ]; then
$rootrun mkdir -p $TEXMFLOCAL/$DEVDIR
fi
for SRC in src/*; do
$rootrun ln -sfn $PROJECTDIR/$SRC $TEXMFLOCAL/$DEVDIR/${SRC##*/}
done
$rootrun $TEXlsr --quiet

View File

@ -3,61 +3,56 @@
# 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.
## -- log functions
# Halt on error
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
verbosity=2 # default to show warnings
silent_lvl=0
err_lvl=1
wrn_lvl=2
inf_lvl=3
dbg_lvl=4
verbose=1
log_n() { log $silent_lvl "NOTE: $1"; } # Always prints
log_e() { log $err_lvl "ERROR: $1"; }
log_w() { log $wrn_lvl "WARNING: $1"; }
log_i() { log $inf_lvl "INFO: $1"; } # "info" is already a command
log_d() { log $dbg_lvl "DEBUG: $1"; }
log() {
if [ $verbosity -ge $1 ]; then
# Expand escaped characters, wrap at 70 chars, indent wrapped lines
$ECHO "$2" | fold -w80 -s >&3 || true
fi
$ECHO "$2" | fold -w80 -s >> $logfile || true
}
while getopts ":q" opt; do
case ${opt} in
q ) verbose=0
;;
\? ) usage
exit 1
;;
esac
done
## -- commands
check_tex_distro() {
# check for latexmk
status=0
command -v pdflatex >/dev/null 2>&1 || status=1
if [ $status = 0 ]; then
log_d "pdflatex found"
if [ "$verbose" -eq 1 ]; then
echo "pdflatex found"
fi
return 0
fi
log_e "Program 'pdflatex' not found."
log_e "Be sure to have texlive or mactex installed!"
echo "Program 'pdflatex' not found."
echo "Be sure to have texlive or mactex installed!"
exit 1
}
check_imagemagick() {
# check for latexmk
# check for ImageMagick
status=0
command -v compare >/dev/null 2>&1 || status=1
if [ $status = 0 ]; then
log_d "compare found"
if [ "$verbose" -eq 1 ]; then
echo "compare found"
fi
return 0
fi
log_e "Program 'compare' not found."
log_e "Be sure to have imagemagick installed!"
echo "Program 'compare' not found."
echo "Be sure to have imagemagick installed!"
exit 1
}
@ -69,10 +64,16 @@ check_imagemagick
mkdir -p .testing
for TEST in $1*.tex; do
echo "Testing: ${TEST%.*}"
if [ "$verbose" -eq 1 ]; then
echo "Testing: ${TEST%.*}"
fi
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
echo "% difference"
if [ "$verbose" -eq 1 ]; then
echo "% difference"
fi
done
log_n "tests passed!"
if [ "$verbose" -eq 1 ]; then
echo "tests passed!"
fi