@@ -17,42 +17,47 @@ set -euo pipefail
1717
1818EVENT_NAME=" ${1:- local} "
1919BASE_REF=" ${2:- main} "
20- BEFORE_SHA=" ${3:- } "
2120
2221echo " Configuring target diff for event: $EVENT_NAME "
2322
24- # Determine the base branch/commit to diff against
23+ # Determine the target reference to diff against
2524if [ " $EVENT_NAME " = " pull_request" ]; then
25+ echo " Fetching origin/$BASE_REF metadata..."
2626 # Ensure we have the target branch metadata fetched.
2727 git fetch origin " $BASE_REF " --depth=1 --quiet
28- BASE_SHA=" origin/$BASE_REF "
28+
29+ # Isolate to only changes in the PR
30+ DIFF_COMMAND=" origin/$BASE_REF ..."
2931else
30- BASE_SHA=" $BEFORE_SHA "
31- # Fallback if it's a direct push without a prior SHA, or a local run
32- if [ " $BASE_SHA " = " 0000000000000000000000000000000000000000" ] || [ -z " $BASE_SHA " ]; then
33- BASE_SHA=" HEAD~1"
34- fi
32+ # Local fallback
33+ # diff against local main branch.
34+ echo " Running locally. Diffing against local $BASE_REF ..."
35+ DIFF_COMMAND=" $BASE_REF "
3536fi
3637
37- DIFF_OUTPUT=$( git diff --name-only --diff-filter=d " $BASE_SHA " -- ' *.py' 2> /dev/null || true)
38+ # Gather modified/added Python files, explicitly ignoring deleted files via --diff-filter=d
39+ DIFF_OUTPUT=$( git diff --name-only --diff-filter=d " $DIFF_COMMAND " -- ' *.py' 2> /dev/null || true)
3840
3941if [ -n " $DIFF_OUTPUT " ]; then
4042 mapfile -t CHANGED_FILES <<< " $DIFF_OUTPUT"
4143else
4244 CHANGED_FILES=()
4345fi
4446
45- # Execute linters if files exist
47+ # Execute linters if changed Python files exist
4648if [ ${# CHANGED_FILES[@]} -gt 0 ]; then
4749 echo " Files to lint:"
4850 printf ' - %s\n' " ${CHANGED_FILES[@]} "
4951
50- # Track execution success manually so both tools get a chance to run
52+ # Track execution success manually so both tools get a chance to run.
53+ # This prevents the workflow from dying on Black without showing Flake8 errors.
5154 BLACK_EXIT=0
5255 LINT_EXIT=0
5356
54- # Pass the array safely using "${CHANGED_FILES[@]} "
57+ echo " Running blacken... "
5558 nox -s blacken -- " ${CHANGED_FILES[@]} " || BLACK_EXIT=$?
59+
60+ echo " Running flake8 lint..."
5661 nox -s lint -- " ${CHANGED_FILES[@]} " || LINT_EXIT=$?
5762
5863 if [ $BLACK_EXIT -ne 0 ] || [ $LINT_EXIT -ne 0 ]; then
0 commit comments