Skip to content

Commit 022dd39

Browse files
authored
Merge pull request #202 from VIZ-Blockchain/ci/fix-ccache-reuse
ci: make ccache actually persist between runs
2 parents 38931fb + ec3d68e commit 022dd39

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎.github/workflows/docker-pr-build.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,14 @@ jobs:
5959
with:
6060
path: cache-mount
6161
key: viz-cache-mount-${{ runner.os }}-pr-${{ github.base_ref }}-${{ hashFiles('share/vizd/docker/Dockerfile-production') }}-${{ github.sha }}
62+
# Actions caches saved by one PR are invisible to every other PR (scoped to
63+
# refs/pull/N/merge), so the pr-* keys only help re-runs of the same PR. Fall
64+
# back to the cache docker-main.yml saves on master, which every PR can read;
65+
# both builds use the same viz-ccache mount.
6266
restore-keys: |
6367
viz-cache-mount-${{ runner.os }}-pr-${{ github.base_ref }}-${{ hashFiles('share/vizd/docker/Dockerfile-production') }}-
6468
viz-cache-mount-${{ runner.os }}-pr-${{ github.base_ref }}-
69+
viz-cache-mount-${{ runner.os }}-main-
6570
6671
- name: Inject cache mounts into BuildKit
6772
uses: reproducible-containers/buildkit-cache-dance@v3

‎.github/workflows/tests.yml‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jobs:
1414
name: consensus_sim + pm unit tests (distro Boost)
1515
runs-on: ubuntu-latest
1616
timeout-minutes: 180
17+
env:
18+
CCACHE_DIR: /home/runner/.cache/ccache
19+
CCACHE_MAXSIZE: 1G
1720

1821
steps:
1922
- uses: actions/checkout@v6
@@ -60,10 +63,13 @@ jobs:
6063
libbz2-dev liblzma-dev libzstd-dev libreadline-dev \
6164
libtool ncurses-dev pkg-config zlib1g-dev
6265
66+
# ccache >= 4 keeps its cache in ~/.cache/ccache, not ~/.ccache, so the old path
67+
# never existed and nothing was ever saved ("Path Validation Error"). Pin the
68+
# directory so the restore/save path and ccache agree.
6369
- name: Restore ccache
6470
uses: actions/cache@v5
6571
with:
66-
path: ~/.ccache
72+
path: ${{ env.CCACHE_DIR }}
6773
key: tests-ccache-${{ runner.os }}-${{ github.sha }}
6874
restore-keys: tests-ccache-${{ runner.os }}-
6975

@@ -85,6 +91,7 @@ jobs:
8591
TEST_CMAKE=$(find ../tests -mindepth 2 -maxdepth 2 -name CMakeLists.txt)
8692
TEST_BINS=$(grep -ho 'add_test(NAME [a-z_]* COMMAND [a-z_]*' $TEST_CMAKE | awk '{print $NF}')
8793
make -j"$(nproc)" $TEST_BINS
94+
ccache -s
8895
8996
- name: Run tests
9097
env:
@@ -111,6 +118,9 @@ jobs:
111118
validators: [1, 2]
112119
runs-on: ubuntu-latest
113120
timeout-minutes: 120
121+
env:
122+
CCACHE_DIR: /home/runner/.cache/ccache
123+
CCACHE_MAXSIZE: 1G
114124

115125
steps:
116126
- uses: actions/checkout@v6
@@ -129,10 +139,18 @@ jobs:
129139
apt="sudo apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20"
130140
$apt update
131141
$apt install -y --no-install-recommends \
132-
build-essential cmake libboost-all-dev libssl-dev \
142+
build-essential ccache cmake libboost-all-dev libssl-dev \
133143
libbz2-dev liblzma-dev libzstd-dev libreadline-dev \
134144
libtool ncurses-dev pkg-config zlib1g-dev
135145
146+
# One cache per matrix arm: CHAIN_TESTNET_VALIDATORS changes compile flags.
147+
- name: Restore ccache
148+
uses: actions/cache@v5
149+
with:
150+
path: ${{ env.CCACHE_DIR }}
151+
key: testnet-ccache-${{ runner.os }}-v${{ matrix.validators }}-${{ github.sha }}
152+
restore-keys: testnet-ccache-${{ runner.os }}-v${{ matrix.validators }}-
153+
136154
- name: Configure and build the consensus simulator (testnet config)
137155
run: |
138156
set -euo pipefail
@@ -143,12 +161,15 @@ jobs:
143161
multi=(-DCHAIN_TESTNET_VALIDATORS=2)
144162
fi
145163
cmake -DCMAKE_BUILD_TYPE=Release \
164+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
165+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
146166
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
147167
-DBUILD_SHARED_LIBRARIES=FALSE \
148168
-DCHAINBASE_CHECK_LOCKING=FALSE \
149169
-DBUILD_TESTNET=TRUE \
150170
-DBUILD_CONSENSUS_TESTS=ON "${multi[@]}" ..
151171
make -j"$(nproc)" consensus_sim_tests
172+
ccache -s
152173
153174
- name: Run the simulator
154175
run: |

0 commit comments

Comments
 (0)