Run commit checkers in CI
71b73249a30d589c97e15b387d4a18e8e6b795a9 Made the change that
format-code is only run on repos that have the appropriate files.
Because commit messages don't have a "file" in the normal sense,
.git/COMMIT_EDITMSG was used instead. While this buffer file contains
the last commit message that was written, it only works on repos that
have had a commit done on them. For developers, this gives the expected
result, where commit message tools are run. For CI, where the repos
never had a commit message interaction, this leads to the commit message
runners never being run.
This commit moves the file check to .git (ie, that this is a git repo)
which should match everything. This was arguably better than adding a
"run all the time" mechanism specific to commit messages.
Tested:
Removing .git/COMMIT_EDITMSG on master and running a build shows commit
checks not run when run against master.
Running format-code.sh against this patch now shows commit tools run in
all cases.
Signed-off-by: Ed Tanous <ed@tanous.net>
Change-Id: Ia596689b2ba220fc1dd17b713143ffc3fc96364f
diff --git a/scripts/format-code.sh b/scripts/format-code.sh
index 847084d..90475ca 100755
--- a/scripts/format-code.sh
+++ b/scripts/format-code.sh
@@ -144,16 +144,28 @@
LINTER_REQUIRE+=([commit_spelling]="codespell")
LINTER_TYPES+=([commit_spelling]="commit")
+
+commit_filename="$(mktemp)"
+function clean_up_file() {
+ rm "$commit_filename"
+}
+trap clean_up_file EXIT
+
function do_commit_spelling() {
+ # Write the commit message to a temporary file
+ git log -1 > "$commit_filename"
+
+ # Some names or emails appear as false-positive misspellings, remove them
+ sed -i "s/Signed-off-by.*//" "$commit_filename"
+
# Run the codespell with openbmc spcific spellings on the patchset
echo -n "openbmc-dictionary - misspelling count >> "
- sed "s/Signed-off-by.*//" "$@" | \
- codespell -D "${CONFIG_PATH}/openbmc-spelling.txt" -d --count -
+
+ codespell -D "${CONFIG_PATH}/openbmc-spelling.txt" -d --count "$commit_filename"
# Run the codespell with generic dictionary on the patchset
echo -n "generic-dictionary - misspelling count >> "
- sed "s/Signed-off-by.*//" "$@" | \
- codespell --builtin clear,rare,en-GB_to_en-US -d --count -
+ codespell --builtin clear,rare,en-GB_to_en-US -d --count "$commit_filename"
}
LINTER_REQUIRE+=([commit_gitlint]="gitlint")
@@ -329,9 +341,8 @@
# Find all the files in the git repository and organize by type.
declare -A FILES=()
-if [ -e .git/COMMIT_EDITMSG ]; then
- FILES+=([commit]=".git/COMMIT_EDITMSG")
-fi
+FILES+=([commit]=".git")
+
while read -r file; do
ftype="$(get_file_type "$file")"
FILES+=([$ftype]="$(echo -ne "$file;${FILES[$ftype]:-}")")