@@ -3,43 +3,51 @@ export LC_ALL=C.UTF-8
33export LANG=C.UTF-8
44
55# Function to check if a directory contains any of the changed files
6- # Returns 0 if the directory contains changes, 1 otherwise
76function contains_changes() {
8- # If no changed files are provided, assume no changes
9- [[ " ${*: 2} " = " " ]] && return 1
10- for f in " ${@: 2} " ; do
11- case $( realpath " $f " ) / in
12- $( realpath " $1 " ) /* ) return 0;;
13- esac
7+ local dir=" $1 "
8+ shift
9+ [[ " $* " == " " ]] && { echo " No changed files provided, skipping $dir " ; return 1; }
10+ for f in " $@ " ; do
11+ if [[ $( realpath " $f " 2> /dev/null) / == $( realpath " $dir " ) /* ]]; then
12+ echo " Found changed file $f in $dir "
13+ return 0
14+ fi
1415 done
16+ echo " No changed files in $dir "
1517 return 1
1618}
19+ # Debug input
20+ echo " Input changed files: $@ "
1721
18- # Get the unique directories of the changed files
19- # This helps in identifying which directories have modifications
20- changed_files= $( echo " ${ @: 1} " | xargs realpath | xargs -I {} dirname {} | sort -u | uniq )
21-
22- # Initialize an array to hold directories containing .clasp.json files
23- dirs=()
22+ # Convert changed files to absolute paths and get unique directories
23+ changed_files= " "
24+ if [ $# -gt 0 ] ; then
25+ changed_files= $( echo " $@ " | xargs -n1 realpath 2> /dev/null | xargs -I {} dirname {} | sort -u )
26+ fi
27+ echo " Changed directories: $changed_files "
2428
2529# Find all directories containing .clasp.json files, which indicate Clasp projects
26- # Use absolute paths for accuracy
27- IFS= $' \n ' read -r -d ' ' -a dirs < <( find . -name ' .clasp.json ' -exec dirname ' {} ' \; | sort -u | xargs realpath )
30+ IFS= $' \n ' read -r -d ' ' -a dirs < <( find . -name ' .clasp.json ' -exec dirname {} \; | sort -u | xargs realpath )
31+ echo " Clasp project directories: ${dirs[@]} "
2832
2933exit_code=0
3034
3135# Process each Clasp project directory
3236for dir in " ${dirs[@]} " ; do
33- pushd " ${ dir} " > /dev/null || exit
37+ pushd " $dir " > /dev/null || { echo " Failed to enter $dir " ; exit 1 ; }
3438 # Skip if the directory does not contain any changed files
35- contains_changes " $dir " " ${changed_files[@]} " || continue
36- echo " Publishing ${dir} "
39+ if ! contains_changes " $dir " " $@ " ; then
40+ popd > /dev/null
41+ continue
42+ fi
43+ echo " Publishing $dir "
3744 clasp push -f
3845 status=$?
3946 if [ $status -ne 0 ]; then
47+ echo " clasp push failed in $dir with status $status "
4048 exit_code=$status
4149 fi
42- popd > /dev/null || exit
50+ popd > /dev/null
4351done
4452
4553if [ $exit_code -ne 0 ]; then
0 commit comments