mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-24 18:10:56 -05:00
60 lines
1.8 KiB
Bash
Executable file
60 lines
1.8 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
SOURCE_DIR="$(dirname -- ${BASH_SOURCE[0]:-$0})";
|
|
|
|
log() {
|
|
echo -e "$1" >&2
|
|
}
|
|
|
|
CMD_NAME="typos"
|
|
TARGET=${INPUT_FILES:-"."}
|
|
if [[ -n "${GITHUB_BASE_REF:-}" ]]; then
|
|
BASE_REF=HEAD~ # HACK: GITHUB_BASE_REF is failing the `--verify` but `HEAD~ should be the same for pull requests
|
|
git config --global --add safe.directory "$PWD"
|
|
if git rev-parse --verify ${BASE_REF} 2>/dev/null ; then
|
|
log "Limiting checks to ${GITHUB_BASE_REF}...HEAD"
|
|
TARGET=$(git diff ${BASE_REF}...HEAD --name-only --diff-filter=AM -- ${TARGET})
|
|
if [[ -z "${TARGET:-}" ]]; then
|
|
log "INPUT_FILES are unchanged"
|
|
exit 0
|
|
fi
|
|
else
|
|
log "WARN: Not limiting checks to ${BASE_REF}...HEAD, ${GITHUB_BASE_REF} is not available"
|
|
fi
|
|
fi
|
|
|
|
if [[ -z $(ls ${TARGET} 2>/dev/null) ]]; then
|
|
log "ERROR: Input files (${TARGET}) not found"
|
|
exit 1
|
|
fi
|
|
if [[ -z $(which ${CMD_NAME} 2>/dev/null) ]]; then
|
|
VERSION=1.14.5
|
|
log "Downloading 'typos' v${VERSION}"
|
|
wget https://github.com/crate-ci/typos/releases/download/v${VERSION}/typos-v${VERSION}-x86_64-unknown-linux-musl.tar.gz
|
|
sudo tar -xzvf typos-v${VERSION}-x86_64-unknown-linux-musl.tar.gz -C /usr/local/bin ./typos
|
|
rm typos-v${VERSION}-x86_64-unknown-linux-musl.tar.gz
|
|
fi
|
|
log "jq: $(jq --version)"
|
|
|
|
ARGS="${TARGET}"
|
|
|
|
# Ignore implicit configuration files
|
|
if [ "${INPUT_ISOLATED:-false}" == "true" ]; then
|
|
ARGS+=" --isolated"
|
|
fi
|
|
|
|
# Write changes to the repository
|
|
if [ "${INPUT_WRITE_CHANGES:-false}" == "true" ]; then
|
|
ARGS+=" --write-changes"
|
|
fi
|
|
|
|
# Use a custom configuration file
|
|
if [[ -n "${INPUT_CONFIG:-}" ]]; then
|
|
ARGS+=" --config ${INPUT_CONFIG}"
|
|
fi
|
|
|
|
log "$ ${CMD_NAME} ${ARGS}"
|
|
${CMD_NAME} ${ARGS} --format json | ${SOURCE_DIR}/format_gh.sh || true
|
|
${CMD_NAME} ${ARGS}
|