@@ -23,6 +23,16 @@ inputs:
2323 description : ' Per-job ccache max size (passed to ccache -M).'
2424 required : false
2525 default : ' 500M'
26+ ghcr-debs-tag :
27+ description : >
28+ Bundle to install ccache from offline (see install-apt-deps).
29+ 'auto' resolves to the runner's ubuntu-<version>-minimal bundle,
30+ which already carries ccache and which most callers pull earlier in
31+ the same job, making the second pull free. 'none' skips the bundle
32+ and uses apt - for callers whose job pulls a different bundle,
33+ where fetching this one costs more than it saves.
34+ required : false
35+ default : ' auto'
2636 read-only :
2737 description : >
2838 When 'true', restore the cache but do NOT save it (no post-job
@@ -36,21 +46,52 @@ inputs:
3646runs :
3747 using : ' composite'
3848 steps :
39- - name : Install ccache
49+ - name : Check for ccache
50+ id : check
4051 shell : bash
4152 run : |
4253 if command -v ccache >/dev/null 2>&1; then
4354 echo "ccache already installed: $(ccache --version | head -1)"
44- elif [ "${{ runner.os }}" = "Linux" ]; then
45- sudo apt-get update -q
46- sudo DEBIAN_FRONTEND=noninteractive apt-get install -y \
47- --no-install-recommends ccache
48- elif [ "${{ runner.os }}" = "macOS" ]; then
49- brew install ccache
50- else
51- echo "::error::ccache install not supported on ${{ runner.os }}"
52- exit 1
55+ echo "present=true" >> "$GITHUB_OUTPUT"
56+ exit 0
57+ fi
58+ echo "present=false" >> "$GITHUB_OUTPUT"
59+ case "${{ runner.os }}" in
60+ Linux|macOS) ;;
61+ *) echo "::error::ccache install not supported on ${{ runner.os }}"
62+ exit 1 ;;
63+ esac
64+ tag=""
65+ if [ "${{ runner.os }}" = "Linux" ]; then
66+ tag="${{ inputs.ghcr-debs-tag }}"
67+ if [ "$tag" = "auto" ]; then
68+ # os-release rather than lsb_release: no package needed.
69+ . /etc/os-release
70+ tag="ubuntu-$VERSION_ID-minimal"
71+ elif [ "$tag" = "none" ]; then
72+ tag=""
73+ fi
5374 fi
75+ echo "tag=$tag" >> "$GITHUB_OUTPUT"
76+
77+ # Offline from the ghcr bundle when it has ccache, apt otherwise -
78+ # bounded either way. See install-apt-deps.
79+ - name : Install ccache (Linux)
80+ if : steps.check.outputs.present != 'true' && runner.os == 'Linux'
81+ uses : ./.github/actions/install-apt-deps
82+ with :
83+ packages : ccache
84+ no-install-recommends : ' true'
85+ ghcr-debs-tag : ${{ steps.check.outputs.tag }}
86+ # ccache is an optimization: never spend more of the job
87+ # installing it than a cold compile would have cost.
88+ apt-budget : ' 120'
89+ apt-install-timeout : ' 120'
90+
91+ - name : Install ccache (macOS)
92+ if : steps.check.outputs.present != 'true' && runner.os == 'macOS'
93+ shell : bash
94+ run : brew install ccache
5495
5596 # read-only=false (default): restore + post-job save (the run_id in the
5697 # key never hits, so it always saves its contribution).
0 commit comments