github action to speedup building using ccache
Find a file
dependabot[bot] 90ecfa0287
Bump ts-jest from 29.4.2 to 29.4.4 (#373)
Bumps [ts-jest](https://github.com/kulshekhar/ts-jest) from 29.4.2 to 29.4.4.
- [Release notes](https://github.com/kulshekhar/ts-jest/releases)
- [Changelog](https://github.com/kulshekhar/ts-jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/kulshekhar/ts-jest/compare/v29.4.2...v29.4.4)

---
updated-dependencies:
- dependency-name: ts-jest
  dependency-version: 29.4.4
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-25 14:22:49 +02:00
.github Bump actions/checkout from 4 to 5 (#357) 2025-08-12 22:00:07 +02:00
__tests__ Evict old files from the cache prior to saving (#270) 2024-12-31 13:07:11 +01:00
dist update code 2025-09-10 17:36:43 +02:00
src Revert "set cache to readonly if skipping save (#301)" 2025-07-09 08:54:59 +02:00
.gitignore implement ccache as github action 2020-12-06 20:22:10 +01:00
action.yml Evict old files from the cache prior to saving (#270) 2024-12-31 13:07:11 +01:00
jest.config.js Add option to add stats to Job Summary page (#263) 2024-12-06 11:37:33 +01:00
LICENSE Initial commit 2020-12-06 14:05:49 +01:00
package-lock.json Bump ts-jest from 29.4.2 to 29.4.4 (#373) 2025-09-25 14:22:49 +02:00
package.json Bump ts-jest from 29.4.2 to 29.4.4 (#373) 2025-09-25 14:22:49 +02:00
README.md Change Bash to Shell everywhere (#223) 2024-09-05 06:23:00 +02:00
tsconfig.json implement ccache as github action 2020-12-06 20:22:10 +01:00

Ccache for gh actions

A Github action to speedup building using ccache/sccache for C/C++ projects.

Works on Linux, macOS, and Windows.

Usage

- run: apt update  # Only for Docker jobs
- name: ccache
  uses: hendrikmuhs/ccache-action@v1.2

NB! This should always come after the actions/checkout step.

In order to use ccache in your other steps, point the compiler to it, e.g. with run-cmake:

- name: build with cmake
  uses: lukka/run-cmake@v3
  with:
    cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
    cmakeAppendedArgs: '-DCMAKE_BUILD_TYPE=${{ matrix.type }} -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache'
    ...

or by manipulating PATH (ccache only):

- name: build
  run: |
    export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"

(works for both ubuntu and macos)

or by setting create-symlink to true:

- name: ccache
  uses: hendrikmuhs/ccache-action@v1.2
  with:
    create-symlink: true

Ccache/sccache gets installed by this action if it is not installed yet.

Example workflow

Notes on Windows support

Note that using Ccache on Windows probably works, but Sccache is recommended for stable Windows support.

If you have multiple jobs

If you have multiple jobs or targets (eg. Debug, Release) or multiple OS's, it makes sense to cache them separately. An additional cache key can be specified.

jobs:
  some_build:
    steps:
      ...
      - name: ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ${{ github.job }}-${{ matrix.os }}  # Eg. "some_build-ubuntu-latest"
  some_other_build:
    ...

Other options

See action.yml for a full list of options.

Ccache statistics

Stats are provided as part of the post action, check the output to see if cache is effective.

You may also set verbose input to 1 to enable verbose output from this action or even to 2 to make it even more verbose.

How it works

This action is based on https://cristianadam.eu/20200113/speeding-up-c-plus-plus-github-actions-using-ccache/

In a nutshell, the .ccache folder is configured in the runner path and the folder is persisted and reloaded using cache. For more details see: https://docs.github.com/en/free-pro-team@latest/actions/guides/caching-dependencies-to-speed-up-workflows.