From d434011ff1fdd3e43a90fac8669ecce136063a1b Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Thu, 30 Apr 2026 10:30:34 +0800 Subject: [PATCH] refactor(drone): improve PM2 command handling in deployment script - Replaced direct PM2 commands with a function to check for PM2 or npx availability, enhancing error handling and flexibility. - Updated the deployment script in .drone.yml to set the PATH correctly, ensuring that npm global binaries are accessible. - This refactor streamlines the application lifecycle management for the nuxt4-demo, improving the robustness of the deployment process. --- .drone.yml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 5350a60..049a088 100644 --- a/.drone.yml +++ b/.drone.yml @@ -67,6 +67,25 @@ steps: rm -rf "$UNZIP_DIR" mkdir -p "$UNZIP_DIR" tar -xzf "$REPO_DIR/build-output.tar.gz" -C "$UNZIP_DIR" - - 'bash -lc "cd $UNZIP_DIR && pm2 stop nuxt4-demo || true"' - - 'bash -lc "cd $UNZIP_DIR && pm2 delete nuxt4-demo || true"' - - 'bash -lc "cd $UNZIP_DIR && pm2 start ./run.sh --name nuxt4-demo"' \ No newline at end of file + - | + set -e + cd "$UNZIP_DIR" + # exec runner 常缺登录 PATH,补 npm 全局 bin(pm2 多装在这里) + if command -v npm >/dev/null 2>&1; then + _pfx="$(npm config get prefix 2>/dev/null || true)" + case "$_pfx" in /*) export PATH="${_pfx}/bin:${PATH}" ;; esac + fi + export PATH="${HOME}/.bun/bin:/usr/local/bin:/usr/bin:${PATH}" + run_pm2() { + if command -v pm2 >/dev/null 2>&1; then + command pm2 "$@" + elif command -v npx >/dev/null 2>&1; then + npx --yes pm2 "$@" + else + echo "未找到 pm2 且没有 npx,请在 Runner 上执行: npm i -g pm2" + exit 1 + fi + } + run_pm2 stop nuxt4-demo || true + run_pm2 delete nuxt4-demo || true + run_pm2 start ./run.sh --name nuxt4-demo \ No newline at end of file