@@ -9,76 +9,54 @@ export LANG=C.UTF-8
99function contains_changes() {
1010 local dir=" $1 "
1111 shift
12- echo " Checking for changed files in $dir : $@ "
13- [[ " $* " == " " ]] && { echo " No changed files provided, skipping $dir " ; return 1; }
14- dir_absolute=$( realpath " $dir " 2> /dev/null || echo " $dir " )
15- dir_absolute=" ${dir_absolute%/ } /"
12+ [[ " $* " == " " ]] && return 1
13+ dir_absolute=$( realpath " $dir " 2> /dev/null || pwd)
14+ dir_absolute=" ${dir_absolute%/ } /" # Ensure trailing slash for pattern match
1615 for f in " $@ " ; do
17- file_absolute=$( realpath " $f " 2> /dev/null || echo " $( pwd) /$f " )
18- echo " Comparing $file_absolute against $dir_absolute "
16+ file_absolute=$( realpath " $f " 2> /dev/null || echo " $f " )
1917 if [[ " $file_absolute " == " $dir_absolute " * ]]; then
20- echo " Found changed file $f in $dir "
2118 return 0
2219 fi
2320 done
24- echo " No changed files in $dir "
2521 return 1
2622}
2723
2824# Ensure working directory is the repository root
29- echo " Initial working directory: $( pwd) "
30- cd " $GITHUB_WORKSPACE " || { echo " Failed to set working directory to $GITHUB_WORKSPACE " ; exit 1; }
31- echo " Current working directory: $( pwd) "
25+ cd " $GITHUB_WORKSPACE " || exit 1
3226
33- # Debug input
34- echo " Input changed files: $@ "
27+ # If no input files, exit
3528if [ $# -eq 0 ]; then
36- echo " No input files provided, exiting"
3729 exit 0
3830fi
3931
4032# Filter changed files to only include src/ directories
41- changed_files=" "
42- if [ $# -gt 0 ]; then
43- changed_files=$( echo " $@ " | xargs -n1 | grep ' ^src/' | xargs -n1 realpath 2> /dev/null | xargs -I {} dirname {} | sort -u || true)
44- fi
45- echo " Changed directories (filtered to src/): $changed_files "
33+ changed_files=$( echo " $@ " | xargs -n1 | grep ' ^src/' | xargs -n1 realpath 2> /dev/null | xargs -I {} dirname {} | sort -u || true)
4634
4735# Find all directories containing .clasp.json files
4836dirs=()
49- if ! find_output=$( find . -name ' .clasp.json' -exec dirname {} \; | sort -u | xargs realpath 2> /dev/null) ; then
50- echo " Warning: find command failed or no .clasp.json files found"
51- else
37+ if find_output=$( find . -name ' .clasp.json' -exec dirname {} \; | sort -u | xargs realpath 2> /dev/null) ; then
5238 IFS=$' \n ' read -r -d ' ' -a dirs <<< " $find_output" || true
5339fi
54- echo " Clasp project directories: ${dirs[@]} "
5540
5641exit_code=0
5742
5843# Process each Clasp project directory
5944for dir in " ${dirs[@]} " ; do
60- echo " Processing directory: $dir "
6145 if [ ! -d " $dir " ]; then
62- echo " Directory $dir does not exist, skipping"
6346 continue
6447 fi
65- pushd " $dir " > /dev/null || { echo " Failed to enter $dir " ; exit_code=1; continue ; }
48+ pushd " $dir " > /dev/null || { exit_code=1; continue ; }
49+ # Skip if the directory does not contain any changed files
6650 if ! contains_changes " $dir " " $@ " ; then
6751 popd > /dev/null
6852 continue
6953 fi
70- echo " Publishing $dir "
7154 clasp push -f
7255 status=$?
7356 if [ $status -ne 0 ]; then
74- echo " clasp push failed in $dir with status $status "
7557 exit_code=$status
7658 fi
7759 popd > /dev/null
7860done
7961
80- if [ $exit_code -ne 0 ]; then
81- echo " Script push failed."
82- fi
83-
8462exit $exit_code
0 commit comments