Skip to content

Commit 731de18

Browse files
authored
Fix issues with "spin configure" (#167)
1 parent 1ab7f11 commit 731de18

3 files changed

Lines changed: 53 additions & 22 deletions

File tree

lib/actions/base64.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ action_base64() {
2323
# Decode the input
2424
if [ -f "$input" ]; then
2525
# If it's a file, decode the file contents
26-
base64_decode - < "$input"
26+
base64_decode "$input"
2727
else
2828
# If it's not a file, assume it's a base64 string and try to decode it
29-
echo "$input" | base64_decode - 2>/dev/null
30-
if [ $? -ne 0 ]; then
31-
echo "Error: Input is not a valid base64 string."
32-
return 1
33-
fi
29+
base64_decode "$input"
3430
fi
3531
;;
3632
*)

lib/actions/configure.sh

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ configure_gha() {
8080

8181
echo "🔑 Adding GitHub Actions secrets..."
8282
# Loop through all files in the CI folder (sorted alphabetically)
83-
find "$SPIN_CI_FOLDER" -type f -maxdepth 1 | sort | while read -r filepath; do
83+
find "$SPIN_CI_FOLDER" -maxdepth 1 -type f | sort | while read -r filepath; do
8484
file=$(basename "$filepath")
8585
# Skip files with file extensions and .gitignore
8686
if [[ "$file" != *.* ]]; then
@@ -136,20 +136,31 @@ gh_set_env() {
136136
return 1
137137
fi
138138

139-
# Get content from either file or value
140-
local content
139+
# Get content from either file or value
141140
if [ -n "$file" ]; then
141+
if [ ! -f "$file" ]; then
142+
echo "${BOLD}${RED}❌ File not found: $file${RESET}"
143+
return 1
144+
fi
145+
146+
# Read file content and normalize line endings to ensure consistency across platforms
147+
# Convert all line endings to Unix format (LF) for cross-platform compatibility
148+
content=$(cat "$file" | tr -d '\r')
149+
150+
# Optionally base64 encode the content
142151
if [ "$base64_encode" = true ]; then
143-
content=$(base64_encode "$file")
144-
else
145-
content=$(<"$file")
152+
content=$(base64_encode "$content")
146153
fi
147-
else
154+
elif [ -n "$value" ]; then
155+
content="$value"
156+
157+
# Optionally base64 encode the content
148158
if [ "$base64_encode" = true ]; then
149-
content=$(echo -n "$value" | base64_encode -)
150-
else
151-
content="$value"
159+
content=$(base64_encode "$content")
152160
fi
161+
else
162+
echo "${BOLD}${RED}❌ No file or value specified${RESET}"
163+
return 1
153164
fi
154165

155166
# Set the secret using the gh CLI

lib/functions.sh

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,43 @@ add_user_todo_item() {
1010

1111
base64_encode() {
1212
local input="$1"
13-
if [[ "$(uname -s)" == "Darwin" ]]; then
14-
base64 -i "$input"
13+
14+
# Check if input is a file path or should be treated as content
15+
if [[ -f "$input" ]]; then
16+
# File path - use existing behavior
17+
if [[ "$(uname -s)" == "Darwin" ]]; then
18+
base64 -b 0 -i "$input"
19+
else
20+
base64 -w 0 "$input"
21+
fi
1522
else
16-
base64 "$input"
23+
# Content - pipe through base64
24+
if [[ "$(uname -s)" == "Darwin" ]]; then
25+
echo "$input" | base64 -b 0
26+
else
27+
echo "$input" | base64 -w 0
28+
fi
1729
fi
1830
}
1931

2032
base64_decode() {
2133
local input="$1"
22-
if [[ "$(uname -s)" == "Darwin" ]]; then
23-
base64 -D "$input"
34+
35+
# Check if input is a file path or should be treated as content
36+
if [[ -f "$input" ]]; then
37+
# File path - use existing behavior
38+
if [[ "$(uname -s)" == "Darwin" ]]; then
39+
base64 -D "$input"
40+
else
41+
base64 -d "$input"
42+
fi
2443
else
25-
base64 -d "$input"
44+
# Content - pipe through base64 decode
45+
if [[ "$(uname -s)" == "Darwin" ]]; then
46+
echo "$input" | base64 -D
47+
else
48+
echo "$input" | base64 -d
49+
fi
2650
fi
2751
}
2852

0 commit comments

Comments
 (0)