$ show Mozilla-Actions/sccache-action
This repository is a GitHub Action written in TypeScript that installs and configures Mozilla's sccache compilation cache inside GitHub Actions workflows. The main entry point (src/setup.ts) reads a version input; if none is given, it queries the GitHub API for the latest sccache release. It then downloads the platform-specific binary from sccache's GitHub releases, verifies the downloaded archive's SHA-256 checksum against the released .sha256 sidecar, extracts it, caches it in the Actions tool directory, adds it to PATH, exports SCCACHE_PATH, and sets ACTIONS_CACHE_SERVICE_V2 plus result URL/token environment variables so sccache can use GitHub Actions cache as its backend. A post step (src/show_stats.ts) runs `sccache --show-stats --stats-format=json`, parses the output, and posts a job annotation and job summary with cache hit/miss/error counts, hit ratio, and durations. Architecturally this is a small two-entry-point action bundled with ncc. The source is strict TypeScript with ESLint, Prettier, and a CI workflow that verifies committed dist bundles match a clean rebuild. It has no real unit tests (jest runs with --passWithNoTests) and a few minor flaws: the zip-extraction branch is dead code because getExtension() always returns 'tar.gz'; unsupported architectures/platforms produce malformed download URLs rather than clean failures; and the displayed cache percentage shows 0% when there are zero requests (e.g., no cache hits). Despite these issues, the code is clear, uses byte-level checksum verification, handles sccache's missing trailing newline in JSON output, and integrates well with GitHub's logging and summary APIs. It is an actively maintained, low-drift repository.
The LLM identified 2 files worth highlighting for reuse:
The `format_json_stats` function and its helpers (`sum_stats`, `format_duration`, `percentage`, `plural`) convert sccache's raw JSON statistics into a percentage, a human-readable notice, and a structured summary table for GitHub's job summary API. It correctly patches the missing trailing newline in sccache's `--stats-format=json` output and uses GitHub Actions groups for clean log organization. This pure transformation logic is self-contained and can be lifted into any CI reporting tool that consumes sccache stats; its only dependency is the internal `SummaryTableRow` type from @actions/core.
`downloadSCCache` implements a defensible binary-install flow: it downloads both the release archive and its `.sha256` sidecar, hashes the archive with Node's crypto module, compares the checksums, extracts the archive, and caches the result via @actions/tool-cache. On checksum mismatch it returns an Error and the action fails rather than running an untrusted binary. This download-verify-extract-cache pattern is directly reusable in any GitHub Action that installs a versioned CLI tool from GitHub Releases.