mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-14 03:53:37 +08:00
feat: 为pnpm添加自动离线安装优化参数以提升缓存命中时的安装性能
This commit is contained in:
@@ -20,7 +20,11 @@ inputs:
|
||||
required: false
|
||||
default: 'store'
|
||||
|
||||
|
||||
optimize-install-flags:
|
||||
description: '是否启用安装参数优化(pnpm+store时自动使用 --offline/--prefer-offline 与 --frozen-lockfile)(true/false)'
|
||||
required: false
|
||||
default: 'true'
|
||||
|
||||
cache-prefix:
|
||||
description: '缓存前缀名称'
|
||||
required: false
|
||||
@@ -208,6 +212,18 @@ runs:
|
||||
if [[ -n "$INSTALL_ARGS" ]]; then
|
||||
echo "➕ 附加安装参数: $INSTALL_ARGS"
|
||||
fi
|
||||
# 根据模式与缓存命中优化安装参数(尽量离线加速)
|
||||
EXTRA_FLAGS=""
|
||||
if [[ "${{ inputs.optimize-install-flags }}" == "true" && "${{ inputs.package-manager }}" == "pnpm" && "${{ inputs.cache-mode }}" == "store" ]]; then
|
||||
if [[ "${{ steps.cache.outputs.cache-hit }}" == "true" ]]; then
|
||||
# 缓存命中:使用完全离线与锁定安装,避免网络请求
|
||||
EXTRA_FLAGS="--offline --frozen-lockfile"
|
||||
else
|
||||
# 缓存未命中:尽量离线,但允许必要网络;同时锁定避免解析差异
|
||||
EXTRA_FLAGS="--prefer-offline --frozen-lockfile"
|
||||
fi
|
||||
echo "⚡ pnpm安装优化参数: $EXTRA_FLAGS"
|
||||
fi
|
||||
# 根据包管理器选择安装命令
|
||||
case "${{ inputs.package-manager }}" in
|
||||
"npm")
|
||||
@@ -222,10 +238,10 @@ runs:
|
||||
"pnpm")
|
||||
if [[ "${{ inputs.force-install }}" == "true" ]]; then
|
||||
echo "🔧 使用pnpm强制安装"
|
||||
pnpm install --force ${INSTALL_ARGS}
|
||||
pnpm install --force ${EXTRA_FLAGS} ${INSTALL_ARGS}
|
||||
else
|
||||
echo "🔧 使用pnpm安装"
|
||||
pnpm install ${INSTALL_ARGS}
|
||||
pnpm install ${EXTRA_FLAGS} ${INSTALL_ARGS}
|
||||
fi
|
||||
;;
|
||||
"yarn")
|
||||
|
Reference in New Issue
Block a user