Skip to content

Commit

Permalink
entrypoint.sh: better messages for incorrect inputs for the action
Browse files Browse the repository at this point in the history
Github Action editor automatically generates a template based on
the meta data from action.yml. However, it passes empty strings
to optional inputs regardless their default values.

To remedy the issue, provide better messages and auto reset compiler
and args inputs if both of them are empty.

Fixes #16.
  • Loading branch information
xu-cheng committed Dec 9, 2019
1 parent 3608d12 commit b25b386
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ jobs:
working_directory: test/
compiler: arara
args: "--verbose"
# https://github.com/xu-cheng/latex-action/issues/16
- name: Test Action with Github Default Template
uses: ./
with:
# The root LaTeX file to be compiled
root_file: test/test.tex
# The working directory for the LaTeX engine
working_directory: # optional
# The LaTeX engine to be invoked
compiler: # optional, default is latexmk
# Extra arguments to be passed to the LaTeX engine
args: # optional, default is -pdf -file-line-error -interaction=nonstopmode
# [Deprecated] Install extra packages by tlmgr
extra_packages: # optional
# Install extra packages by apk
extra_system_packages: # optional
- name: Check pdf files
run: |
file test/test.pdf | grep -q ' PDF '
Expand Down
25 changes: 24 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,32 @@

set -e

warn() {
echo "::warning :: $1"
}

error() {
echo "::error :: $1"
exit 1
}

root_file="$1"
working_directory="$2"
compiler="$3"
args="$4"
extra_packages="$5"
extra_system_packages="$6"

if [ -z "$root_file" ]; then
error "Input 'root_file' is missing."
fi

if [ -z "$compiler" ] && [ -z "$args" ]; then
warn "Input 'compiler' and 'args' are both empty. Reset them to default values."
compiler="latexmk"
args="-pdf -file-line-error -interaction=nonstopmode"
fi

if [ -n "$extra_system_packages" ]; then
for pkg in $extra_system_packages; do
echo "Install $pkg by apk"
Expand All @@ -17,12 +36,16 @@ if [ -n "$extra_system_packages" ]; then
fi

if [ -n "$extra_packages" ]; then
echo "::warning ::Input 'extra_packages' is deprecated. We now build LaTeX document with full TeXLive installed."
warn "Input 'extra_packages' is deprecated. We now build LaTeX document with full TeXLive installed."
fi

if [ -n "$working_directory" ]; then
cd "$working_directory"
fi

if [ ! -f "$root_file" ]; then
error "File '$root_file' cannot be found from the directory '$PWD'."
fi

# shellcheck disable=SC2086
"$compiler" $args "$root_file"

0 comments on commit b25b386

Please sign in to comment.