I am working on an R package and using GitHub Action (GHA) as a Continuous Integration (CI) provider. I cache R packages (dependencies) by using actions/cache. And now I want to
As pointed out in the corresponding issue, there is currently no native solution to clear the cache.
However, there are two practical workarounds to use a new cache. This is not exactly the same as clearing the current cache, but it does the job.
In order to do so, you have to change the cache key
(and any restore-keys
). Because if the key(s) is/are different, this is considered a cache miss and you start with a new one.
You can change the cache key either by modifying the workflow file directly, e.g., by adding a version number:
key: ${{ runner.os }}-mycache-v1-${{ hashFiles(...) }}
If you now want to use a new cache, all you have to do is to commit a different version number:
key: ${{ runner.os }}-mycache-v2-${{ hashFiles(...) }}
If you don't want to modify the workflow file and prefer using the UI, you can abuse secrets:
key: ${{ runner.os }}-mycache-${{ secrets.CACHE_VERSION }}-${{ hashFiles(...) }}
Whenever the secret changes, a new cache will be used.