@@ -71,6 +71,10 @@ inputs:
7171 extensions :
7272 description : ' A list of Gemini CLI extensions to install.'
7373 required : false
74+ upload_artifacts :
75+ description : ' Whether or not to upload artifacts to the github action.'
76+ required : false
77+ default : ' false'
7478
7579outputs :
7680 summary :
@@ -183,26 +187,6 @@ runs:
183187 token_format : ' access_token'
184188 access_token_scopes : ' https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile'
185189
186- - name : ' Run Telemetry Collector for Google Cloud'
187- if : |-
188- ${{ inputs.gcp_workload_identity_provider != '' }}
189- env :
190- OTLP_GOOGLE_CLOUD_PROJECT : ' ${{ inputs.gcp_project_id }}'
191- GITHUB_ACTION_PATH : ' ${{ github.action_path }}'
192- shell : ' bash'
193- run : |-
194- set -euo pipefail
195- mkdir -p .gemini/
196- sed "s/OTLP_GOOGLE_CLOUD_PROJECT/${OTLP_GOOGLE_CLOUD_PROJECT}/g" "${GITHUB_ACTION_PATH}/scripts/collector-gcp.yaml.template" > ".gemini/collector-gcp.yaml"
197-
198- chmod 444 "$GOOGLE_APPLICATION_CREDENTIALS"
199- docker run -d --name gemini-telemetry-collector --network host \
200- -v "${GITHUB_WORKSPACE}:/github/workspace" \
201- -e "GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS/$GITHUB_WORKSPACE//github/workspace}" \
202- -w "/github/workspace" \
203- otel/opentelemetry-collector-contrib:0.128.0 \
204- --config /github/workspace/.gemini/collector-gcp.yaml
205-
206190 - name : ' Install Gemini CLI'
207191 id : ' install'
208192 env :
@@ -274,22 +258,29 @@ runs:
274258 fi
275259 fi
276260
277- GEMINI_RESPONSE="$(cat "${TEMP_STDOUT}")"
261+ # Create the artifacts directory and copy full logs
262+ mkdir -p gemini-artifacts
263+ cp "${TEMP_STDOUT}" gemini-artifacts/stdout.log
264+ cp "${TEMP_STDERR}" gemini-artifacts/stderr.log
265+ if [[ -f .gemini/telemetry.log ]]; then
266+ cp .gemini/telemetry.log gemini-artifacts/telemetry.log
267+ else
268+ # Create an empty file so the artifact upload doesn't fail if telemetry is missing
269+ touch gemini-artifacts/telemetry.log
270+ fi
278271
279272 # Set the captured response as a step output, supporting multiline
280273 echo "gemini_response<<EOF" >> "${GITHUB_OUTPUT}"
281- echo "${GEMINI_RESPONSE }" >> "${GITHUB_OUTPUT}"
274+ cat "${TEMP_STDOUT }" >> "${GITHUB_OUTPUT}"
282275 echo "EOF" >> "${GITHUB_OUTPUT}"
283276
284- GEMINI_ERRORS="$(cat "${TEMP_STDERR}")"
285-
286277 # Set the captured errors as a step output, supporting multiline
287278 echo "gemini_errors<<EOF" >> "${GITHUB_OUTPUT}"
288- echo "${GEMINI_ERRORS }" >> "${GITHUB_OUTPUT}"
279+ cat "${TEMP_STDERR }" >> "${GITHUB_OUTPUT}"
289280 echo "EOF" >> "${GITHUB_OUTPUT}"
290281
291282 if [[ "${FAILED}" = true ]]; then
292- LAST_LINE="$(echo "${GEMINI_ERRORS}" | tail -n1 )"
283+ LAST_LINE="$(tail -n1 "${TEMP_STDERR}" )"
293284 echo "::error title=Gemini CLI execution failed::${LAST_LINE}"
294285 echo "See logs for more details"
295286 exit 1
@@ -307,6 +298,82 @@ runs:
307298 PROMPT : ' ${{ inputs.prompt }}'
308299 GEMINI_MODEL : ' ${{ inputs.gemini_model }}'
309300
301+ - name : ' Upload Gemini CLI outputs'
302+ if : |-
303+ ${{ inputs.upload_artifacts }}
304+ uses : ' actions/upload-artifact@v4' # ratchet:exclude
305+ with :
306+ name : ' gemini-output'
307+ path : ' gemini-artifacts/'
308+
309+ - name : ' Upload Telemetry to Google Cloud'
310+ if : |-
311+ ${{ inputs.gcp_workload_identity_provider != '' }}
312+ shell : ' bash'
313+ run : |-
314+ set -euo pipefail
315+
316+ # If the telemetry log doesn't exist or is empty, do nothing.
317+ if [[ ! -s ".gemini/telemetry.log" ]]; then
318+ echo "No telemetry log found, skipping upload."
319+ exit 0
320+ fi
321+
322+ # Generate the real config file from the template
323+ sed -e "s#OTLP_GOOGLE_CLOUD_PROJECT#${OTLP_GOOGLE_CLOUD_PROJECT}#g" \
324+ -e "s#GITHUB_REPOSITORY_PLACEHOLDER#${GITHUB_REPOSITORY}#g" \
325+ -e "s#GITHUB_RUN_ID_PLACEHOLDER#${GITHUB_RUN_ID}#g" \
326+ "${GITHUB_ACTION_PATH}/scripts/collector-gcp.yaml.template" > ".gemini/collector-gcp.yaml"
327+
328+ # Ensure credentials file has the right permissions
329+ chmod 444 "$GOOGLE_APPLICATION_CREDENTIALS"
330+
331+ # Run the collector in the background with a known name
332+ docker run --rm --name gemini-telemetry-collector --network host \
333+ -v "${GITHUB_WORKSPACE}:/github/workspace" \
334+ -e "GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS/$GITHUB_WORKSPACE//github/workspace}" \
335+ -w "/github/workspace" \
336+ otel/opentelemetry-collector-contrib:0.108.0 \
337+ --config /github/workspace/.gemini/collector-gcp.yaml &
338+
339+ # Wait for the collector to start up
340+ echo "Waiting for collector to initialize..."
341+ sleep 10
342+
343+ # Monitor the queue until it's empty or we time out
344+ echo "Monitoring exporter queue..."
345+ ATTEMPTS=0
346+ MAX_ATTEMPTS=12 # 12 * 5s = 60s timeout
347+ while true; do
348+ # Use -f to fail silently if the server isn't ready yet
349+ # Filter out the prometheus help/type comments before grabbing the value
350+ QUEUE_SIZE=$(curl -sf http://localhost:8888/metrics | grep otelcol_exporter_queue_size | grep -v '^#' | awk '{print $2}' || echo "-1")
351+
352+ if [ "$QUEUE_SIZE" == "0" ]; then
353+ echo "Exporter queue is empty, all data processed."
354+ break
355+ fi
356+
357+ if [ "$ATTEMPTS" -ge "$MAX_ATTEMPTS" ]; then
358+ echo "::warning::Timed out waiting for exporter queue to empty. Proceeding with shutdown."
359+ break
360+ fi
361+
362+ echo "Queue size: $QUEUE_SIZE, waiting..."
363+ sleep 5
364+ ATTEMPTS=$((ATTEMPTS + 1))
365+ done
366+
367+ # Gracefully shut down the collector
368+ echo "Stopping collector..."
369+ docker stop gemini-telemetry-collector
370+ echo "Collector stopped."
371+ env :
372+ OTLP_GOOGLE_CLOUD_PROJECT : ' ${{ inputs.gcp_project_id }}'
373+ GITHUB_ACTION_PATH : ' ${{ github.action_path }}'
374+ GITHUB_REPOSITORY : ' ${{ github.repository }}'
375+ GITHUB_RUN_ID : ' ${{ github.run_id }}'
376+
310377branding :
311378 icon : ' terminal'
312379 color : ' blue'
0 commit comments