CMake/.gitlab/ci/codespell.bash
Brad King d11552c2d9 codespell: Exclude paths by patterns following pre-commit check conventions
In order to share `.codespellrc` between our CI checks and `pre-commit`
checks, we need to match paths without the leading `./`.  Convert to a
`bash` script so we can use `dotglob` to pass paths explicitly.

Unfortunately this means we can no longer run `codespell` manually with
no arguments.  Instead we can run `.gitlab/ci/codespell.bash`.
2025-01-22 08:51:45 -05:00

22 lines
543 B
Bash
Executable File

#!/bin/sh
set -e
result=0
# 'codespell' with no arguments adds a leading './' to all paths.
# Avoid that by globbing top-level entries explicitly.
shopt -s dotglob
echo "Running 'codespell' on source code..."
codespell * || result=1
shopt -u dotglob
if [ -n "$CI_MERGE_REQUEST_DIFF_BASE_SHA" ]; then
for COMMIT in $(git rev-list "^$CI_MERGE_REQUEST_DIFF_BASE_SHA" "$CI_COMMIT_SHA"); do
echo "Running 'codespell' on commit message of $COMMIT..."
git show --format=%B -s "$COMMIT" | codespell - || result=1
done
fi
exit $result