2021-05-31 20:42:45 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-06-05 13:22:24 -04:00
|
|
|
set -eu
|
2021-05-31 20:42:45 -04:00
|
|
|
|
2022-06-22 12:33:54 -04:00
|
|
|
SOURCE_DIR="$(dirname -- ${BASH_SOURCE[0]:-$0})";
|
|
|
|
|
2021-06-05 13:22:24 -04:00
|
|
|
log() {
|
|
|
|
echo -e "$1" >&2
|
|
|
|
}
|
2021-05-31 20:42:45 -04:00
|
|
|
|
2023-05-22 14:29:19 -04:00
|
|
|
_DEFAULT_INSTALL_DIR=${HOME}/bin
|
|
|
|
_INSTALL_DIR=${INSTALL_DIR:-${_DEFAULT_INSTALL_DIR}}
|
2021-06-05 13:22:24 -04:00
|
|
|
CMD_NAME="typos"
|
2023-05-22 14:29:19 -04:00
|
|
|
COMMAND="${_INSTALL_DIR}/${CMD_NAME}"
|
|
|
|
|
2021-06-05 13:22:24 -04:00
|
|
|
TARGET=${INPUT_FILES:-"."}
|
|
|
|
if [[ -z $(ls ${TARGET} 2>/dev/null) ]]; then
|
|
|
|
log "ERROR: Input files (${TARGET}) not found"
|
|
|
|
exit 1
|
2021-05-31 20:42:45 -04:00
|
|
|
fi
|
2023-08-21 13:25:34 -04:00
|
|
|
|
2024-06-17 11:11:57 -04:00
|
|
|
|
2023-05-22 14:29:19 -04:00
|
|
|
if [[ ! -x ${COMMAND} ]]; then
|
2024-11-25 16:07:26 -05:00
|
|
|
VERSION=1.28.0
|
2024-06-17 11:11:57 -04:00
|
|
|
if [[ "$(uname -m)" == "arm64" ]]; then
|
|
|
|
ARCH="aarch64"
|
|
|
|
else
|
|
|
|
ARCH="x86_64"
|
|
|
|
fi
|
2024-09-04 01:38:08 -04:00
|
|
|
UNAME=$(uname -s)
|
|
|
|
if [[ "$UNAME" == "Darwin" ]]; then
|
2024-06-17 11:11:57 -04:00
|
|
|
TARGET_FILE="${ARCH}-apple-darwin"
|
2024-09-04 01:38:08 -04:00
|
|
|
FILE_EXT="tar.gz"
|
|
|
|
elif [[ "$UNAME" == CYGWIN* || "$UNAME" == MINGW* || "$UNAME" == MSYS* ]] ; then
|
|
|
|
TARGET_FILE="${ARCH}-pc-windows-msvc"
|
|
|
|
FILE_EXT="zip"
|
2024-06-17 11:11:57 -04:00
|
|
|
else
|
|
|
|
TARGET_FILE="${ARCH}-unknown-linux-musl"
|
2024-09-04 01:38:08 -04:00
|
|
|
FILE_EXT="tar.gz"
|
2024-06-17 11:11:57 -04:00
|
|
|
fi
|
2024-09-04 01:38:08 -04:00
|
|
|
FILE_NAME="typos-v${VERSION}-${TARGET_FILE}.${FILE_EXT}"
|
2023-03-13 22:32:08 -04:00
|
|
|
log "Downloading 'typos' v${VERSION}"
|
2024-06-17 11:11:57 -04:00
|
|
|
wget --progress=dot:mega "https://github.com/crate-ci/typos/releases/download/v${VERSION}/${FILE_NAME}"
|
2023-05-22 14:29:19 -04:00
|
|
|
mkdir -p ${_INSTALL_DIR}
|
2024-09-04 01:38:08 -04:00
|
|
|
if [[ "$FILE_EXT" == "zip" ]]; then
|
|
|
|
unzip -o "${FILE_NAME}" -d ${_INSTALL_DIR} ${CMD_NAME}.exe
|
|
|
|
else
|
|
|
|
tar -xzvf "${FILE_NAME}" -C ${_INSTALL_DIR} ./${CMD_NAME}
|
|
|
|
fi
|
2024-06-17 11:11:57 -04:00
|
|
|
rm "${FILE_NAME}"
|
2021-05-31 20:42:45 -04:00
|
|
|
fi
|
2022-06-16 12:12:15 -04:00
|
|
|
log "jq: $(jq --version)"
|
2021-05-31 20:42:45 -04:00
|
|
|
|
2022-06-22 12:30:58 -04:00
|
|
|
ARGS="${TARGET}"
|
2021-05-31 20:42:45 -04:00
|
|
|
|
2021-06-05 13:22:24 -04:00
|
|
|
# Ignore implicit configuration files
|
|
|
|
if [ "${INPUT_ISOLATED:-false}" == "true" ]; then
|
2022-06-22 12:30:58 -04:00
|
|
|
ARGS+=" --isolated"
|
2021-05-31 20:42:45 -04:00
|
|
|
fi
|
|
|
|
|
2023-01-26 11:42:41 -05:00
|
|
|
# Write changes to the repository
|
|
|
|
if [ "${INPUT_WRITE_CHANGES:-false}" == "true" ]; then
|
|
|
|
ARGS+=" --write-changes"
|
|
|
|
fi
|
|
|
|
|
2021-06-05 13:22:24 -04:00
|
|
|
# Use a custom configuration file
|
|
|
|
if [[ -n "${INPUT_CONFIG:-}" ]]; then
|
2022-06-22 12:30:58 -04:00
|
|
|
ARGS+=" --config ${INPUT_CONFIG}"
|
2021-05-31 20:42:45 -04:00
|
|
|
fi
|
|
|
|
|
2023-05-22 14:29:19 -04:00
|
|
|
log "$ ${COMMAND} ${ARGS}"
|
|
|
|
${COMMAND} ${ARGS} --format json | ${SOURCE_DIR}/format_gh.sh || true
|
|
|
|
${COMMAND} ${ARGS}
|