fix(action): Be stricter/cleaner with entrypoint

This commit is contained in:
Ed Page 2021-06-05 12:22:24 -05:00
parent 0aaa2c0d60
commit 39d9a90c9b

View file

@ -1,59 +1,34 @@
#!/bin/bash #!/bin/bash
set -e set -eu
printf "Found files in workspace:\n" log() {
ls echo -e "$1" >&2
}
printf "\nLooking for typos installed...\n" CMD_NAME="typos"
which typos TARGET=${INPUT_FILES:-"."}
COMMAND="typos" if [[ -z $(ls ${TARGET} 2>/dev/null) ]]; then
log "ERROR: Input files (${TARGET}) not found"
# Show the _typos.toml file exit 1
if [ -f "_typos.toml" ]; then
echo "_typos.toml:"
cat _typos.toml
echo
fi fi
if [[ -z $(which ${CMD_NAME} 2>/dev/null) ]]; then
log "ERROR: 'typos' not found"
exit 1
fi
COMMAND="${CMD_NAME} ${TARGET}"
# Ignore implicit configuration files # Ignore implicit configuration files
if [ "${INPUT_ISOLATED}" == "true" ]; then if [ "${INPUT_ISOLATED:-false}" == "true" ]; then
COMMAND="${COMMAND} --isolated" COMMAND+=" --isolated"
fi fi
# Use a custom configuration file # Use a custom configuration file
if [ ! -z "${INPUT_CONFIG}" ]; then if [[ -n "${INPUT_CONFIG:-}" ]]; then
COMMAND+=" --config ${INPUT_CONFIG}"
# It must exist
if [ ! -f "${INPUT_CONFIG}" ]; then
printf "${INPUT_CONFIG} does not exist.\n"
exit 1;
else
# Show the custom config to the user
printf "Custom config:\n"
cat "${INPUT_CONFIG}"
echo
fi
COMMAND="${COMMAND} --config ${INPUT_CONFIG}"
fi fi
# Files are technically optional log "$ ${COMMAND}"
if [ ! -z "${INPUT_FILES}" ]; then
COMMAND="${COMMAND} ${INPUT_FILES}"
fi
echo "Command: "
echo "${COMMAND}"
echo
${COMMAND} ${COMMAND}
retval=$?
if [[ "${retval}" -eq 0 ]]; then
printf "No spelling mistakes found! 🎉️\n"
else
printf "Spelling mistakes found! 😱️\n"
exit $retval;
fi