Add static check for overzealous .gitignores.

(cherry picked from commit 7ea171adca)
This commit is contained in:
Ben Rog-Wilhelm 2023-07-01 08:32:30 -05:00 committed by Rémi Verschelde
parent 0e2bfdc3a3
commit b19469a08e
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 31 additions and 0 deletions

View File

@ -30,6 +30,11 @@ jobs:
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 100
sudo pip3 install black==22.3.0 pygments
# This needs to happen before Python and npm execution; it must happen before any extra files are written.
- name: .gitignore checks (gitignore_check.sh)
run: |
bash ./misc/scripts/gitignore_check.sh
- name: File formatting checks (file_format.sh)
run: |
bash ./misc/scripts/file_format.sh

View File

@ -0,0 +1,26 @@
set -uo pipefail
shopt -s globstar
echo -e ".gitignore validation..."
# Get a list of files that exist in the repo but are ignored.
# The --verbose flag also includes files un-ignored via ! prefixes.
# We filter those out with a somewhat awkward `awk` directive.
# (Explanation: Split each line by : delimiters,
# see if the actual gitignore line shown in the third field starts with !,
# if it doesn't, print it.)
# ignorecase for the sake of Windows users.
output=$(git -c core.ignorecase=true check-ignore --verbose --no-index **/* | \
awk -F ':' '{ if ($3 !~ /^!/) print $0 }')
# Then we take this result and return success if it's empty.
if [ -z "$output" ]; then
exit 0
else
# And print the result if it isn't.
echo "$output"
exit 1
fi