@@ -10,6 +10,21 @@ if [ -z "${GITHUB_OUTPUT:-}" ]; then
1010 exit 1
1111fi
1212
13+ # Unknown changes require checks, but cannot authorize deployment.
14+ unknown_changes () {
15+ echo " Unable to determine changed files." >&2
16+ if [ " $mode " = " docs-only" ]; then
17+ echo " run=false" >> " $GITHUB_OUTPUT "
18+ else
19+ echo " run=true" >> " $GITHUB_OUTPUT "
20+ fi
21+ exit 0
22+ }
23+
24+ if [ " $mode " = " docs-only" ] && { [ -z " $base_sha " ] || [ -z " $head_sha " ]; }; then
25+ unknown_changes
26+ fi
27+
1328if [ -z " $head_sha " ]; then
1429 head_sha=" $( git rev-parse HEAD 2> /dev/null || true) "
1530fi
@@ -24,40 +39,49 @@ if [ -z "$base_sha" ]; then
2439fi
2540
2641if [ -z " $base_sha " ] || [ -z " $head_sha " ]; then
27- echo " run=true" >> " $GITHUB_OUTPUT "
28- exit 0
42+ unknown_changes
2943fi
3044
3145if [ " $base_sha " = " 0000000000000000000000000000000000000000" ]; then
32- echo " run=true" >> " $GITHUB_OUTPUT "
33- exit 0
46+ unknown_changes
3447fi
3548
36- if ! git cat-file -e " $base_sha " 2> /dev/null; then
37- git fetch --no-tags --depth=1 origin " $base_sha " || true
38- fi
49+ for sha in " $base_sha " " $head_sha " ; do
50+ if ! git cat-file -e " $sha ^{commit}" 2> /dev/null; then
51+ git fetch --no-tags --depth=1 origin " $sha " || true
52+ fi
53+ if ! git cat-file -e " $sha ^{commit}" 2> /dev/null; then
54+ unknown_changes
55+ fi
56+ done
3957
40- if ! git cat-file -e " $base_sha " 2> /dev/null; then
41- echo " run=true" >> " $GITHUB_OUTPUT "
42- exit 0
58+ changed_files=$( mktemp)
59+ trap ' rm -f "$changed_files"' EXIT
60+ # Include both sides of renames and preserve complete Git path names.
61+ if ! git diff --name-only --no-renames -z " $base_sha " " $head_sha " -- > " $changed_files " ; then
62+ unknown_changes
4363fi
4464
45- changed_files=$( git diff --name-only " $base_sha " " $head_sha " || true)
46-
65+ docs_pattern=' ^(docs/|mkdocs\.yml$)'
4766case " $mode " in
4867 code)
49- pattern=' ^(src/|tests/|integration_tests/|examples/|\.agents/skills/(code-change-verification|examples-auto-run|examples-run-analysis|integration-tests)/|\.github/scripts/(detect-changes\.sh|run_examples\.sh|run_integration_tests\.py|update_released_api_contract\.py)$|\. github/workflows/tests\.yml$|pyproject.toml$|uv.lock$|Makefile$)'
68+ pattern=' ^(src/|tests/|integration_tests/|examples/|docs/scripts/| \.agents/skills/(code-change-verification|examples-auto-run|examples-run-analysis|integration-tests)/|\.github/scripts/|\. github/workflows/( tests|docs|publish|repo-skills) \.yml$|pyproject\ .toml$|uv\ .lock$|Makefile$|pyrightconfig\.json $)'
5069 ;;
51- docs)
52- pattern=' ^(docs/|mkdocs.yml$) '
70+ docs|docs-only )
71+ pattern=" $docs_pattern "
5372 ;;
5473 * )
5574 pattern=" $mode "
5675 ;;
5776esac
5877
59- if echo " $changed_files " | grep -Eq " $pattern " ; then
60- echo " run=true" >> " $GITHUB_OUTPUT "
61- else
62- echo " run=false" >> " $GITHUB_OUTPUT "
63- fi
78+ run=false
79+ while IFS= read -r -d ' ' path; do
80+ if [[ " $path " =~ $pattern ]]; then
81+ run=true
82+ elif [ " $mode " = " docs-only" ]; then
83+ run=false
84+ break
85+ fi
86+ done < " $changed_files "
87+ echo " run=$run " >> " $GITHUB_OUTPUT "
0 commit comments