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
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.
  • Loading branch information
zydou committed Aug 28, 2023
1 parent 33306cd commit 3f153d8
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 @@ -33,10 +35,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 @@ -67,15 +67,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 @@ -93,7 +93,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 @@ -103,7 +103,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 @@ -157,7 +157,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 @@ -171,14 +171,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 3f153d8

Please sign in to comment.