GitHub 中的缓存依赖项 Windows 中的操作
Cache dependencies in GitHub Actions on Windows
我有一个在 Windows OS 上运行的 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..
非常感谢任何帮助!
缓存包依赖项是一项已在 actions/setup-node@v2 中可用的功能。你不必配置 actions/cache@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
您可以在 Caching packages dependencies 中阅读更多相关信息。
我有一个在 Windows OS 上运行的 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..
非常感谢任何帮助!
缓存包依赖项是一项已在 actions/setup-node@v2 中可用的功能。你不必配置 actions/cache@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
您可以在 Caching packages dependencies 中阅读更多相关信息。