From 4558c8f9ff1e3855a72e647380d18d7a07b70eb9 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Mon, 10 Feb 2025 00:56:39 +0400 Subject: ci: Use `typos` to check commit messages Commit messages in the CMake repo may have Git hashes that can trigger false positives in the `typos` checker. Revert commit ddebf4653d (ci: Do not check commit messages with 'typos' due to false positives, 2025-02-07). Instead, copy the top-level config file to a temporary location, add a configuration option to mark 10-hex-digit identifiers as always valid, and pass it to `typos` at the commit checking phase. --- .gitlab/ci/typos.bash | 15 ++++++++++++--- .typos.toml | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.gitlab/ci/typos.bash b/.gitlab/ci/typos.bash index 7293a03..4c92383 100755 --- a/.gitlab/ci/typos.bash +++ b/.gitlab/ci/typos.bash @@ -7,8 +7,17 @@ result=0 echo "Running 'typos' on source code..." typos || result=1 -# FIXME(typos): checking commit messages hits false positives -# on "words" inside commit hashes. We'd need a way to disable -# checking of combined identifiers to avoid this. +cfg='.typos.toml' +tmp_cfg="${TEMP:-/tmp}/$cfg" +# Uncomment `extend-ignore-identifiers-re` in the top-level config file +# to make Git hashes (possibly used in commit messages) valid "identifiers". +sed 's/^#\s*\(extend-ignore-identifiers-re\)/\1/' "$cfg" >"$tmp_cfg" + +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 'typos' on commit message of $COMMIT..." + git show --format=%B -s "$COMMIT" | typos -c "$tmp_cfg" - || result=1 + done +fi exit $result diff --git a/.typos.toml b/.typos.toml index c494769..c06745a 100644 --- a/.typos.toml +++ b/.typos.toml @@ -11,6 +11,11 @@ extend-ignore-re = [ , "(?Rm)^.*(#|/(/|\\*)|\\.\\.)\\s*(NOQA|noqa):? spellcheck(: *|=| +)disable-line$" ] locale = "en-us" +# ATTENTION If, for any reason, you want to add the +# `extend-ignore-identifiers-re` to this section, +# please also modify the `.gitlab/ci/typos.bash` +# script accordingly. +#extend-ignore-identifiers-re=["\\b[0-9a-f]{10}\\b"] # Add repo-wide false positives here in the form of `word = "word"`. # Check the manual for details. -- cgit v0.12