@@ -217,14 +217,21 @@ jobs:
217217 - name : Checkout repository
218218 uses : actions/checkout@v3
219219
220- - name : Compilation cache
221- uses : actions/cache@v3
222- with :
223- # It looks like this path needs to be hard-coded.
224- path : C:/msys64/home/runneradmin/.ccache
220+ - name : Prepare ccache
221+ # Get cache location of ccache
222+ # Create key that is used in action/cache/restore and action/cache/save steps
223+ id : ccache-prepare
224+ run : |
225+ echo "ccachedir=$(cygpath -m $(ccache -k cache_dir))" >> $GITHUB_OUTPUT
225226 # We include the commit sha in the cache key, as new cache entries are
226227 # only created if there is no existing entry for the key yet.
227- key : ccache-msys2-${{ matrix.msystem }}-${{ matrix.idx }}-${{ matrix.build-type }}-${{ github.ref }}-${{ github.sha }}
228+ echo "key=ccache-msys2-${{ matrix.msystem }}-${{ matrix.idx }}-${{ matrix.build-type }}-${{ github.ref }}-${{ github.sha }}" >> $GITHUB_OUTPUT
229+
230+ - name : Restore ccache
231+ uses : actions/cache/restore@v3
232+ with :
233+ path : ${{ steps.ccache-prepare.outputs.ccachedir }}
234+ key : ${{ steps.ccache-prepare.outputs.key }}
228235 # Restore a matching ccache cache entry. Prefer same branch.
229236 restore-keys : |
230237 ccache-msys2-${{ matrix.msystem }}-${{ matrix.idx }}-${{ matrix.build-type }}-${{ github.ref }}
@@ -234,9 +241,10 @@ jobs:
234241 # Limit the maximum size and switch on compression to avoid exceeding the total disk or cache quota.
235242 run : |
236243 which ccache
237- test -d ~/.ccache || mkdir -p ~/.ccache
238- echo "max_size = 250M" > ~/.ccache/ccache.conf
239- echo "compression = true" >> ~/.ccache/ccache.conf
244+ test -d ${{ steps.ccache-prepare.outputs.ccachedir }} || mkdir -p ${{ steps.ccache-prepare.outputs.ccachedir }}
245+ echo "max_size = 250M" > ${{ steps.ccache-prepare.outputs.ccachedir }}/ccache.conf
246+ echo "compression = true" >> ${{ steps.ccache-prepare.outputs.ccachedir }}/ccache.conf
247+ ccache -p
240248 ccache -s
241249 echo $HOME
242250 cygpath -w $HOME
@@ -264,6 +272,13 @@ jobs:
264272 continue-on-error : true
265273 run : ccache -s
266274
275+ - name : Save ccache
276+ # Save the cache after we are done (successfully) building
277+ uses : actions/cache/save@v3
278+ with :
279+ path : ${{ steps.ccache-prepare.outputs.ccachedir }}
280+ key : ${{ steps.ccache-prepare.outputs.key }}
281+
267282 - name : Run tests
268283 timeout-minutes : 60
269284 run : cd build && ctest
0 commit comments