Skip to content

BUILD-11555 Emit cache metrics JSON on all platforms; restrict size measurement to Linux - #83

Merged
julien-carsique-sonarsource merged 1 commit into
masterfrom
feat/jcarsique/BUILD-cache-metrics-cross-platform
Jun 9, 2026
Merged

julien-carsique-sonarsource merged 1 commit into
masterfrom
feat/jcarsique/BUILD-cache-metrics-cross-platform

Conversation

@julien-carsique-sonarsource

@julien-carsique-sonarsource julien-carsique-sonarsource commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The process.platform !== 'linux' guards in cache-metrics-main and cache-metrics-post were blocking all metrics functionality on macOS and Windows — including the entirely cross-platform JSON writing. Only measureCacheBytes() genuinely requires Linux (GNU du -sb).

What changes:

  • JSON records (cache_hit, key, backend, restore_key_hit, saved, timestamps) are now written on all platforms
  • Size fields (size_bytes_restored, size_bytes_at_end) remain null on non-Linux
  • cache-size-bytes output is only set on Linux (unchanged from today)
  • State (metricsFile, path, cacheHit, lookupOnly) is now saved on all platforms so the post step can update the record

What does NOT change:

  • The gate mechanism (CI_METRICS_ENABLED) — the runner pre-job hook only runs on Linux today, so macOS/Windows users would need env: CI_METRICS_ENABLED: 'true' to opt in explicitly
  • github-runners-infra, ci-ami-images, ci-github-actions — no changes

Test plan

  • All 54 unit tests pass
  • Pre-commit passes
  • test-s3-cache-windows CI job implicitly verifies JSON is written without crashing on Windows

Comment thread README.md Resolved
@julien-carsique-sonarsource julien-carsique-sonarsource changed the title Emit cache metrics JSON on all platforms; restrict size measurement to Linux BUILD-11444 Emit cache metrics JSON on all platforms; restrict size measurement to Linux Jun 8, 2026
@julien-carsique-sonarsource julien-carsique-sonarsource changed the title BUILD-11444 Emit cache metrics JSON on all platforms; restrict size measurement to Linux BUILD-11555 Emit cache metrics JSON on all platforms; restrict size measurement to Linux Jun 8, 2026
@julien-carsique-sonarsource
julien-carsique-sonarsource force-pushed the feat/jcarsique/BUILD-cache-metrics-cross-platform branch from f6f9997 to b85bf0e Compare June 8, 2026 16:37
…easurement to Linux

Remove the process.platform !== 'linux' early-return guards from the
cache-metrics main and post steps. The JSON record (cache_hit, key,
backend, restore_key_hit, saved, timestamps) is now written on every
platform. Size fields (size_bytes_restored, size_bytes_at_end) are null
on non-Linux where GNU du is unavailable; cache-size-bytes output is
only set on Linux.

Update action.yml output description, README, and tests accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@julien-carsique-sonarsource
julien-carsique-sonarsource force-pushed the feat/jcarsique/BUILD-cache-metrics-cross-platform branch from 3045ea8 to 623b1e3 Compare June 8, 2026 17:02
@sonarqubecloud

sonarqubecloud Bot commented Jun 8, 2026

Copy link
Copy Markdown

@sonarqube-cloud-us

Copy link
Copy Markdown

@julien-carsique-sonarsource
julien-carsique-sonarsource merged commit 8f750b6 into master Jun 9, 2026
28 checks passed
@julien-carsique-sonarsource
julien-carsique-sonarsource deleted the feat/jcarsique/BUILD-cache-metrics-cross-platform branch June 9, 2026 07:34
@gitar-bot

gitar-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Enables cross-platform cache metrics by decoupling JSON record writing from Linux-specific size measurement. The gate step logic has been updated to support non-Linux execution, resolving the unreachable metrics finding.

✅ 1 resolved
✅ Bug: Cross-platform metrics unreachable: gate step is Linux-only

📄 action.yml:251-265 📄 action.yml:307-310 📄 README.md:156-162 📄 src/cache-metrics-main.ts:11-18
This PR removes the process.platform !== 'linux' early-returns from cache-metrics-main.ts / cache-metrics-post.ts and updates README.md and the action.yml output description to claim "The JSON record is written on all platforms." However, the composite action in action.yml (unchanged by this PR) still prevents the metrics sub-action from ever executing on non-Linux runners:

  • The Resolve CI metrics gate step (line 251) has if: runner.os == 'Linux', so steps.ci-metrics-gate.outputs.decision is only ever set on Linux.
  • Prepare local cache-metrics sub-action (line 286) runs only if: steps.ci-metrics-gate.outputs.decision == 'true'.
  • Emit cache metrics (line 308) runs only if: steps.cache-metrics-prep.outputs.prepared == 'true'.

On macOS/Windows the gate step is skipped, decision is empty, prep is skipped, and the metrics step never runs. The PR description even states the intended opt-in path is env: CI_METRICS_ENABLED: 'true', but that env var is only consulted inside the Linux-gated gate step, so it has no effect on non-Linux. As a result, the new cross-platform code paths are dead when invoked through this composite action, and the updated documentation ("written on all platforms") is inaccurate.

Suggested fix: either (a) make the gate/prep/metrics steps run on all platforms (e.g. remove if: runner.os == 'Linux' from the gate step and provide a non-Linux gate resolution), or (b) soften the README/action.yml wording to clarify that, today, the JSON record is still only emitted on Linux runners via this action, even though the underlying scripts are platform-agnostic. The unit tests pass because they import and call run() directly, bypassing the action.yml gating.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

This branch was previously deployed

1 inactive deployment
sca-checking — 623b1e39 Deployed Jun 8, 2026 by julien-carsique-sonarsource via verify-sca #60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants