Skip to content

Commit 5bd87f5

Browse files
authored
fix: fetch AIC logs per workflow to avoid truncation in busy repos
2 parents 95b020b + da5d057 commit 5bd87f5

4 files changed

Lines changed: 127 additions & 55 deletions

File tree

.github/workflows/agentic-token-audit.lock.yml

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/agentic-token-audit.md

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,61 @@ steps:
5050
run: |
5151
set -euo pipefail
5252
mkdir -p /tmp/gh-aw/token-audit
53+
PARTS_DIR=/tmp/gh-aw/token-audit/log-parts
54+
mkdir -p "$PARTS_DIR"
55+
56+
# Fetch logs per workflow to avoid repo-wide pagination truncation in
57+
# high-CI-volume repositories.
58+
FOUND_WORKFLOW=0
59+
for workflow in .github/workflows/*.md; do
60+
[ -f "$workflow" ] || continue
61+
62+
WORKFLOW_ID=$(sed -n 's/^tracker-id:[[:space:]]*//p' "$workflow" | head -n 1 | tr -d '\r' | sed 's/[[:space:]]*$//')
63+
[ -n "$WORKFLOW_ID" ] || continue
64+
65+
FOUND_WORKFLOW=1
66+
SAFE_WORKFLOW_ID=$(printf '%s' "$WORKFLOW_ID" | tr -cs 'A-Za-z0-9._-' '_')
67+
PART_FILE="$PARTS_DIR/$SAFE_WORKFLOW_ID.json"
68+
PART_EXIT=0
69+
gh aw logs "$WORKFLOW_ID" \
70+
--start-date -1d \
71+
--json \
72+
-c 100 \
73+
> "$PART_FILE" || PART_EXIT=$?
74+
75+
if ! jq -e . "$PART_FILE" >/dev/null 2>&1; then
76+
echo "⚠️ $WORKFLOW_ID: invalid log JSON (exit code $PART_EXIT)"
77+
rm -f "$PART_FILE"
78+
continue
79+
fi
5380
54-
# Download last 24 hours of agentic workflow logs as JSON
55-
# Allow partial results — gh aw logs streams incrementally, so even if
56-
# it hits an API rate limit partway through, the JSON written so far is
57-
# still valid and should be processed by the agent.
58-
LOGS_EXIT=0
59-
gh aw logs \
60-
--start-date -1d \
61-
--json \
62-
-c 100 \
63-
> /tmp/gh-aw/token-audit/workflow-logs.json || LOGS_EXIT=$?
64-
65-
if [ -s /tmp/gh-aw/token-audit/workflow-logs.json ]; then
81+
COUNT=$(jq '(.runs // []) | length' "$PART_FILE")
82+
if [ "$COUNT" -gt 0 ]; then
83+
echo "✅ $WORKFLOW_ID: downloaded $COUNT runs (exit code $PART_EXIT)"
84+
else
85+
echo "⚠️ $WORKFLOW_ID: no log data (exit code $PART_EXIT)"
86+
rm -f "$PART_FILE"
87+
fi
88+
done
89+
90+
if [ "$FOUND_WORKFLOW" -eq 1 ] && ls "$PARTS_DIR"/*.json >/dev/null 2>&1; then
91+
jq -s '
92+
(map(.runs // []) | add // [] | unique_by(.run_id)) as $runs |
93+
{
94+
summary: {
95+
total_runs: ($runs | length),
96+
total_tokens: ($runs | map(.token_usage // 0) | add // 0),
97+
total_aic: ($runs | map(.aic // 0) | add // 0)
98+
},
99+
runs: $runs
100+
}
101+
' "$PARTS_DIR"/*.json > /tmp/gh-aw/token-audit/workflow-logs.json
66102
TOTAL=$(jq '.runs | length' /tmp/gh-aw/token-audit/workflow-logs.json)
67103
echo "✅ Downloaded $TOTAL agentic workflow runs (last 24 hours)"
68-
if [ "$LOGS_EXIT" -ne 0 ]; then
69-
echo "⚠️ gh aw logs exited with code $LOGS_EXIT (partial results — likely API rate limit)"
70-
fi
71104
else
72-
echo "❌ No log data downloaded (exit code $LOGS_EXIT)"
105+
if [ "$FOUND_WORKFLOW" -eq 0 ]; then
106+
echo "⚠️ No agentic workflow sources found under .github/workflows"
107+
fi
73108
echo '{"runs":[],"summary":{}}' > /tmp/gh-aw/token-audit/workflow-logs.json
74109
fi
75110
timeout-minutes: 25

0 commit comments

Comments
 (0)