🐛 fix(workflow): manage Node versions with fnm

This commit is contained in:
csh
2026-08-13 17:33:55 +08:00
parent f90faa10c3
commit fac69aafbd
6 changed files with 126 additions and 5 deletions
+25
View File
@@ -26,6 +26,8 @@ env:
SOURCE_SHA: ${{ github.event.workflow_run.head_sha }}
SOURCE_EVENT: ${{ github.event.workflow_run.event }}
COMMIT_LINT_REQUIRE_EMOJI: "1"
FNM_BIN: "/data/bin/fnm"
FNM_DIR: "/data/fnm"
jobs:
checks:
@@ -131,6 +133,29 @@ jobs:
echo "========================================"
cd "$REPO_DIR"
node_version=$(tr -d '[:space:]' < .node-version)
if ! [[ "$node_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo ".node-version 必须是完整的 Node.js 版本号: $node_version" >&2
exit 1
fi
if [ ! -x "$FNM_BIN" ]; then
echo "Prepare 未安装 fnm: $FNM_BIN" >&2
exit 1
fi
eval "$("$FNM_BIN" env --shell bash)"
exec 9>"${FNM_DIR}.install.lock"
flock 9
"$FNM_BIN" use --install-if-missing "$node_version"
flock -u 9
if [ "$(node --version)" != "v$node_version" ]; then
echo "Node.js 切换后版本不符合要求: $(node --version)" >&2
exit 1
fi
node --version
npm --version
echo "📦 安装锁定的 Node.js 校验工具"
npm ci --ignore-scripts --no-audit --no-fund --no-bin-links