Skip to content

Commit 6fb331c

Browse files
feat: add file-based output mode to avoid exceeding GitHub Actions output limits
Add `output_to_file` input that redirects all output to files and returns file paths as step outputs instead of content. When enabled with `gemini_debug: true`, debug output goes to files without console streaming, keeping GITHUB_OUTPUT well under the ~1MB platform limit. New outputs: `output_mode` (content/file) and `artifacts_dir` (path to gemini-artifacts/). Full backwards compatibility when not set. Ref: #479
1 parent b0c9501 commit 6fb331c

File tree

1 file changed

+73
-33
lines changed

1 file changed

+73
-33
lines changed

action.yml

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ inputs:
8383
description: 'Whether to upload artifacts to the github action.'
8484
required: false
8585
default: 'false'
86+
output_to_file:
87+
description: 'When true, redirect all output to files and return file paths as step outputs instead of content. Useful when gemini_debug is true to avoid exceeding GitHub Actions output limits.'
88+
required: false
89+
default: 'false'
8690
use_pnpm:
8791
description: 'Whether or not to use pnpm instead of npm to install gemini-cli'
8892
required: false
@@ -107,6 +111,12 @@ outputs:
107111
error:
108112
description: 'The error output from the Gemini CLI execution, if any.'
109113
value: '${{ steps.gemini_run.outputs.gemini_errors }}'
114+
output_mode:
115+
description: 'Output mode used: "content" (default) or "file".'
116+
value: '${{ steps.gemini_run.outputs.output_mode }}'
117+
artifacts_dir:
118+
description: 'Path to gemini-artifacts/ directory containing stdout.log, stderr.log, telemetry.log.'
119+
value: '${{ steps.gemini_run.outputs.artifacts_dir }}'
110120

