fix-ci-proxy
Some checks failed
CI / build-and-test (push) Failing after 1m53s
CI / deploy (push) Has been skipped

This commit is contained in:
SpecialX
2026-02-25 15:17:49 +08:00
parent 3986c5919c
commit cc02ddf82e

View File

@@ -16,12 +16,6 @@ jobs:
env:
SKIP_ENV_VALIDATION: "1"
NEXT_TELEMETRY_DISABLED: "1"
http_proxy: http://127.0.0.1:7890
https_proxy: http://127.0.0.1:7890
no_proxy: localhost,127.0.0.1,192.168.31.94,172.17.0.1,internal.domain
HTTP_PROXY: http://127.0.0.1:7890
HTTPS_PROXY: http://127.0.0.1:7890
NO_PROXY: localhost,127.0.0.1,192.168.31.94,172.17.0.1,internal.domain
steps:
- name: Checkout
@@ -39,10 +33,31 @@ jobs:
- name: Configure npm proxy
run: |
if [ -n "$HTTP_PROXY" ]; then npm config set proxy "$HTTP_PROXY"; fi
if [ -n "$http_proxy" ]; then npm config set proxy "$http_proxy"; fi
if [ -n "$HTTPS_PROXY" ]; then npm config set https-proxy "$HTTPS_PROXY"; fi
if [ -n "$https_proxy" ]; then npm config set https-proxy "$https_proxy"; fi
# 自动获取容器的默认网关 IP即宿主机 IP
# ip route show default | awk '{print $3}'
# 或者如果没有 ip 命令,尝试解析 host.docker.internal (如果 runner 支持)
# 这里假设容器内有 iproute2 工具
GATEWAY_IP=$(ip route show | grep default | awk '{print $3}')
echo "Detected Docker Gateway: $GATEWAY_IP"
if [ -z "$GATEWAY_IP" ]; then
echo "Warning: Could not detect gateway IP, falling back to 172.17.0.1"
GATEWAY_IP="172.17.0.1"
fi
PROXY_URL="http://$GATEWAY_IP:7890"
echo "Using Proxy: $PROXY_URL"
# 设置 npm 代理
npm config set proxy "$PROXY_URL"
npm config set https-proxy "$PROXY_URL"
# 设置环境变量供后续步骤使用 (例如 cypress, next build 等)
echo "http_proxy=$PROXY_URL" >> $GITHUB_ENV
echo "https_proxy=$PROXY_URL" >> $GITHUB_ENV
echo "HTTP_PROXY=$PROXY_URL" >> $GITHUB_ENV
echo "HTTPS_PROXY=$PROXY_URL" >> $GITHUB_ENV
- name: Show proxy status
run: |