2022-12-31 10:31:39 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2023-07-02 20:33:09 -07:00
|
|
|
BASE=${1:-origin/master}
|
2023-01-15 16:59:06 -08:00
|
|
|
RETCODE=0
|
2022-12-31 10:31:39 -08:00
|
|
|
|
2023-02-22 17:17:23 -08:00
|
|
|
RED='\033[1;31m'
|
|
|
|
|
GREEN='\033[1;32m'
|
|
|
|
|
NC='\033[0m'
|
|
|
|
|
|
2022-12-31 10:31:39 -08:00
|
|
|
function fail() {
|
2023-02-22 17:17:23 -08:00
|
|
|
echo -e "${RED}$*${NC}"
|
2023-01-15 16:59:06 -08:00
|
|
|
RETCODE=1
|
2022-12-31 10:31:39 -08:00
|
|
|
}
|
|
|
|
|
|
2023-02-22 17:17:23 -08:00
|
|
|
echo -e "${GREEN}Checking from $(git rev-parse --short ${BASE}):${NC}"
|
|
|
|
|
git log --pretty=oneline --no-merges --abbrev-commit ${BASE}..
|
2023-07-02 20:33:09 -07:00
|
|
|
echo
|
2023-02-22 17:17:23 -08:00
|
|
|
|
2025-05-29 11:39:49 -04:00
|
|
|
git diff ${BASE}.. -- '*.py' | grep '^+' > added_lines
|
2026-06-30 16:22:27 -07:00
|
|
|
git diff ${BASE}.. -- 'chirp/drivers/*.py' | grep '^+' > driver_lines
|
2022-12-31 10:31:39 -08:00
|
|
|
|
2026-07-02 14:39:59 +10:00
|
|
|
if grep -E '\<(from|import)\>.*\<six\>' added_lines; then
|
2026-05-30 22:04:04 +02:00
|
|
|
fail No new uses of six
|
2022-12-31 10:31:39 -08:00
|
|
|
fi
|
|
|
|
|
|
2026-05-30 22:04:04 +02:00
|
|
|
if grep -E '\<six\>' added_lines; then
|
2022-12-31 10:31:39 -08:00
|
|
|
fail No new uses of six
|
|
|
|
|
fi
|
|
|
|
|
|
2026-07-02 14:39:59 +10:00
|
|
|
if grep -E '\<(from|import)\>.*builtins' added_lines; then
|
2022-12-31 10:31:39 -08:00
|
|
|
fail No new uses of future
|
|
|
|
|
fi
|
|
|
|
|
|
2026-05-30 22:04:04 +02:00
|
|
|
if grep -E '\<future\>' added_lines; then
|
2022-12-31 10:31:39 -08:00
|
|
|
fail No new uses of future
|
|
|
|
|
fi
|
|
|
|
|
|
2026-07-02 14:39:59 +10:00
|
|
|
if grep -E '\<(from|import)\>.*\<past\>' added_lines; then
|
2022-12-31 10:31:39 -08:00
|
|
|
fail Use of past library not allowed
|
|
|
|
|
fi
|
2023-01-04 14:49:15 -08:00
|
|
|
|
2026-07-02 14:39:59 +10:00
|
|
|
if grep -E '\<MemoryMap\(' added_lines; then
|
2023-01-04 14:49:15 -08:00
|
|
|
fail New uses of MemoryMap should be MemoryMapBytes
|
|
|
|
|
fi
|
2023-01-15 16:59:06 -08:00
|
|
|
|
2023-03-14 21:04:21 -07:00
|
|
|
if grep -E "[^_]_\([^\"']" added_lines; then
|
2023-03-10 14:39:42 -08:00
|
|
|
fail 'Translated strings must be literals!'
|
|
|
|
|
fi
|
|
|
|
|
|
2026-07-02 14:39:59 +10:00
|
|
|
if grep -E "\<eval\(" added_lines; then
|
2024-02-06 10:48:19 -08:00
|
|
|
fail 'Use of eval() is dangerous and not permitted!'
|
|
|
|
|
fi
|
|
|
|
|
|
2025-05-29 11:39:49 -04:00
|
|
|
if git diff ${BASE}.. -- 'tools/cpep8.manifest' | tail -n +5 | grep -q '^+'; then
|
2023-03-10 17:40:37 -08:00
|
|
|
fail 'Do not add new files to cpep8.manifest; no longer needed'
|
|
|
|
|
fi
|
|
|
|
|
|
2025-05-29 11:39:49 -04:00
|
|
|
if git diff ${BASE}.. -- 'tools/cpep8.blacklist' | tail -n +5 | grep -q '^+'; then
|
2024-01-21 12:55:49 +01:00
|
|
|
fail 'Do not add new files to cpep8.blacklist; fix the code'
|
2023-03-10 17:40:37 -08:00
|
|
|
fi
|
|
|
|
|
|
2023-07-02 20:33:09 -07:00
|
|
|
grep -i 'license' added_lines > license_lines
|
2023-07-03 16:21:21 -07:00
|
|
|
if grep -ivE '(GNU General Public License|Free Software Foundation|gnu.org.licenses)' license_lines; then
|
2023-07-02 20:33:09 -07:00
|
|
|
fail 'Files must be GPLv3 licensed (or not contain any license language)'
|
|
|
|
|
fi
|
|
|
|
|
|
2023-02-22 17:17:23 -08:00
|
|
|
for file in $(git diff --name-only ${BASE}..); do
|
2023-01-15 21:12:27 -08:00
|
|
|
if file $file | grep -q CRLF; then
|
2023-01-15 16:59:06 -08:00
|
|
|
fail "$file : Files should be LF (Unix) format, not CR (Mac) or CRLF (Windows)"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2023-11-24 11:01:50 -08:00
|
|
|
#if grep 'def match_model' added_lines; then
|
|
|
|
|
# fail 'New drivers should not have match_model() implemented as it is not needed'
|
|
|
|
|
#fi
|
2023-11-05 09:13:56 -08:00
|
|
|
|
2026-07-02 14:39:59 +10:00
|
|
|
if grep -E '\<print\(' added_lines; then
|
2025-05-27 16:48:04 -07:00
|
|
|
fail 'Do not use print()'
|
|
|
|
|
fi
|
|
|
|
|
|
2026-07-02 14:39:59 +10:00
|
|
|
if grep -E '\<(from|import)\>.*wx' driver_lines; then
|
2026-06-30 16:22:27 -07:00
|
|
|
fail 'Drivers may not import GUI components or manipulate the GUI'
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if grep -E '(subprocess|webbrowser)' driver_lines; then
|
|
|
|
|
fail 'Drivers may not spawn external commands'
|
|
|
|
|
fi
|
|
|
|
|
|
2023-02-22 17:17:23 -08:00
|
|
|
if git log ${BASE}.. --merges | grep .; then
|
2023-01-28 07:54:15 -08:00
|
|
|
fail Please do not include merge commits in your PR
|
|
|
|
|
fi
|
|
|
|
|
|
2023-06-14 17:38:23 -07:00
|
|
|
make -C chirp/locale clean all >/dev/null 2>&1
|
2025-05-29 11:39:49 -04:00
|
|
|
if git diff -- chirp/locale | grep '^+[^#+]' | grep -v POT-Creation; then
|
2023-03-06 17:01:12 -08:00
|
|
|
fail Locale files need updating
|
|
|
|
|
fi
|
|
|
|
|
|
2023-11-17 17:29:46 -08:00
|
|
|
added_files=$(git diff --name-only --diff-filter=A ${BASE}..)
|
|
|
|
|
added_py=$(git diff --name-only --diff-filter=A ${BASE}.. | grep '\.py$')
|
|
|
|
|
if echo $added_py | grep -q chirp.drivers && ! echo $added_files | grep -q tests.images; then
|
2023-06-18 15:11:40 -07:00
|
|
|
fail All new drivers should include a test image
|
|
|
|
|
fi
|
|
|
|
|
|
2025-05-22 15:50:36 -07:00
|
|
|
modified_files=$(git diff --name-only --diff-filter=M ${BASE}..)
|
|
|
|
|
modified_img=$(echo "$modified_files" | grep 'tests.images')
|
|
|
|
|
modified_py=$(echo "$modified_files" | grep '\.py$')
|
|
|
|
|
if [ "$modified_img" -a "$modified_py" ]; then
|
|
|
|
|
fail "Change modifies an image and (potentially) a driver for a possible upgrade breakage"
|
|
|
|
|
fi
|
|
|
|
|
|
2025-05-29 11:39:49 -04:00
|
|
|
existing_drivers=$(git ls-tree --name-only $BASE -- chirp/drivers/)
|
2023-11-17 17:26:10 -08:00
|
|
|
limit=51
|
2023-11-17 17:29:46 -08:00
|
|
|
for nf in $added_py; do
|
2023-07-03 16:21:21 -07:00
|
|
|
for of in $existing_drivers; do
|
2023-11-17 17:26:10 -08:00
|
|
|
common=$(wdiff -s $of $nf | grep -I $nf | sed -r 's/.* ([0-9]+)% common.*/\1/')
|
|
|
|
|
if [ ! "$common" ]; then
|
2023-10-25 17:37:45 -07:00
|
|
|
continue
|
|
|
|
|
fi
|
2023-11-17 17:26:10 -08:00
|
|
|
if [ "$common" -gt "$limit" ]; then
|
|
|
|
|
fail "New file $nf shares at least ${common}% with $of!"
|
2023-07-03 16:21:21 -07:00
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
|
2024-02-06 10:48:19 -08:00
|
|
|
rm -f added_lines license_lines
|
|
|
|
|
|
2025-08-17 10:18:39 -07:00
|
|
|
commits=$(git log --pretty=format:%h ${BASE}..)
|
|
|
|
|
for commit in $commits; do
|
|
|
|
|
git log -n1 $commit --pretty=format:%B > commit_msg
|
|
|
|
|
if [[ `sed -n '1p' commit_msg | wc -c` > 99 ]]; then
|
|
|
|
|
fail "First line of commit message of $commit must be <99 chars"
|
|
|
|
|
fi
|
|
|
|
|
if [[ `wc -l < commit_msg` > 1 ]]; then
|
|
|
|
|
if ! sed -n '2p' commit_msg | grep '^$'; then
|
|
|
|
|
fail "Second line of commit message of $commit must be blank for proper formatting in the notification emails"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
rm -f commit_msg
|
|
|
|
|
done
|
|
|
|
|
|
2023-01-15 16:59:06 -08:00
|
|
|
exit $RETCODE
|