Files
pangolin/scripts/ci/_env.sh
T
wangjia f0f845c6e5
Deploy Site / deploy-site (push) Successful in 2m6s
Deploy Client / build-windows (push) Successful in 1m43s
Deploy Client / build-android (push) Successful in 20m37s
Deploy Client / build-macos (push) Successful in 8m19s
Deploy Client / build-ios (push) Successful in 5m29s
Deploy Client / release-deploy (push) Failing after 24m14s
fix(ci): site 流水线加 npm 国内镜像(GFW)+ npm ci 重试
site pipeline(deploy-site.yml:Astro 官网 + Next.js 用户中心 + npx wrangler)
在墙内 nas runner 上 npm ci / npx wrangler@4 直连 registry.npmjs.org → 慢/抖断。
_env.sh 早有 Go(goproxy.cn)/Flutter(flutter-io.cn)镜像,唯独漏了 npm,且 3 个
site 脚本根本没 source _env.sh。上次「修外网发版 GFW 坑」只覆盖 android(gradle)/
windows(maven),site 这块遗漏。

- _env.sh:加 NPM_CONFIG_REGISTRY=registry.npmmirror.com(可 env 覆盖)+ npm_ci_retry
  助手(照 flutter_pub_get_retry,5 次重试)。
- compile-site.sh / compile-usercenter.sh:source _env.sh,npm ci → npm_ci_retry。
- deploy-site.sh:source _env.sh,让 npx wrangler@4 也走镜像拉包。

本地实跑 compile-site.sh:镜像生效、Astro 构建成功、dist/ 产物齐全(index.html 48K
+ 多语言目录)。shellcheck -x 全 clean。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A79VtQA1BwTuQN1ThpvYpo
2026-08-01 20:32:37 +08:00

63 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# _env.sh — shared CI mirror env + tag-version helper. `source` this from other
# scripts; do not execute directly. Idempotent: only sets vars if not already
# provided by the environment (e.g. workflow-level overrides).
export GOPROXY="${GOPROXY:-https://goproxy.cn,direct}"
export PUB_HOSTED_URL="${PUB_HOSTED_URL:-https://pub.flutter-io.cn}"
export FLUTTER_STORAGE_BASE_URL="${FLUTTER_STORAGE_BASE_URL:-https://storage.flutter-io.cn}"
# npm/npx 国内镜像:site 流水线(Astro 官网 + Next.js 用户中心 + npx wrangler)在
# 墙内 nas runner 上直连 registry.npmjs.org 会慢/抖断,与 Go/Flutter 同样需镜像。
export NPM_CONFIG_REGISTRY="${NPM_CONFIG_REGISTRY:-https://registry.npmmirror.com}"
# Forgejo/Gitea repo coordinates (used by lib-forgejo.sh). Secrets
# FORGEJO_TOKEN / FORGEJO_URL are injected by the CI runner, not set here.
export FORGEJO_REPO="${FORGEJO_REPO:-wangjia/pangolin}"
# Ensure Homebrew tools are on PATH (macOS runners); harmless elsewhere.
case ":${PATH}:" in
*":/opt/homebrew/bin:"*) ;;
*) export PATH="/opt/homebrew/bin:${PATH}" ;;
esac
# ver_from_tag <prefix> <ref>
# Strips an optional "refs/tags/" prefix, then the "<prefix>-v" prefix,
# leaving a bare semver. Uses parameter expansion only (no command
# substitution). Examples:
# ver_from_tag server server-v1.2.3 -> 1.2.3
# ver_from_tag server refs/tags/server-v1.2.3 -> 1.2.3
ver_from_tag() {
local prefix="$1" ref="$2"
ref="${ref#refs/tags/}"
ref="${ref#"${prefix}"-v}"
printf '%s' "$ref"
}
# flutter_pub_get_retry — pub.flutter-io.cn 常被 GFW 抖断(socket error / exit 69),
# 让 flutter build 内隐式的 pub get 偶发失败(见 iOS build 曾因 google_fonts 拉包
# 断线而挂)。构建前显式预取 + 重试;成功后 build 命中缓存不再拉网。在 flutter
# 项目根目录调用。
flutter_pub_get_retry() {
local i
for i in 1 2 3 4 5; do
if flutter pub get; then return 0; fi
echo "==> flutter pub get 失败(第 ${i}/5 次,pub.flutter-io.cn 抖?),8s 后重试..." >&2
sleep 8
done
echo "==> flutter pub get 5 次仍失败,放弃" >&2
return 1
}
# npm_ci_retry — 同理:npmmirror 偶发抖断时重试 `npm ci`。在含 package-lock.json 的
# 目录调用(site 各 web 子项目根)。已由 NPM_CONFIG_REGISTRY 指向国内镜像。
npm_ci_retry() {
local i
for i in 1 2 3 4 5; do
if npm ci; then return 0; fi
echo "==> npm ci 失败(第 ${i}/5 次,registry 抖?),8s 后重试..." >&2
sleep 8
done
echo "==> npm ci 5 次仍失败,放弃" >&2
return 1
}