Skip to content

Commit f91bfe8

Browse files
bgianfolinusg
authored andcommitted
Meta: pre-commit should run lint-ports.py only when Ports change
Most of the existing lint-ing shell scripts have the ability to only run on the files which have actually changed. The new port lint-ing script doesn't have this functionality unfortunately. This forces us to lint ALL the ports on every single change to any other file in the system if you have the pre-commit hook setup for your git clone locally. Instead we can use pre-commit's feature to only run a hook if certain files have changed to reduce the situations in which we would run the Meta/lint-ports.py script.
1 parent 7bd796b commit f91bfe8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ repos:
44
- id: meta-lint-ci
55
name: Running Meta/lint-ci.sh to ensure changes will pass linting on CI
66
entry: bash Meta/lint-ci.sh
7+
args: [ --no-ports ]
8+
language: system
9+
10+
- id: meta-lint-ports
11+
name: Running Meta/lint-ports.py to ensure changes will pass linting on CI
12+
entry: Meta/lint-ports.py
13+
pass_filenames: false
14+
files: ^Ports/
715
language: system

Meta/lint-ci.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ set -e
55
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
66
cd "${script_path}/.." || exit 1
77

8+
ports=true
9+
if [ "$1" == "--no-ports" ]; then
10+
ports=false
11+
shift
12+
fi
13+
814
RED='\033[0;31m'
915
GREEN='\033[0;32m'
1016
NC='\033[0m' # No Color
@@ -22,7 +28,6 @@ for cmd in \
2228
Meta/lint-ipc-ids.sh \
2329
Meta/lint-keymaps.py \
2430
Meta/lint-shell-scripts.sh \
25-
Meta/lint-ports.py \
2631
Meta/lint-prettier.sh \
2732
Meta/lint-python.sh; do
2833
echo "Running ${cmd}... "
@@ -42,6 +47,21 @@ else
4247
((FAILURES+=1))
4348
fi
4449

50+
# lint-ports.py is handled separately as it scans all Ports/ all the time.
51+
# This is fine when running lint-ci.sh from the PR validation workflow.
52+
# However when running from the pre-commit workflow it takes an excessive
53+
# amount of time. This condition allows the pre-commit program to detect
54+
# when Ports/ files have changed and only invoke lint-ports.py when needed.
55+
#
56+
if [ "$ports" = true ]; then
57+
if Meta/lint-ports.py; then
58+
echo -e "[${GREEN}OK${NC}]: Meta/lint-ports.py"
59+
else
60+
echo -e "[${RED}FAIL${NC}]: Meta/lint-ports.py"
61+
((FAILURES+=1))
62+
fi
63+
fi
64+
4565
echo "(Not running lint-missing-resources.sh due to high false-positive rate.)"
4666
echo "(Also look out for check-symbols.sh, which can only be executed after the build!)"
4767

0 commit comments

Comments
 (0)