Skip to content

Commit 0119108

Browse files
committed
fix: implement authentication priority to prevent CLI hang
1 parent 2b6c074 commit 0119108

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

action.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ runs:
134134
fi
135135
136136
if [[ ${auth_methods} -gt 1 ]]; then
137-
warn "Multiple authentication methods provided. Please use only one of 'gemini_api_key', 'google_api_key', or 'gcp_workload_identity_provider'."
137+
echo "::notice title=Authentication priority::Multiple authentication methods provided. The action will prioritize them in the following order: 1. Workload Identity Federation, 2. Vertex AI API Key, 3. Gemini API Key. Conflicting environment variables will be unset for the CLI."
138138
fi
139139
140140
# Validate Workload Identity Federation inputs
@@ -260,6 +260,20 @@ runs:
260260
echo "Error: Gemini CLI not found in PATH"
261261
exit 1
262262
fi
263+
264+
# Sanitize authentication environment variables to avoid conflicts when installing extensions.
265+
if [[ -n "${GOOGLE_CLOUD_ACCESS_TOKEN:-}" ]]; then
266+
unset GEMINI_API_KEY
267+
unset GOOGLE_API_KEY
268+
elif [[ "${GOOGLE_GENAI_USE_VERTEXAI:-false}" == "true" && -n "${GOOGLE_API_KEY:-}" ]]; then
269+
unset GEMINI_API_KEY
270+
elif [[ -n "${GEMINI_API_KEY:-}" ]]; then
271+
export GOOGLE_GENAI_USE_VERTEXAI="false"
272+
export GOOGLE_GENAI_USE_GCA="false"
273+
unset GOOGLE_API_KEY
274+
unset GOOGLE_CLOUD_ACCESS_TOKEN
275+
fi
276+
263277
if [[ -n "${EXTENSIONS}" ]]; then
264278
echo "Installing Gemini CLI extensions:"
265279
echo "${EXTENSIONS}" | jq -r '.[]' | while IFS= read -r extension; do
@@ -289,6 +303,26 @@ runs:
289303
# Keep track of whether we've failed
290304
FAILED=false
291305
306+
# Sanitize authentication environment variables to avoid conflicts.
307+
# Priority:
308+
# 1. Workload Identity Federation (use_vertex_ai or use_gemini_code_assist with access token)
309+
# 2. Vertex AI API Key (use_vertex_ai with google_api_key)
310+
# 3. Gemini API Key (gemini_api_key)
311+
if [[ -n "${GOOGLE_CLOUD_ACCESS_TOKEN:-}" ]]; then
312+
echo "Using Workload Identity Federation; unsetting conflicting API keys."
313+
unset GEMINI_API_KEY
314+
unset GOOGLE_API_KEY
315+
elif [[ "${GOOGLE_GENAI_USE_VERTEXAI:-false}" == "true" && -n "${GOOGLE_API_KEY:-}" ]]; then
316+
echo "Using Vertex AI API Key; unsetting conflicting Gemini API key."
317+
unset GEMINI_API_KEY
318+
elif [[ -n "${GEMINI_API_KEY:-}" ]]; then
319+
echo "Using Gemini API Key; ensuring Vertex AI and Code Assist are disabled."
320+
export GOOGLE_GENAI_USE_VERTEXAI="false"
321+
export GOOGLE_GENAI_USE_GCA="false"
322+
unset GOOGLE_API_KEY
323+
unset GOOGLE_CLOUD_ACCESS_TOKEN
324+
fi
325+
292326
# Run Gemini CLI with the provided prompt, using JSON output format
293327
# We capture stdout (JSON) to TEMP_STDOUT and stderr to TEMP_STDERR
294328
if [[ "${GEMINI_DEBUG}" = true ]]; then

0 commit comments

Comments
 (0)