Skip to content

Commit

Permalink
build.sh: set variable default and lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
dhimmel committed Aug 26, 2021
1 parent b88e454 commit ec0e455
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/manubot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ on:
workflow_dispatch:
inputs:
BUILD_PDF:
description: generate PDF output
description: generate PDF output (true or false)
default: "true"
BUILD_DOCX:
description: generate DOCX output
description: generate DOCX output (true or false)
default: "false"
BUILD_LATEX:
description: generate LaTeX output
description: generate LaTeX output (true or false)
default: "false"
jobs:
manubot:
Expand Down
27 changes: 17 additions & 10 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ export TZ=Etc/UTC
# Default Python to read/write text files using UTF-8 encoding
export LC_ALL=en_US.UTF-8

# Set option defaults
CI="${CI:-false}"
BUILD_PDF="${BUILD_PDF:-true}"
BUILD_DOCX="${BUILD_DOCX:-false}"
BUILD_LATEX="${BUILD_LATEX:-false}"
SPELLCHECK="${SPELLCHECK:-false}"
# Pandoc's configuration is specified via files of option defaults
# located in the $PANDOC_DATA_DIR/defaults directory.
PANDOC_DATA_DIR="${PANDOC_DATA_DIR:-build/pandoc}"

# Generate reference information
echo >&2 "Retrieving and processing reference metadata"
manubot process \
Expand All @@ -20,10 +30,6 @@ manubot process \
--skip-citations \
--log-level=INFO

# Pandoc's configuration is specified via files of option defaults
# located in the $PANDOC_DATA_DIR/defaults directory.
PANDOC_DATA_DIR="${PANDOC_DATA_DIR:-build/pandoc}"

# Make output directory
mkdir -p output

Expand All @@ -39,8 +45,9 @@ pandoc --verbose \
DOCKER_RUNNING="$(docker info &> /dev/null && echo "yes" || true)"

# Create PDF output (unless BUILD_PDF environment variable equals "false")
# The double-commas (,,) lowercase the variable.
# If Docker is not available, use WeasyPrint to create PDF
if [ "${BUILD_PDF:-}" != "false" ] && [ -z "$DOCKER_RUNNING" ]; then
if [ "${BUILD_PDF,,}" != "false" ] && [ -z "$DOCKER_RUNNING" ]; then
echo >&2 "Exporting PDF manuscript using WeasyPrint"
if [ -L images ]; then rm images; fi # if images is a symlink, remove it
ln -s content/images
Expand All @@ -53,9 +60,9 @@ if [ "${BUILD_PDF:-}" != "false" ] && [ -z "$DOCKER_RUNNING" ]; then
fi

# If Docker is available, use athenapdf to create PDF
if [ "${BUILD_PDF:-}" != "false" ] && [ -n "$DOCKER_RUNNING" ]; then
if [ "${BUILD_PDF,,}" != "false" ] && [ -n "$DOCKER_RUNNING" ]; then
echo >&2 "Exporting PDF manuscript using Docker + Athena"
if [ "${CI:-}" = "true" ]; then
if [ "${CI,,}" = "true" ]; then
# Incease --delay for CI builds to ensure the webpage fully renders, even when the CI server is under high load.
# Local builds default to a shorter --delay to minimize runtime, assuming proper rendering is less crucial.
MANUBOT_ATHENAPDF_DELAY="${MANUBOT_ATHENAPDF_DELAY:-5000}"
Expand All @@ -77,7 +84,7 @@ if [ "${BUILD_PDF:-}" != "false" ] && [ -n "$DOCKER_RUNNING" ]; then
fi

# Create DOCX output (if BUILD_DOCX environment variable equals "true")
if [ "${BUILD_DOCX:-}" = "true" ]; then
if [ "${BUILD_DOCX,,}" = "true" ]; then
echo >&2 "Exporting Word Docx manuscript"
pandoc --verbose \
--data-dir="$PANDOC_DATA_DIR" \
Expand All @@ -86,7 +93,7 @@ if [ "${BUILD_DOCX:-}" = "true" ]; then
fi

# Create LaTeX output (if BUILD_LATEX environment variable equals "true")
if [ "${BUILD_LATEX:-}" = "true" ]; then
if [ "${BUILD_LATEX,,}" = "true" ]; then
echo >&2 "Exporting LaTeX manuscript"
pandoc \
--data-dir="$PANDOC_DATA_DIR" \
Expand All @@ -95,7 +102,7 @@ if [ "${BUILD_LATEX:-}" = "true" ]; then
fi

# Spellcheck
if [ "${SPELLCHECK:-}" = "true" ]; then
if [ "${SPELLCHECK,,}" = "true" ]; then
export ASPELL_CONF="add-extra-dicts $(pwd)/build/assets/custom-dictionary.txt; ignore-case true"

# Identify and store spelling errors
Expand Down

0 comments on commit ec0e455

Please sign in to comment.