111121
runs:
112122
using: 'composite'
@@ -303,7 +313,12 @@ runs:
303313
304314
# Run Gemini CLI with the provided prompt, using JSON output format
305315
# We capture stdout (JSON) to TEMP_STDOUT and stderr to TEMP_STDERR
306-
if [[ "${GEMINI_DEBUG}" = true ]]; then
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
319+
FAILED=true
320+
fi
321+
elif [[ "${GEMINI_DEBUG}" = true ]]; then
307322
echo "::warning::Gemini CLI debug logging is enabled. This will stream responses, which could reveal sensitive information if processed with untrusted inputs."
308323
echo "::: Start Gemini CLI STDOUT :::"
309324
if ! gemini --debug --yolo --prompt "${PROMPT}" --output-format json 2> >(tee "${TEMP_STDERR}" >&2) | tee "${TEMP_STDOUT}"; then
@@ -349,23 +364,38 @@ runs:
349364
fi
350365
351366
352-
# Set the captured response as a step output, supporting multiline
353-
echo "gemini_response<<EOF" >> "${GITHUB_OUTPUT}"
354-
if [[ -n "${RESPONSE}" ]]; then
355-
echo "${RESPONSE}" >> "${GITHUB_OUTPUT}"
356-
else
357-
cat "${TEMP_STDOUT}" >> "${GITHUB_OUTPUT}"
358-
fi
359-
echo "EOF" >> "${GITHUB_OUTPUT}"
367+
ARTIFACTS_DIR="$(pwd)/gemini-artifacts"
368+
echo "artifacts_dir=${ARTIFACTS_DIR}" >> "${GITHUB_OUTPUT}"
360369
361-
# Set the captured errors as a step output, supporting multiline
362-
echo "gemini_errors<<EOF" >> "${GITHUB_OUTPUT}"
363-
if [[ -n "${ERROR_JSON}" ]]; then
364-
echo "${ERROR_JSON}" >> "${GITHUB_OUTPUT}"
370+
if [[ "${OUTPUT_TO_FILE}" = true ]]; then
371+
echo "output_mode=file" >> "${GITHUB_OUTPUT}"
372+
# Return file paths instead of content
373+
echo "gemini_response<<EOF" >> "${GITHUB_OUTPUT}"
374+
echo "${ARTIFACTS_DIR}/stdout.log" >> "${GITHUB_OUTPUT}"
375+
echo "EOF" >> "${GITHUB_OUTPUT}"
376+
echo "gemini_errors<<EOF" >> "${GITHUB_OUTPUT}"
377+
echo "${ARTIFACTS_DIR}/stderr.log" >> "${GITHUB_OUTPUT}"
378+
echo "EOF" >> "${GITHUB_OUTPUT}"
365379
else
366-
cat "${TEMP_STDERR}" >> "${GITHUB_OUTPUT}"
380+
echo "output_mode=content" >> "${GITHUB_OUTPUT}"
381+
# Set the captured response as a step output, supporting multiline
382+
echo "gemini_response<<EOF" >> "${GITHUB_OUTPUT}"
383+
if [[ -n "${RESPONSE}" ]]; then
384+
echo "${RESPONSE}" >> "${GITHUB_OUTPUT}"
385+
else
386+
cat "${TEMP_STDOUT}" >> "${GITHUB_OUTPUT}"
387+
fi
388+
echo "EOF" >> "${GITHUB_OUTPUT}"
389+
390+
# Set the captured errors as a step output, supporting multiline
391+
echo "gemini_errors<<EOF" >> "${GITHUB_OUTPUT}"
392+
if [[ -n "${ERROR_JSON}" ]]; then
393+
echo "${ERROR_JSON}" >> "${GITHUB_OUTPUT}"
394+
else
395+
cat "${TEMP_STDERR}" >> "${GITHUB_OUTPUT}"
396+
fi
397+
echo "EOF" >> "${GITHUB_OUTPUT}"
367398
fi
368-
echo "EOF" >> "${GITHUB_OUTPUT}"
369399
370400
# Generate Job Summary
371401
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
@@ -378,26 +408,35 @@ runs:
378408
echo "${PROMPT}"
379409
echo "\`\`\`"
380410
echo
381-
if [[ -n "${RESPONSE}" ]]; then
382-
echo "#### Response"
383-
echo
384-
echo "${RESPONSE}"
385-
echo
386-
fi
387-
if [[ -n "${ERROR_JSON}" ]]; then
388-
echo "#### Error"
389-
echo
390-
echo "\`\`\`json"
391-
echo "${ERROR_JSON}"
392-
echo "\`\`\`"
393-
echo
394-
elif [[ "${FAILED}" == "true" ]]; then
395-
echo "#### Error Output"
411+
if [[ "${OUTPUT_TO_FILE}" = true ]]; then
412+
echo "#### Output (file mode)"
396413
echo
397-
echo "\`\`\`"
398-
cat "${TEMP_STDERR}"
399-
echo "\`\`\`"
414+
echo "Output redirected to files:"
415+
echo "- stdout.log ($(wc -c < "${TEMP_STDOUT}" | xargs) bytes)"
416+
echo "- stderr.log ($(wc -c < "${TEMP_STDERR}" | xargs) bytes)"
400417
echo
418+
else
419+
if [[ -n "${RESPONSE}" ]]; then
420+
echo "#### Response"
421+
echo
422+
echo "${RESPONSE}"
423+
echo
424+
fi
425+
if [[ -n "${ERROR_JSON}" ]]; then
426+
echo "#### Error"
427+
echo
428+
echo "\`\`\`json"
429+
echo "${ERROR_JSON}"
430+
echo "\`\`\`"
431+
echo
432+
elif [[ "${FAILED}" == "true" ]]; then
433+
echo "#### Error Output"
434+
echo
435+
echo "\`\`\`"
436+
cat "${TEMP_STDERR}"
437+
echo "\`\`\`"
438+
echo
439+
fi
401440
fi
402441
} >> "${GITHUB_STEP_SUMMARY}"
403442
fi
@@ -415,6 +454,7 @@ runs:
415454
fi
416455
env:
417456
GEMINI_DEBUG: '${{ fromJSON(inputs.gemini_debug || false) }}'
457+
OUTPUT_TO_FILE: '${{ fromJSON(inputs.output_to_file || false) }}'
418458
GEMINI_API_KEY: '${{ inputs.gemini_api_key }}'
419459
SURFACE: 'GitHub'
420460
GOOGLE_CLOUD_PROJECT: '${{ inputs.gcp_project_id }}'

0 commit comments

Comments
 (0)