Skip to content

Commit

Permalink
fix: add default values for boolean option and use = to test them (#…
Browse files Browse the repository at this point in the history
…131)

* fix: add default values for boolean option and use `=` to test them

Use [[ $option = 'true' ]] instead of [[ -n $option ]] to check enabled option.
[[ -n $option ]] will return true if the string is not empty even if
we set `option=false`, because bash treats `false` as a non-empty string.

* chore: remove superfluous info

---------

Co-authored-by: Cheng XU <[email protected]>
  • Loading branch information
zydou and xu-cheng authored Aug 28, 2023
1 parent 868bee6 commit 9ae8710
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ inputs:
description: The working directory for this action
work_in_root_file_dir:
description: Change directory into each root file's directory before compiling each documents
default: "false"
continue_on_error:
description: Continuing to build document even with LaTeX build errors
default: "false"
compiler:
description: The LaTeX engine to be invoked
default: latexmk
Expand All @@ -31,10 +33,13 @@ inputs:
description: Arbitrary bash codes to be executed after compiling LaTeX documents
latexmk_shell_escape:
description: Instruct latexmk to enable --shell-escape
default: "false"
latexmk_use_lualatex:
description: Instruct latexmk to use LuaLaTeX
default: "false"
latexmk_use_xelatex:
description: Instruct latexmk to use XeLaTeX
default: "false"

runs:
using: composite
Expand Down
16 changes: 8 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ fi
IFS=' ' read -r -a args <<<"$args"

if [[ "$compiler" = "latexmk" ]]; then
if [[ -n "$latexmk_shell_escape" ]]; then
if [[ "$latexmk_shell_escape" = "true" ]]; then
args+=("-shell-escape")
fi

if [[ -n "$latexmk_use_lualatex" && -n "$latexmk_use_xelatex" ]]; then
if [[ "$latexmk_use_lualatex" = "true" && "$latexmk_use_xelatex" = "true" ]]; then
error "Input 'latexmk_use_lualatex' and 'latexmk_use_xelatex' cannot be used at the same time."
fi

if [[ -n "$latexmk_use_lualatex" ]]; then
if [[ "$latexmk_use_lualatex" = "true" ]]; then
for i in "${!args[@]}"; do
if [[ "${args[i]}" = "-pdf" ]]; then
unset 'args[i]'
Expand All @@ -92,7 +92,7 @@ if [[ "$compiler" = "latexmk" ]]; then
args=("${args[@]/#-interaction=/--interaction=}")
fi

if [[ -n "$latexmk_use_xelatex" ]]; then
if [[ "$latexmk_use_xelatex" = "true" ]]; then
for i in "${!args[@]}"; do
if [[ "${args[i]}" = "-pdf" ]]; then
unset 'args[i]'
Expand All @@ -102,7 +102,7 @@ if [[ "$compiler" = "latexmk" ]]; then
fi
else
for VAR in "${!latexmk_@}"; do
if [[ -n "${!VAR}" ]]; then
if [[ "${!VAR}" = "true" ]]; then
error "Input '${VAR}' is only valid if input 'compiler' is set to 'latexmk'."
fi
done
Expand Down Expand Up @@ -152,7 +152,7 @@ for f in "${root_file[@]}"; do
continue
fi

if [[ -n "$work_in_root_file_dir" ]]; then
if [[ "$work_in_root_file_dir" = "true" ]]; then
pushd "$(dirname "$f")" >/dev/null
f="$(basename "$f")"
info "Compile $f in $PWD"
Expand All @@ -166,14 +166,14 @@ for f in "${root_file[@]}"; do

"$compiler" "${args[@]}" "$f" || ret="$?"
if [[ "$ret" -ne 0 ]]; then
if [[ -n "$continue_on_error" ]]; then
if [[ "$continue_on_error" = "true" ]]; then
exit_code="$ret"
else
exit "$ret"
fi
fi

if [[ -n "$work_in_root_file_dir" ]]; then
if [[ "$work_in_root_file_dir" = "true" ]]; then
popd >/dev/null
fi
done
Expand Down

0 comments on commit 9ae8710

Please sign in to comment.