From 0a420d2e31c5f069e8b2be195c58aaf21409c72a Mon Sep 17 00:00:00 2001 From: Jay Rogers Date: Tue, 5 Aug 2025 16:32:03 -0500 Subject: [PATCH 1/6] Optimize file search in configure.sh by adjusting find command parameters for improved performance and clarity. --- lib/actions/configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/actions/configure.sh b/lib/actions/configure.sh index d61314e9..a0e552fa 100644 --- a/lib/actions/configure.sh +++ b/lib/actions/configure.sh @@ -80,7 +80,7 @@ configure_gha() { echo "🔑 Adding GitHub Actions secrets..." # Loop through all files in the CI folder (sorted alphabetically) - find "$SPIN_CI_FOLDER" -type f -maxdepth 1 | sort | while read -r filepath; do + find "$SPIN_CI_FOLDER" -maxdepth 1 -type f | sort | while read -r filepath; do file=$(basename "$filepath") # Skip files with file extensions and .gitignore if [[ "$file" != *.* ]]; then From a085d4819c90aaa24c9578cb887367b6f3fc403b Mon Sep 17 00:00:00 2001 From: Jay Rogers Date: Wed, 6 Aug 2025 10:16:52 -0500 Subject: [PATCH 2/6] Normalize line endings before base64 encoding in configure.sh for improved cross-platform compatibility --- lib/actions/configure.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/actions/configure.sh b/lib/actions/configure.sh index a0e552fa..d212bcad 100644 --- a/lib/actions/configure.sh +++ b/lib/actions/configure.sh @@ -140,13 +140,14 @@ gh_set_env() { local content if [ -n "$file" ]; then if [ "$base64_encode" = true ]; then - content=$(base64_encode "$file") + # Normalize line endings before encoding to ensure cross-platform compatibility + content=$(tr -d '\r' < "$file" | base64_encode -) else content=$(<"$file") fi else if [ "$base64_encode" = true ]; then - content=$(echo -n "$value" | base64_encode -) + content=$(printf '%s' "$value" | base64_encode -) else content="$value" fi From eda100a1ab9ba3a167481131b6d5ed2975b4844d Mon Sep 17 00:00:00 2001 From: Jay Rogers Date: Wed, 6 Aug 2025 10:37:28 -0500 Subject: [PATCH 3/6] Enhance error handling and content normalization in configure.sh for improved robustness and cross-platform compatibility --- lib/actions/configure.sh | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/actions/configure.sh b/lib/actions/configure.sh index d212bcad..4d57821d 100644 --- a/lib/actions/configure.sh +++ b/lib/actions/configure.sh @@ -80,7 +80,7 @@ configure_gha() { echo "🔑 Adding GitHub Actions secrets..." # Loop through all files in the CI folder (sorted alphabetically) - find "$SPIN_CI_FOLDER" -maxdepth 1 -type f | sort | while read -r filepath; do + find "$SPIN_CI_FOLDER" -type f -maxdepth 1 | sort | while read -r filepath; do file=$(basename "$filepath") # Skip files with file extensions and .gitignore if [[ "$file" != *.* ]]; then @@ -136,21 +136,31 @@ gh_set_env() { return 1 fi - # Get content from either file or value - local content +# Get content from either file or value if [ -n "$file" ]; then + if [ ! -f "$file" ]; then + echo "${BOLD}${RED}❌ File not found: $file${RESET}" + return 1 + fi + + # Read file content and normalize line endings to ensure consistency across platforms + # Convert all line endings to Unix format (LF) for cross-platform compatibility + content=$(cat "$file" | tr -d '\r') + + # Optionally base64 encode the content if [ "$base64_encode" = true ]; then - # Normalize line endings before encoding to ensure cross-platform compatibility - content=$(tr -d '\r' < "$file" | base64_encode -) - else - content=$(<"$file") + content=$(echo "$content" | base64_encode) fi - else + elif [ -n "$value" ]; then + content="$value" + + # Optionally base64 encode the content if [ "$base64_encode" = true ]; then - content=$(printf '%s' "$value" | base64_encode -) - else - content="$value" + content=$(echo "$content" | base64_encode) fi + else + echo "${BOLD}${RED}❌ No file or value specified${RESET}" + return 1 fi # Set the secret using the gh CLI From ef4a0623d7d25b7386c581da6a5c3bca5ce83f62 Mon Sep 17 00:00:00 2001 From: Jay Rogers Date: Wed, 6 Aug 2025 10:56:12 -0500 Subject: [PATCH 4/6] Refactor base64 encoding and decoding functions for improved input handling and cross-platform compatibility - Enhanced base64_encode and base64_decode functions to differentiate between file paths and raw content, ensuring correct processing on macOS and Linux. - Updated action_base64 to streamline decoding logic and improve error handling for base64 strings. - Simplified content encoding in configure.sh by directly passing content to base64_encode, enhancing clarity and maintainability. --- lib/actions/base64.sh | 8 ++------ lib/actions/configure.sh | 4 ++-- lib/functions.sh | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lib/actions/base64.sh b/lib/actions/base64.sh index 6a384c7c..50c87ef9 100755 --- a/lib/actions/base64.sh +++ b/lib/actions/base64.sh @@ -23,14 +23,10 @@ action_base64() { # Decode the input if [ -f "$input" ]; then # If it's a file, decode the file contents - base64_decode - < "$input" + base64_decode "$input" else # If it's not a file, assume it's a base64 string and try to decode it - echo "$input" | base64_decode - 2>/dev/null - if [ $? -ne 0 ]; then - echo "Error: Input is not a valid base64 string." - return 1 - fi + base64_decode "$input" fi ;; *) diff --git a/lib/actions/configure.sh b/lib/actions/configure.sh index 4d57821d..50fec739 100644 --- a/lib/actions/configure.sh +++ b/lib/actions/configure.sh @@ -149,14 +149,14 @@ gh_set_env() { # Optionally base64 encode the content if [ "$base64_encode" = true ]; then - content=$(echo "$content" | base64_encode) + content=$(base64_encode "$content") fi elif [ -n "$value" ]; then content="$value" # Optionally base64 encode the content if [ "$base64_encode" = true ]; then - content=$(echo "$content" | base64_encode) + content=$(base64_encode "$content") fi else echo "${BOLD}${RED}❌ No file or value specified${RESET}" diff --git a/lib/functions.sh b/lib/functions.sh index 7e3696c5..7514ea93 100755 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -10,19 +10,43 @@ add_user_todo_item() { base64_encode() { local input="$1" - if [[ "$(uname -s)" == "Darwin" ]]; then - base64 -i "$input" + + # Check if input is a file path or should be treated as content + if [[ -f "$input" ]]; then + # File path - use existing behavior + if [[ "$(uname -s)" == "Darwin" ]]; then + base64 -i "$input" + else + base64 "$input" + fi else - base64 "$input" + # Content - pipe through base64 + if [[ "$(uname -s)" == "Darwin" ]]; then + echo "$input" | base64 + else + echo "$input" | base64 + fi fi } base64_decode() { local input="$1" - if [[ "$(uname -s)" == "Darwin" ]]; then - base64 -D "$input" + + # Check if input is a file path or should be treated as content + if [[ -f "$input" ]]; then + # File path - use existing behavior + if [[ "$(uname -s)" == "Darwin" ]]; then + base64 -D "$input" + else + base64 -d "$input" + fi else - base64 -d "$input" + # Content - pipe through base64 decode + if [[ "$(uname -s)" == "Darwin" ]]; then + echo "$input" | base64 -D + else + echo "$input" | base64 -d + fi fi } From 86e763e65e8fbd8d641c47472e28555304d0efad Mon Sep 17 00:00:00 2001 From: Jay Rogers Date: Wed, 6 Aug 2025 11:11:04 -0500 Subject: [PATCH 5/6] Adjust order of maxdepth and type (ref #165) --- lib/actions/configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/actions/configure.sh b/lib/actions/configure.sh index 50fec739..3d6360df 100644 --- a/lib/actions/configure.sh +++ b/lib/actions/configure.sh @@ -80,7 +80,7 @@ configure_gha() { echo "🔑 Adding GitHub Actions secrets..." # Loop through all files in the CI folder (sorted alphabetically) - find "$SPIN_CI_FOLDER" -type f -maxdepth 1 | sort | while read -r filepath; do + find "$SPIN_CI_FOLDER" -maxdepth 1 -type f | sort | while read -r filepath; do file=$(basename "$filepath") # Skip files with file extensions and .gitignore if [[ "$file" != *.* ]]; then From 427b4b66db0900f2ed7f112d8c4c1f523a9919f3 Mon Sep 17 00:00:00 2001 From: Jay Rogers Date: Wed, 6 Aug 2025 11:48:05 -0500 Subject: [PATCH 6/6] Refactor base64 encoding in functions.sh for improved cross-platform compatibility - Updated base64 encoding commands to use flags that ensure consistent output across macOS and Linux. - Enhanced handling of both file paths and raw content for better performance and reliability. --- lib/functions.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/functions.sh b/lib/functions.sh index 7514ea93..f028e8a6 100755 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -15,16 +15,16 @@ base64_encode() { if [[ -f "$input" ]]; then # File path - use existing behavior if [[ "$(uname -s)" == "Darwin" ]]; then - base64 -i "$input" + base64 -b 0 -i "$input" else - base64 "$input" + base64 -w 0 "$input" fi else # Content - pipe through base64 if [[ "$(uname -s)" == "Darwin" ]]; then - echo "$input" | base64 + echo "$input" | base64 -b 0 else - echo "$input" | base64 + echo "$input" | base64 -w 0 fi fi }