Skip to content

Commit badefcd

Browse files
refactor: decouple output_to_file from gemini_debug
Check output_to_file first, independently of debug mode. The debug flag only controls whether --debug is passed to gemini CLI. Also extract command args to avoid duplicating the gemini invocation. Ref: #479
1 parent 6fb331c commit badefcd

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

action.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,24 +311,30 @@ runs:
311311
# Keep track of whether we've failed
312312
FAILED=false
313313
314+
# Build the base command arguments
315+
GEMINI_ARGS="--yolo --prompt ${PROMPT} --output-format json"
316+
if [[ "${GEMINI_DEBUG}" = true ]]; then
317+
GEMINI_ARGS="--debug ${GEMINI_ARGS}"
318+
fi
319+
314320
# Run Gemini CLI with the provided prompt, using JSON output format
315321
# We capture stdout (JSON) to TEMP_STDOUT and stderr to TEMP_STDERR
316-
if [[ "${GEMINI_DEBUG}" = true ]] && [[ "${OUTPUT_TO_FILE}" = true ]]; then
317-
echo "::notice::Gemini CLI debug output redirected to files (gemini-artifacts/)"
318-
if ! gemini --debug --yolo --prompt "${PROMPT}" --output-format json 2> "${TEMP_STDERR}" 1> "${TEMP_STDOUT}"; then
322+
if [[ "${OUTPUT_TO_FILE}" = true ]]; then
323+
echo "::notice::Gemini CLI output redirected to files (gemini-artifacts/)"
324+
if ! gemini ${GEMINI_ARGS} 2> "${TEMP_STDERR}" 1> "${TEMP_STDOUT}"; then
319325
FAILED=true
320326
fi
321327
elif [[ "${GEMINI_DEBUG}" = true ]]; then
322328
echo "::warning::Gemini CLI debug logging is enabled. This will stream responses, which could reveal sensitive information if processed with untrusted inputs."
323329
echo "::: Start Gemini CLI STDOUT :::"
324-
if ! gemini --debug --yolo --prompt "${PROMPT}" --output-format json 2> >(tee "${TEMP_STDERR}" >&2) | tee "${TEMP_STDOUT}"; then
330+
if ! gemini ${GEMINI_ARGS} 2> >(tee "${TEMP_STDERR}" >&2) | tee "${TEMP_STDOUT}"; then
325331
FAILED=true
326332
fi
327333
# Wait for async stderr logging to complete. This is because process substitution in Bash is async so let tee finish writing to ${TEMP_STDERR}
328334
sleep 1
329335
echo "::: End Gemini CLI STDOUT :::"
330336
else
331-
if ! gemini --yolo --prompt "${PROMPT}" --output-format json 2> "${TEMP_STDERR}" 1> "${TEMP_STDOUT}"; then
337+
if ! gemini ${GEMINI_ARGS} 2> "${TEMP_STDERR}" 1> "${TEMP_STDOUT}"; then
332338
FAILED=true
333339
fi
334340
fi

0 commit comments

Comments
 (0)