project-config/tools/check_valid_gerrit_config.sh
Ian Wienand ac1ef44843
tools/normalize_acl.py: Add some human readable output
Currently if your ACL fails the normalization pass you get a diff, but
no explaination of what that diff represents.

This is an attempt to make the situation better without having to
undertake some sort of major rewrite of the transformer.  We move the
current in-code comments into human-actionable strings, and add a
"-help" argument that prints this out.  If we have normalization
failures, we add a step to the driver script to print this string out.
This will appear in the job output and hopefully be easily seen when
scrolling the logs.

Change-Id: Ib07a10a25f35875afad21f77f545dc1cc207cecd
2023-04-27 16:52:57 +10:00

52 lines
1.3 KiB
Bash
Executable File

#!/bin/bash -e
# It checks that *.config files respect certain gerrit ACL rules
TMPDIR=$(mktemp -d)
export TMPDIR
trap "rm -rf $TMPDIR" EXIT
pushd $TMPDIR
CONFIGS_LIST_BASE=$OLDPWD/gerrit/acls
declare -i NUM_TESTS=0
function check_team_acl {
local configs_dir="$1"
local configs_list
echo "Checking" $(basename $configs_dir)
configs_list=$(find $configs_dir -name "*.config")
for config in $configs_list; do
let "NUM_TESTS+=1"
$OLDPWD/tools/normalize_acl.py $config all > $TMPDIR/normalized
if ! diff -u $config $TMPDIR/normalized >>config_failures;
then
echo "Project $config is not normalized!" >>config_failures
fi
done
}
# Add more namespaces here, if necessary
for namespace in $CONFIGS_LIST_BASE/*; do
if [ -d $namespace ] ; then
check_team_acl "${namespace}"
fi
done
num_errors=$(cat config_failures | grep "is not normalized" | wc -l)
if [ $num_errors -ne 0 ]; then
echo -e; cat config_failures
echo -e "There are $num_errors projects not normalized."
echo
echo -e "******************************************************"
$OLDPWD/tools/normalize_acl.py -help
echo -e "******************************************************"
exit 1
fi
echo "Gerrit ACL configs are valid!"
echo "Checked $NUM_TESTS ACL files"
popd