Skip to content

Commit 065b613

Browse files
committed
ci: add sccache summary to CI workflow
1 parent e80a151 commit 065b613

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

.github/workflows/ci.yml

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,66 @@ jobs:
9494
- name: Show sccache stats
9595
if: always()
9696
shell: bash
97-
run: sccache --show-stats || true
97+
run: |
98+
mkdir -p .ci
99+
sccache --show-stats 2>&1 | tee .ci/sccache-stats.txt || true
100+
101+
- name: Summarize sccache stats
102+
if: always()
103+
shell: bash
104+
run: |
105+
STATS_FILE=".ci/sccache-stats.txt"
106+
if [ ! -f "$STATS_FILE" ]; then
107+
echo "No sccache stats file found."
108+
exit 0
109+
fi
110+
111+
stats="$(cat "$STATS_FILE")"
112+
113+
extract_field() {
114+
local pattern="$1"
115+
local result
116+
result="$(printf '%s\n' "$stats" | awk -v pat="$pattern" '$0 ~ pat {print $NF; exit}')"
117+
if [ -z "$result" ]; then
118+
echo "N/A"
119+
else
120+
echo "$result"
121+
fi
122+
}
123+
124+
cache_hits="$(extract_field '^Cache hits[[:space:]]')"
125+
cache_misses="$(extract_field '^Cache misses[[:space:]]')"
126+
compile_requests="$(extract_field '^Compile requests[[:space:]]')"
127+
compile_executed="$(extract_field '^Compile requests executed[[:space:]]')"
128+
compile_errors="$(extract_field '^Compile errors[[:space:]]')"
129+
cache_hit_rate="$(printf '%s\n' "$stats" | awk '/^Cache hits rate[[:space:]]/ {print $(NF-1) " " $NF; exit}')"
130+
if [ -z "$cache_hit_rate" ]; then
131+
cache_hit_rate="$(printf '%s\n' "$stats" | awk '/^Cache hit rate[[:space:]]/ {print $(NF-1) " " $NF; exit}')"
132+
fi
133+
if [ -z "$cache_hit_rate" ]; then
134+
cache_hit_rate="N/A"
135+
fi
136+
137+
{
138+
echo "### sccache summary"
139+
echo ""
140+
echo "| Metric | Value |"
141+
echo "| --- | --- |"
142+
echo "| Compile requests | ${compile_requests} |"
143+
echo "| Compile requests executed | ${compile_executed} |"
144+
echo "| Cache hits | ${cache_hits} |"
145+
echo "| Cache misses | ${cache_misses} |"
146+
echo "| Cache hit rate | ${cache_hit_rate} |"
147+
echo "| Compile errors | ${compile_errors} |"
148+
echo ""
149+
echo "<details><summary>Full <code>sccache --show-stats</code></summary>"
150+
echo ""
151+
echo '```text'
152+
cat "$STATS_FILE"
153+
echo '```'
154+
echo "</details>"
155+
} >> "$GITHUB_STEP_SUMMARY"
156+
157+
if [ "$cache_hits" = "0" ] && [ "$cache_misses" = "0" ]; then
158+
echo "::notice title=sccache::No cache activity detected (hits=0, misses=0)."
159+
fi

0 commit comments

Comments
 (0)