Skip to content

Commit 3563248

Browse files
authored
Merge pull request #111 from hackforla/deploy_patch
dix deploy bug with change file
2 parents 48472dd + 6127e2b commit 3563248

4 files changed

Lines changed: 32 additions & 27 deletions

File tree

.github/scripts/clasp_push.sh

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,51 @@ export LC_ALL=C.UTF-8
33
export 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
76
function 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

2933
exit_code=0
3034

3135
# Process each Clasp project directory
3236
for 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
4351
done
4452

4553
if [ $exit_code -ne 0 ]; then

.github/workflows/deploy.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@ jobs:
2222
id: changed-files
2323
run: |
2424
if [[ "${{ github.event_name }}" == "push" ]]; then
25-
# For push to main: diff against previous commit
26-
echo "all_changed_files<<EOF" >> $GITHUB_OUTPUT
27-
git diff --name-only HEAD~1 || true
28-
echo "EOF" >> $GITHUB_OUTPUT
25+
CHANGED_FILES=$(git diff --name-only HEAD~1 | tr '\n' ' ' || true)
2926
else
30-
# For workflow_dispatch or other: diff against main (or use empty for full push)
31-
echo "all_changed_files<<EOF" >> $GITHUB_OUTPUT
32-
git diff --name-only origin/main || true
33-
echo "EOF" >> $GITHUB_OUTPUT
27+
CHANGED_FILES=$(git diff --name-only origin/main | tr '\n' ' ' || true)
3428
fi
29+
echo "all_changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT
3530
3631
- name: Debug changed files
3732
run: |

src/ClaspTestScript/Code.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ function Run() {
1010
Logger.log("Test4");
1111
Logger.log("9/25");
1212
Logger.log("9/25-1");
13+
Logger.log("9/25-2");
1314
}

src/dummyscript/Code.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ function myFunction() {
44
Logger.log("Test4");
55
Logger.log("Test9/23");
66
Logger.log("9/25-1");
7+
Logger.log("9/25-2");
78
}

0 commit comments

Comments
 (0)