From e5c26d38f83faba0ba502303b5ccff40cb90fa1e Mon Sep 17 00:00:00 2001 From: Luca Weiss Date: Thu, 28 Dec 2023 16:38:23 +0100 Subject: [PATCH] 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 --- .ci/codeowners.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 1 + 2 files changed, 44 insertions(+) create mode 100755 .ci/codeowners.sh diff --git a/.ci/codeowners.sh b/.ci/codeowners.sh new file mode 100755 index 000000000..6b41ebb38 --- /dev/null +++ b/.ci/codeowners.sh @@ -0,0 +1,43 @@ +#!/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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f988b05e4..66c91a221 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -60,6 +60,7 @@ shellcheck-grep: - .ci/lib/gitlab_prepare_ci.sh - .ci/shellcheck.sh - .ci/grep.sh + - .ci/codeowners.sh editor-config: stage: lint