Files
solvecraft/.github/actions/cpp-reference/action.yml
T
Brett Lawson ad4e4c1aa8 ci: pin sccache-action's sccache version so jobs stop calling the REST API
Without a version input, mozilla-actions/sccache-action looks up sccache's
latest release through the REST API in every job that sets up the C++
reference (clippy, test and the four difftest jobs). Those calls spend the
repository's GITHUB_TOKEN quota, and once it runs out the step fails with
"API rate limit exceeded for installation", failing the job.

With a version the action downloads the release asset directly. v0.19.0 is
the release the latest lookup resolves to today, so CI behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MNXLXj2sJf943y2dDF36Vy
2026-10-30 19:48:27 +01:00

102 lines
4.3 KiB
YAML

name: C++ reference
description: >
Clones upstream at the pinned commit, enables sccache and installs the C++ reference
(bin/cpp layout) into $SOLIDCORE_CPP_DIR, so the cpp feature of solidcore-ffi builds.
Expects SOLIDCORE_CPP_DIR in the job environment; the upstream pin (UPSTREAM_REPO,
UPSTREAM_VERSION, UPSTREAM_COMMIT) comes from scripts/upstream-pin.env unless the job
environment already sets it.
runs:
using: composite
steps:
- name: Load upstream pin
shell: bash
run: |
while IFS='=' read -r k v; do
case "$k" in
UPSTREAM_REPO|UPSTREAM_VERSION|UPSTREAM_COMMIT)
if [ -z "${!k:-}" ]; then echo "$k=$v" >> "$GITHUB_ENV"; fi ;;
esac
done < scripts/upstream-pin.env
- name: Clone upstream at pinned commit
shell: bash
run: |
git init upstream
git -C upstream remote add origin "$UPSTREAM_REPO"
git -C upstream fetch --depth 1 origin "$UPSTREAM_COMMIT" \
|| git -C upstream fetch origin
git -C upstream checkout --detach "$UPSTREAM_COMMIT"
# sccache caches the ~200 shim objects solidcore-ffi compiles (the cc crate wraps the
# C++ compiler in RUSTC_WRAPPER when it is sccache) and the workspace crates, which
# rust-cache does not keep; both survive across runs in the GitHub Actions cache.
# A pinned version is downloaded straight from the release URL; without one the
# action asks the REST API for the latest release on every job, which spends the
# repository's GITHUB_TOKEN quota and fails the job once it runs out.
- name: Set up sccache
uses: mozilla-actions/sccache-action@v0.0.11
with:
version: v0.19.0
- name: Enable sccache
shell: bash
run: |
echo "SCCACHE_GHA_ENABLED=true" >> "$GITHUB_ENV"
echo "RUSTC_WRAPPER=sccache" >> "$GITHUB_ENV"
# The difftest run is idle for sccache for minutes; without this the server
# exits after 10 idle minutes and the stats printed at the end read zero.
echo "SCCACHE_IDLE_TIMEOUT=0" >> "$GITHUB_ENV"
# Start the server now, so a cache-storage outage (the Actions cache answering
# 503 ServerBusy at startup) costs a cold build instead of failing the job.
if ! SCCACHE_GHA_ENABLED=true SCCACHE_IDLE_TIMEOUT=0 sccache --start-server; then
echo "::warning::sccache could not start (cache storage unavailable); building without it"
echo "RUSTC_WRAPPER=" >> "$GITHUB_ENV"
echo "SCCACHE_GHA_ENABLED=false" >> "$GITHUB_ENV"
fi
# The C++ reference (bin/cpp/lib) comes prebuilt from the GitHub Release that
# .github/workflows/cpp-reference.yml publishes for scripts/cpp-ref-key.sh's key.
# When none matches (a PR that changes harness/cpp before it is published), build it
# from source and keep that build in actions/cache under the same key. It lives
# outside cargo's target dir (bin/): rust-cache's post-step cleans bin/.
- name: C++ reference key
id: cppkey
shell: bash
run: echo "key=$(scripts/cpp-ref-key.sh)" >> "$GITHUB_OUTPUT"
- name: Restore C++ reference built from source
uses: actions/cache/restore@v4
with:
path: .cpp
key: cpp-v3-${{ runner.os }}-${{ steps.cppkey.outputs.key }}
- name: Fetch C++ reference (build it when no prebuilt matches)
id: cpp
shell: bash
run: |
cpp=$SOLIDCORE_CPP_DIR
if [ -f "$cpp/lib/libSMLib.a" ] && [ -f "$cpp/lib/libSM_API.a" ] && [ -f "$cpp/ffi.env" ]; then
echo "C++ reference restored from cache"
exit 0
fi
command -v zstd >/dev/null || sudo apt-get install -y zstd
rc=0
scripts/fetch-cpp.sh --no-build || rc=$?
if [ "$rc" = 3 ]; then
sudo apt-get update && sudo apt-get install -y ninja-build cmake g++
harness/cpp/build.sh --no-tests --jobs "$(nproc)"
echo "built=true" >> "$GITHUB_OUTPUT"
elif [ "$rc" != 0 ]; then
exit "$rc"
fi
# Several jobs may build the same key at once; only the first save wins, the
# others log a warning.
- name: Save C++ reference built from source
if: steps.cpp.outputs.built == 'true'
uses: actions/cache/save@v4
continue-on-error: true
with:
path: .cpp
key: cpp-v3-${{ runner.os }}-${{ steps.cppkey.outputs.key }}