pmaports/.ci/codeowners.sh
Luca Weiss e5c26d38f8
CI: add CODEOWNERS file sanity check (MR 4662)
* Check for space indentation instead of tabs
* Check that an entry actually exists
* Check that a directory ends in a slash, otherwise GitLab seems to
  ignore it
2023-12-29 15:02:10 +01:00

43 lines
1.1 KiB
Bash
Executable file

#!/bin/sh -e
# Description: verify CODEOWNERS file is sane
# https://postmarketos.org/pmb-ci
# TODO Future improvements:
# * Check that all devices in main/community have someone in CODEOWNERS
# * Check that GitLab user actually exists (e.g. deleted account, account with
# changed user name)
if grep -q " " CODEOWNERS; then
echo
echo "ERROR: Found space indentation in CODEOWNERS."
echo "ERROR: Please indent with tab characters."
grep " " CODEOWNERS
echo
exit 1
fi
fail=0
tmppipe=$(mktemp -u)
mkfifo "$tmppipe"
grep -v "^#" CODEOWNERS | cut -d' ' -f1 > "$tmppipe" &
while IFS= read -r line; do
[ -z "$line" ] && continue
# Check if entry generally exists
# shellcheck disable=SC2086
ls $line >/dev/null 2>&1 || { fail=1; echo "Non-existing: $line"; }
# Check that directories end with a slash
# shellcheck disable=SC2086
if test -d "$(ls -d $line)"; then
echo "$line" | grep -q '/$' || { fail=1; echo "Missing trailing slash: $line"; }
fi
done < "$tmppipe"
rm "$tmppipe"
if [ "$fail" = 1 ]; then
echo
echo "ERROR: Invalid CODEOWNERS entries, see above."
echo
exit 1
fi