Skip to content

Commit 360e88b

Browse files
committed
fix: resolve hang by prioritizing authentication and unsetting conflicting credentials (minimal)
1 parent af23e99 commit 360e88b

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

action.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ runs:
316316
if [[ -n "${GOOGLE_CLOUD_ACCESS_TOKEN:-}" ]]; then
317317
unset GEMINI_API_KEY
318318
unset GOOGLE_API_KEY
319-
# Unset credential file pointers that might cause conflicts with the access token.
319+
# Unset credential file pointers that might cause conflicts with the access token and hang.
320320
unset CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE
321321
unset GOOGLE_GHA_CREDS_PATH
322322
elif [[ "${GOOGLE_GENAI_USE_VERTEXAI:-false}" == "true" && -n "${GOOGLE_API_KEY:-}" ]]; then
@@ -332,16 +332,32 @@ runs:
332332
# We capture stdout (JSON) to TEMP_STDOUT and stderr to TEMP_STDERR
333333
if [[ "${GEMINI_DEBUG}" = true ]]; then
334334
echo "::warning::Gemini CLI debug logging is enabled. This will stream responses, which could reveal sensitive information if processed with untrusted inputs."
335+
echo "::: Start Gemini CLI STDOUT :::"
335336
if ! gemini --debug --yolo --prompt "${PROMPT}" --output-format json 2> >(tee "${TEMP_STDERR}" >&2) | tee "${TEMP_STDOUT}"; then
336337
FAILED=true
337338
fi
339+
# Wait for async stderr logging to complete. This is because process substitution in Bash is async so let tee finish writing to ${TEMP_STDERR}
340+
sleep 1
341+
echo "::: End Gemini CLI STDOUT :::"
338342
else
339343
if ! gemini --yolo --prompt "${PROMPT}" --output-format json 2> "${TEMP_STDERR}" 1> "${TEMP_STDOUT}"; then
340344
FAILED=true
341345
fi
342346
fi
343347
348+
# Create the artifacts directory and copy full logs
349+
mkdir -p gemini-artifacts
350+
cp "${TEMP_STDOUT}" gemini-artifacts/stdout.log
351+
cp "${TEMP_STDERR}" gemini-artifacts/stderr.log
352+
if [[ -f .gemini/telemetry.log ]]; then
353+
cp .gemini/telemetry.log gemini-artifacts/telemetry.log
354+
else
355+
# Create an empty file so the artifact upload doesn't fail if telemetry is missing
356+
touch gemini-artifacts/telemetry.log
357+
fi
358+
344359
# Parse JSON output to extract response and errors
360+
# If output is not valid JSON, RESPONSE will be empty and we'll rely on stderr for errors
345361
RESPONSE=""
346362
ERROR_JSON=""
347363
if jq -e . "${TEMP_STDOUT}" >/dev/null 2>&1; then
@@ -357,21 +373,32 @@ runs:
357373
fi
358374
fi
359375
360-
# Use a unique delimiter to avoid collisions for multiline outputs
376+
if { [[ -s "${TEMP_STDERR}" ]] && [[ -z "${ERROR_JSON}" ]]; }; then
377+
echo "::warning::Gemini CLI stderr contains data but no valid JSON error object was extracted"
378+
fi
379+
380+
if { [[ -s "${TEMP_STDOUT}" ]] && ! jq -e . "${TEMP_STDOUT}" >/dev/null 2>&1; }; then
381+
echo "::warning::Gemini CLI stdout was not valid JSON"
382+
fi
383+
384+
385+
# Set the captured response as a step output, supporting multiline
386+
# Use a unique delimiter to avoid collisions
361387
EOF_DELIMITER="gh_gemini_out_$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)"
362388
363389
echo "gemini_response<<${EOF_DELIMITER}" >> "${GITHUB_OUTPUT}"
364390
if [[ -n "${RESPONSE}" ]]; then
365391
echo "${RESPONSE}" >> "${GITHUB_OUTPUT}"
366-
elif [[ -s "${TEMP_STDOUT}" ]]; then
392+
else
367393
cat "${TEMP_STDOUT}" >> "${GITHUB_OUTPUT}"
368394
fi
369395
echo "${EOF_DELIMITER}" >> "${GITHUB_OUTPUT}"
370396
397+
# Set the captured errors as a step output, supporting multiline
371398
echo "gemini_errors<<${EOF_DELIMITER}" >> "${GITHUB_OUTPUT}"
372399
if [[ -n "${ERROR_JSON}" ]]; then
373400
echo "${ERROR_JSON}" >> "${GITHUB_OUTPUT}"
374-
elif [[ -s "${TEMP_STDERR}" ]]; then
401+
else
375402
cat "${TEMP_STDERR}" >> "${GITHUB_OUTPUT}"
376403
fi
377404
echo "${EOF_DELIMITER}" >> "${GITHUB_OUTPUT}"
@@ -417,6 +444,9 @@ runs:
417444
ERROR_MSG=$(jq -r '.message // .' <<< "${ERROR_JSON}")
418445
echo "::error title=Gemini CLI execution failed::${ERROR_MSG}"
419446
fi
447+
echo "::: Start Gemini CLI STDERR :::"
448+
cat "${TEMP_STDERR}"
449+
echo "::: End Gemini CLI STDERR :::"
420450
exit 1
421451
fi
422452
env:

0 commit comments

Comments
 (0)