本文介绍了清除GitHub Actions中的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究R包,并将GitHub Action(GHA)用作持续集成(CI)提供程序.我通过使用 actions/cache 来缓存R包(依赖项).现在,我想清除所有缓存.我该怎么办?

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}

推荐答案

相应问题,目前尚无清除缓存的本地解决方案.

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.

为此,您必须更改缓存 key (以及任何 restore-keys ).因为如果密钥不同,则认为这是高速缓存未命中,因此您将从新密钥开始.

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(...) }}

如果您不想修改工作流文件而更喜欢使用UI,则可以滥用机密:

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.

这篇关于清除GitHub Actions中的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:37