Skip to content

Commit b4209ba

Browse files
mkannwischerhanno-becker
authored andcommitted
Nix: Only write caches in main branch
For a long time we are having issues with Github Actions cache evictions when multiple PRs change the nix setup. What happens in that case it that each of these PRs will create it's own cache entries exceeding 5 GB for the 3 platforms we require. As the total cache size limit is 10 GB, Github often evicted the older cases which often is the cache from the main branch. This will consequently slow down _all_ PRs as they have to build all dependencies from scratch. The symptom of this is commonly the autogeneration CI jobs taking 2 hours or more as they have to compile the cross toolchains from scratch. This commit fixes that for good. Caches are only written in the main branch, and, hence, no cache evictions can occur do to PRs. PRs changing the the nix setup will no longer be faster on second execution, however, they still benefit from the cache from the main branch as that has most of the packages they need anyway in most cases. For example, a PR changing CBMC, will only have to rebuild CBMC, but can use the cached z3 and HOL-Light. Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 8e74a84 commit b4209ba

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

.github/actions/setup-nix/action.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ runs:
104104
if: ${{ env.NIX_CACHE_ENABLED != 1 && inputs.cache == 'true' }}
105105
continue-on-error: true
106106
with:
107-
primary-key: ${{ steps.nix-post-check.outputs.cache_prefix }}-${{ hashFiles('**/*.nix') }}
108-
restore-prefixes-first-match: ${{ steps.nix-post-check.outputs.cache_prefix }}
109-
gc-max-store-size-linux: 536870912
107+
primary-key: ${{ steps.nix-post-check.outputs.cache_prefix }}
108+
gc-max-store-size-linux: 3221225472
110109
purge: ${{ inputs.save_cache == 'true' }}
111110
save: ${{ inputs.save_cache == 'true' }}
112111
purge-prefixes: cache-${{ steps.nix-post-check.outputs.cache_prefix }}

.github/workflows/nix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
with:
6666
cache: true
6767
verbose: true
68-
save_cache: true
68+
save_cache: ${{ github.ref == 'refs/heads/main' }}
6969
devShell: ci
7070
gh_token: ${{ secrets.GITHUB_TOKEN }}
7171
script: |

0 commit comments

Comments
 (0)