Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,39 @@
# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425?permalink_comment_id=3945021
#set -eo pipefail

DEBUG=true
WORKING_DIRECTORY=$1
INPUT_FILE=$2
OUTPUT_FILE=$3
INPUT_FILE_PATTERN=$4
OUTPUT_FILE_SUFFIX=$5

verbose() {
if [ "${DEBUG}" = true ]; then
echo "${1}"
fi
echo "::debug::${1}"
}

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

validate_inputs() {
if [ -z "${WORKING_DIRECTORY}" ]; then
echo "ERROR: You must define your 'working-directory'" 1>&2
error "You must define your 'working-directory'"
exit 1
fi

if [ -z "${INPUT_FILE}" ] && [ -z "${INPUT_FILE_PATTERN}" ]; then
echo "ERROR: You must define one of 'input-file' or 'input-file-pattern' to use this utility" 1>&2
error "You must define one of 'input-file' or 'input-file-pattern' to use this utility"
exit 1
fi
if [ -n "${INPUT_FILE}" ] && [ -z "${OUTPUT_FILE}" ]; then
echo "ERROR: You must define 'output-file' input when using 'input-file'" 1>&2
error "You must define 'output-file' input when using 'input-file'"
exit 1
fi
if [ -n "${INPUT_FILE_PATTERN}" ] && [ -z "${OUTPUT_FILE_SUFFIX}" ]; then
echo "ERROR: You must define 'output-file-suffix' input when using 'input-file-pattern'" 1>&2
error "You must define 'output-file-suffix' input when using 'input-file-pattern'"
exit 1
fi
}

verbose "DEBUG=${DEBUG}"
verbose "WORKING_DIRECTORY=${WORKING_DIRECTORY}"
verbose "INPUT_FILE=${INPUT_FILE}"
verbose "OUTPUT_FILE=${OUTPUT_FILE}"
Expand All @@ -48,7 +47,7 @@ validate_inputs
# Exec envsubst
if [ -n "${INPUT_FILE}" ] && [ -n "${OUTPUT_FILE}" ]; then
if [ ! -f "${WORKING_DIRECTORY}/${INPUT_FILE}" ]; then
echo "ERROR: ${WORKING_DIRECTORY}/${INPUT_FILE} file not found." 1>&2
error "${WORKING_DIRECTORY}/${INPUT_FILE} file not found."
exit 1
fi
verbose "Applying envsubst with file ${WORKING_DIRECTORY}/${INPUT_FILE}"
Expand Down