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 clear all cache. How can I do that?
on: push name: R-CMD-check jobs: R-CMD-check: runs-on: ${{ matrix.config.os }} name: ${{ matrix.config.os }} (${{ matrix.config.r }}) strategy: fail-fast: false matrix: config: # - {os: windows-latest, r: 'devel'} - {os: macOS-latest, r: 'release'} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - uses: r-lib/actions/setup-r@master - name: Query dependencies run: | repos <- c("https://r-hyperspec.github.io/hySpc.pkgs/", getOption("repos")) saveRDS("remotes::dev_package_deps(dependencies = TRUE)", ".github/depends.Rds", version = 2) writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") shell: Rscript {0} - name: Cache R packages if: runner.os != 'Windows' uses: actions/cache@v1 with: path: ${{ env.R_LIBS_USER }} key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - name: Install dependencies run: remotes::install_deps(dependencies = TRUE) shell: Rscript {0} - name: Session info run: | options(width = 100) pkgs <- installed.packages()[, "Package"] sessioninfo::session_info(pkgs, include_base = TRUE) shell: Rscript {0}
The easiest way to clear your Git cache is to use the “git rm” command with the “–cached” option. You can choose to remove one file or to remove an entire working directory.
About caching workflow dependencies To help speed up the time it takes to recreate files like dependencies, GitHub can cache files you frequently use in workflows. To cache dependencies for a job, you can use GitHub's cache action. The action creates and restores a cache identified by a unique key.
GitHub Actions usage is free for standard GitHub-hosted runners in public repositories, and for self-hosted runners.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With