You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB
Bash

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env bash
# 在容器内执行:为各子项目 npm ci再调用仓库根脚本路径挂载为 /work
set -euo pipefail
cd /work
BUILD_ARCH="${BUILD_ARCH:-all}"
# npm 网络增强:默认使用官方 registry可通过 NPM_REGISTRY 覆盖;增加超时与重试,减少 ECONNRESET 失败概率。
npm config set registry "${NPM_REGISTRY:-https://registry.npmjs.org/}"
npm config set fetch-retries 5
npm config set fetch-retry-factor 2
npm config set fetch-retry-mintimeout 20000
npm config set fetch-retry-maxtimeout 120000
npm config set fetch-timeout 300000
if (($# == 0)); then
mapfile -t projects < <(bash /work/scripts/build-linux-deb-all.sh --list-projects)
else
projects=("$@")
fi
if (( ${#projects[@]} == 0 )); then
echo "错误: 没有可构建项目" >&2
exit 1
fi
for d in "${projects[@]}"; do
if [[ ! -f "$d/package.json" ]]; then
echo "错误: 缺少 /work/$d/package.json" >&2
exit 1
fi
(
cd "$d"
# npm ci 网络偶发抖动时最多重试 3 次
for i in 1 2 3; do
if npm ci; then
break
fi
if [[ "$i" -eq 3 ]]; then
echo "错误: $d npm ci 连续 3 次失败" >&2
exit 1
fi
echo "警告: $d npm ci 失败10 秒后重试($i/3..." >&2
sleep 10
done
)
done
exec bash /work/scripts/build-linux-deb-all.sh --arch "$BUILD_ARCH" "${projects[@]}"