在 GitHub 操作中缓存 node_modules
Cache node_modules in GitHub Actions
我有一个带有 2 个包的 Yarn monorepo(工作区):后端(Node.js/TypeScript)和前端(React/Typescript)。
/package.json
(修剪)
{
"workspaces": [
"backend",
"frontend"
],
}
并且我正在尝试添加与 GitHub 操作的持续集成,并尝试使用 actions/cache@v2
来缓存 Yarn 缓存目录和所有项目的 node_modules
目录
.github/workflows/CI.yml
(修剪)
steps:
- uses: actions/checkout@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: |
echo "::set-output name=dir::$(yarn cache dir)"
echo "::set-output name=version::$(yarn -v)"
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v2
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
'**/node_modules'
'**/.eslintcache'
key: ${{ runner.os }}-yarn-${{ steps.yarn-cache-dir-path.outputs.version }}-${{ hashFiles('**/yarn.lock') }}
- name: Install packages
run: yarn install --frozen-lockfile
我收到缓存已存储并重新用于连续运行:
key: Linux-yarn-1.22.10-143fef95c7228810cf502305eff3be1cbc468dc8a3e0b153a4311c0250aaef6f
Received 158645465 of 175422681 (90.4%), 151.3 MBs/sec
Received 175422681 of 175422681 (100.0%), 138.1 MBs/sec
Cache Size: ~167 MB (175422681 B)
/usr/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/08363700-9a23-447e-a80e-6f3dbec6068f/cache.tzst -P -C /home/runner/work/path
Cache restored successfully
Cache restored from key: Linux-yarn-1.22.10-143fef95c7228810cf502305eff3be1cbc468dc8a3e0b153a4311c0250aaef6f
但 yarn
仍然尝试解决依赖关系:
yarn install --frozen-lockfile
shell: /usr/bin/bash -e {0}
yarn install v1.22.10
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@2.3.2: The platform "linux" is incompatible with this module.
info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.3.1: The platform "linux" is incompatible with this module.
info "fsevents@2.3.1" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
.....
[4/4] Building fresh packages...
Done in 40.07s.
我的期望是它应该像在我的本地机器上一样工作:
$ yarn --frozen-lockfile
yarn install v1.22.10
[1/4] Resolving packages...
success Already up-to-date.
✨ Done in 0.72s.
我能否以某种方式改进我的配置以满足预期结果,或者这种 GitHub 预期的操作行为?
更新:尝试使用以下路径时:
path: |
'**/node_modules'
'**/.eslintcache'
或:
path: |
'node_modules'
'*/node_modules'
'**/.eslintcache'
缓存大小为 22 B。可能不匹配任何 node_modules
目录
经过反复试验,从 path
中删除引号 似乎解决了问题。而且缓存的大小几乎增加了两倍
- uses: actions/cache@v2
id: yarn-cache
with:
path: |
**/node_modules
**/.eslintcache
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
Run actions/cache@v2
Received 213909504 of 305669200 (70.0%), 203.6 MBs/sec
Received 305669200 of 305669200 (100.0%), 185.6 MBs/sec
Cache Size: ~292 MB (305669200 B)
/usr/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/2e2d2a1d-04d7-44c3-829e-ec4e8faf394b/cache.tzst -P -C /home/runner/work/path
Cache restored successfully
Cache restored from key: Linux-yarn-143fef95c7228810cf502305eff3be1cbc468dc8a3e0b153a4311c0250aaef6f
Run yarn install --frozen-lockfile
yarn install v1.22.10
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.96s.
我有一个带有 2 个包的 Yarn monorepo(工作区):后端(Node.js/TypeScript)和前端(React/Typescript)。
/package.json
(修剪)
{
"workspaces": [
"backend",
"frontend"
],
}
并且我正在尝试添加与 GitHub 操作的持续集成,并尝试使用 actions/cache@v2
来缓存 Yarn 缓存目录和所有项目的 node_modules
目录
.github/workflows/CI.yml
(修剪)
steps:
- uses: actions/checkout@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: |
echo "::set-output name=dir::$(yarn cache dir)"
echo "::set-output name=version::$(yarn -v)"
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v2
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
'**/node_modules'
'**/.eslintcache'
key: ${{ runner.os }}-yarn-${{ steps.yarn-cache-dir-path.outputs.version }}-${{ hashFiles('**/yarn.lock') }}
- name: Install packages
run: yarn install --frozen-lockfile
我收到缓存已存储并重新用于连续运行:
key: Linux-yarn-1.22.10-143fef95c7228810cf502305eff3be1cbc468dc8a3e0b153a4311c0250aaef6f
Received 158645465 of 175422681 (90.4%), 151.3 MBs/sec
Received 175422681 of 175422681 (100.0%), 138.1 MBs/sec
Cache Size: ~167 MB (175422681 B)
/usr/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/08363700-9a23-447e-a80e-6f3dbec6068f/cache.tzst -P -C /home/runner/work/path
Cache restored successfully
Cache restored from key: Linux-yarn-1.22.10-143fef95c7228810cf502305eff3be1cbc468dc8a3e0b153a4311c0250aaef6f
但 yarn
仍然尝试解决依赖关系:
yarn install --frozen-lockfile
shell: /usr/bin/bash -e {0}
yarn install v1.22.10
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@2.3.2: The platform "linux" is incompatible with this module.
info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.3.1: The platform "linux" is incompatible with this module.
info "fsevents@2.3.1" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
.....
[4/4] Building fresh packages...
Done in 40.07s.
我的期望是它应该像在我的本地机器上一样工作:
$ yarn --frozen-lockfile
yarn install v1.22.10
[1/4] Resolving packages...
success Already up-to-date.
✨ Done in 0.72s.
我能否以某种方式改进我的配置以满足预期结果,或者这种 GitHub 预期的操作行为?
更新:尝试使用以下路径时:
path: |
'**/node_modules'
'**/.eslintcache'
或:
path: |
'node_modules'
'*/node_modules'
'**/.eslintcache'
缓存大小为 22 B。可能不匹配任何 node_modules
目录
经过反复试验,从 path
中删除引号 似乎解决了问题。而且缓存的大小几乎增加了两倍
- uses: actions/cache@v2
id: yarn-cache
with:
path: |
**/node_modules
**/.eslintcache
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
Run actions/cache@v2
Received 213909504 of 305669200 (70.0%), 203.6 MBs/sec
Received 305669200 of 305669200 (100.0%), 185.6 MBs/sec
Cache Size: ~292 MB (305669200 B)
/usr/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/2e2d2a1d-04d7-44c3-829e-ec4e8faf394b/cache.tzst -P -C /home/runner/work/path
Cache restored successfully
Cache restored from key: Linux-yarn-143fef95c7228810cf502305eff3be1cbc468dc8a3e0b153a4311c0250aaef6f
Run yarn install --frozen-lockfile
yarn install v1.22.10
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.96s.