1

我有一个在 Windows 操作系统上运行的 Github 操作。然后,为了缓存依赖项,我使用actions/cache@v2. 但是,它没有按预期工作。当我看到调试日志时,缓存的大小只有30 B. 在此处输入图像描述

这是我正在使用的代码:

name: Build
on: push

jobs:
 build_on_win:
runs-on: windows-latest
if: "!contains(github.event.head_commit.message, 'skip-publish')"

steps:
  - uses: actions/checkout@v2
  - uses: actions/setup-node@master
    with:
      node-version: 15
  - name: Cache NPM dependencies
    uses: actions/cache@v2
    with:
      path: ~/.npm
      key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
      restore-keys: |
        ${{ runner.OS }}-npm-cache-
  - name: install dependencies
    run: npm install

  rest of the code..

任何帮助是极大的赞赏 !

4

1 回答 1

1

缓存包依赖项是一项已经在actions/setup-node@v2中可用的功能。您不必配置操作/缓存@v2,您可以做的是使用如下所示的setup-node@v2操作,您只需添加cache: 'npm'它,它将自动检测并缓存依赖项。

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
  with:
    node-version: '14'
    cache: 'npm'
- run: npm install
- run: npm test

如果你有 monorepo 那么你也可以定义路径

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
  with:
    node-version: '14'
    cache: 'npm'
    cache-dependency-path: subdir/package-lock.json
- run: npm install
- run: npm test

您可以在缓存包依赖项中了解更多信息。

于 2021-09-26T13:14:17.537 回答