Skip to content

Commit df6eba2

Browse files
authored
fix(action): Unset empty gemini_api_key environment variable (#127)
GitHub Actions defaults to passing an empty string for optional inputs that are not explicitly set in a workflow. When the `gemini_api_key` input is unset, it is passed as an empty string to the `GEMINI_API_KEY` environment variable. The Gemini CLI does not handle an empty `GEMINI_API_KEY` variable gracefully, which can lead to unexpected behavior. This commit addresses the issue by explicitly checking if the `GEMINI_API_KEY` variable is empty (`-z`). If it is, the variable is unset before invoking the Gemini CLI. This ensures the CLI's default authentication behavior (e.g., using Application Default Credentials) is triggered correctly when no API key is provided, improving the action's robustness and predictability. >Note: This is a temporary workaround to unblock users. The underlying issue of handling empty string inputs will be addressed with improved validation in the Gemini CLI upstream. Fixes: #123
1 parent 7d94f07 commit df6eba2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,15 @@ runs:
140140
id: 'gemini_run'
141141
run: |-
142142
set -e
143+
144+
# Unset GEMINI_API_KEY if empty
145+
if [ -z "${GEMINI_API_KEY}" ]; then
146+
unset GEMINI_API_KEY
147+
fi
148+
149+
# Run Gemini CLI with the provided prompt
143150
GEMINI_RESPONSE=$(gemini --yolo --prompt "${PROMPT}")
151+
144152
# Set the captured response as a step output, supporting multiline
145153
echo "gemini_response<<EOF" >> "${GITHUB_OUTPUT}"
146154
echo "${GEMINI_RESPONSE}" >> "${GITHUB_OUTPUT}"

0 commit comments

Comments
 (0)