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
|
|
|
|
2021-06-05 13:22:24 -04:00
|
|
|
CMD_NAME="typos"
|
|
|
|
TARGET=${INPUT_FILES:-"."}
|
2022-06-16 11:09:50 -04:00
|
|
|
if [[ -n "${GITHUB_BASE_REF:-}" ]]; then
|
2022-06-16 14:08:37 -04:00
|
|
|
BASE_REF=HEAD~ # HACK: GITHUB_BASE_REF is failing the `--verify` but `HEAD~ should be the same for pull requests
|
2022-08-16 11:02:32 -04:00
|
|
|
git config --global --add safe.directory "$PWD"
|
2022-06-16 14:08:37 -04:00
|
|
|
if git rev-parse --verify ${BASE_REF} 2>/dev/null ; then
|
2022-06-16 11:09:50 -04:00
|
|
|
log "Limiting checks to ${GITHUB_BASE_REF}...HEAD"
|
2022-06-16 14:08:37 -04:00
|
|
|
TARGET=$(git diff ${BASE_REF}...HEAD --name-only --diff-filter=AM -- ${TARGET})
|
2022-06-16 14:40:37 -04:00
|
|
|
if [[ -z "${TARGET:-}" ]]; then
|
|
|
|
log "INPUT_FILES are unchanged"
|
|
|
|
exit 0
|
|
|
|
fi
|
2022-06-16 11:09:50 -04:00
|
|
|
else
|
2022-06-16 14:08:37 -04:00
|
|
|
log "WARN: Not limiting checks to ${BASE_REF}...HEAD, ${GITHUB_BASE_REF} is not available"
|
2022-06-16 11:09:50 -04:00
|
|
|
fi
|
|
|
|
fi
|
2021-05-31 20:42:45 -04:00
|
|
|
|
2021-06-05 13:22:24 -04:00
|
|
|
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
|
2021-06-05 13:22:24 -04:00
|
|
|
if [[ -z $(which ${CMD_NAME} 2>/dev/null) ]]; then
|
|
|
|
log "ERROR: 'typos' not found"
|
|
|
|
exit 1
|
2021-05-31 20:42:45 -04:00
|
|
|
fi
|
2022-06-16 12:12:15 -04:00
|
|
|
log "typos: $(typos --version)"
|
|
|
|
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
|
|
|
|
|
2022-06-22 12:30:58 -04:00
|
|
|
log "$ ${CMD_NAME} ${ARGS}"
|
2022-06-22 12:33:54 -04:00
|
|
|
${CMD_NAME} ${ARGS} --format json | ${SOURCE_DIR}/format_gh.sh || true
|
2022-06-22 12:30:58 -04:00
|
|
|
${CMD_NAME} ${ARGS}
|