mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-14 06:33:37 +08:00
feat: 增加清理项目根 .pnpm-store 残留的选项并优化 store 目录配置
This commit is contained in:
@@ -55,6 +55,11 @@ inputs:
|
||||
required: false
|
||||
default: ''
|
||||
|
||||
clean-project-store:
|
||||
description: '在安装前清理项目根的 .pnpm-store 残留(true/false)'
|
||||
required: false
|
||||
default: 'false'
|
||||
|
||||
cache-hash:
|
||||
description: '缓存hash值(推荐使用hashFiles计算)'
|
||||
required: false
|
||||
@@ -140,6 +145,11 @@ runs:
|
||||
|
||||
if [[ "$MODE" == "node_modules" ]]; then
|
||||
CACHE_PATH="${{ inputs.node-modules-path }}"
|
||||
# 即使只缓存 node_modules,pnpm 也会使用 store。为避免在项目根生成 .pnpm-store,这里同样固定 PNPM_STORE_DIR
|
||||
if [[ "$MANAGER" == "pnpm" ]]; then
|
||||
DEFAULT_PNPM_STORE="${RUNNER_TEMP:-$HOME}/.pnpm-store"
|
||||
echo "PNPM_STORE_DIR=${DEFAULT_PNPM_STORE}" >> "$GITHUB_ENV"
|
||||
fi
|
||||
else
|
||||
case "$MANAGER" in
|
||||
"npm")
|
||||
@@ -198,6 +208,25 @@ runs:
|
||||
if: (inputs.cache-mode == 'node_modules' && steps.cache.outputs.cache-hit != 'true') || (inputs.cache-mode == 'store')
|
||||
shell: bash
|
||||
run: |
|
||||
# 若使用 pnpm,在本步骤内始终显式设置 PNPM_STORE_DIR(覆盖可能存在的相对配置)
|
||||
if [[ "${{ inputs.package-manager }}" == "pnpm" ]]; then
|
||||
if [[ "${{ inputs.cache-mode }}" == "store" ]]; then
|
||||
# store 模式:cache-path 的 path 即为期望的 store 目录
|
||||
export PNPM_STORE_DIR="${{ steps.cache-path.outputs.path }}"
|
||||
else
|
||||
# node_modules 模式:不要回退到 cache-path(那是 node_modules 目录),而是使用 RUNNER_TEMP/HOME
|
||||
export PNPM_STORE_DIR="${PNPM_STORE_DIR:-${RUNNER_TEMP:-$HOME}/.pnpm-store}"
|
||||
fi
|
||||
echo "🧩 已设置 PNPM_STORE_DIR=${PNPM_STORE_DIR}"
|
||||
fi
|
||||
|
||||
# 可选清理:如启用并发现项目根存在残留的 .pnpm-store,且与目标目录不同,则清理
|
||||
if [[ "${{ inputs.package-manager }}" == "pnpm" && "${{ inputs.clean-project-store }}" == "true" ]]; then
|
||||
if [[ -d ".pnpm-store" && "${PNPM_STORE_DIR}" != "$PWD/.pnpm-store" ]]; then
|
||||
echo "🧹 清理项目根的残留 .pnpm-store(目标store为 ${PNPM_STORE_DIR})"
|
||||
rm -rf .pnpm-store || true
|
||||
fi
|
||||
fi
|
||||
# 如果提供了自定义安装命令,使用自定义命令
|
||||
if [[ -n "${{ inputs.install-command }}" ]]; then
|
||||
echo "🔧 使用自定义安装命令: ${{ inputs.install-command }}"
|
||||
|
Reference in New Issue
Block a user