fix-ci-proxy
This commit is contained in:
@@ -16,12 +16,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
SKIP_ENV_VALIDATION: "1"
|
SKIP_ENV_VALIDATION: "1"
|
||||||
NEXT_TELEMETRY_DISABLED: "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:
|
steps:
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@@ -39,10 +33,31 @@ jobs:
|
|||||||
|
|
||||||
- name: Configure npm proxy
|
- name: Configure npm proxy
|
||||||
run: |
|
run: |
|
||||||
if [ -n "$HTTP_PROXY" ]; then npm config set proxy "$HTTP_PROXY"; fi
|
# 自动获取容器的默认网关 IP(即宿主机 IP)
|
||||||
if [ -n "$http_proxy" ]; then npm config set proxy "$http_proxy"; fi
|
# ip route show default | awk '{print $3}'
|
||||||
if [ -n "$HTTPS_PROXY" ]; then npm config set https-proxy "$HTTPS_PROXY"; fi
|
# 或者如果没有 ip 命令,尝试解析 host.docker.internal (如果 runner 支持)
|
||||||
if [ -n "$https_proxy" ]; then npm config set https-proxy "$https_proxy"; fi
|
# 这里假设容器内有 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
|
- name: Show proxy status
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
Reference in New Issue
Block a user