Mil*_*iez 5 continuous-integration caching github github-actions
我很难弄清楚如何使管道使用 npm 模块恢复的缓存。
这是清单文件:
jobs:
setup-build-push-deploy:
name: Setup, Build, Push, and Deploy
runs-on: ubuntu-latest
steps:
# Checkout the repo
- name: Checkout
uses: actions/checkout@v2
- name: Setup NodeJS
uses: actions/setup-node@v1
with:
node-version: '12.14'
# Cache the npm node modules
- name: Cache node modules
uses: actions/cache@v1
id: cache-node-modules
env:
CACHE_NAME: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ env.CACHE_NAME }}-${{ hashFiles('app/package-lock.json') }}
restore-keys: |
${{ env.CACHE_NAME }}-
# Install NPM dependencies
- name: Install Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: |
cd app/
npm install
# Compile Typescript to Javascript
- name: Compile Typescript
run: |
cd app/
npm run make
Run Code Online (Sandbox Code Playgroud)
“缓存”步骤确实成功缓存命中,因此跳过“安装依赖项”步骤。但是“编译”步骤失败了,因为它找不到任何已安装的 npm 模块。
这里和这里的文档以及SO问题,例如。此处,不要指定任何指向从何处获取缓存模块的特定步骤或配置。似乎它们应该自动从 中获取,但事实并非如此。~/.npm
我发现自己处于完全相同的情况。似乎node_modules已缓存,但下一个作业由于缺少依赖项而立即失败。
我最终使用了 Gleb Bahmutov 的这个GitHub 操作。
具体这部分:
- uses: bahmutov/npm-install@v1.4.5
- run: npm install
- run: npm run ***
Run Code Online (Sandbox Code Playgroud)
详细说明可以参见这篇文章: https://glebbahmutov.com/blog/do-not-let-npm-cache-snowball/