2024-10-27 12:05:32 +00:00
|
|
|
|
name: Clone Repository with Trojan-Go Proxy
|
|
|
|
|
|
|
|
|
|
on:
|
2024-10-28 03:00:32 +00:00
|
|
|
|
# push:
|
|
|
|
|
# branches:
|
|
|
|
|
# - main
|
2024-10-27 12:05:32 +00:00
|
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
|
clone_with_proxy:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
steps:
|
2024-10-28 02:40:42 +00:00
|
|
|
|
# 1. 下载并安装 Trojan-Go
|
2024-10-27 12:41:19 +00:00
|
|
|
|
- name: 📦 解压并安装 Trojan-Go
|
2024-10-27 12:05:32 +00:00
|
|
|
|
run: |
|
2024-10-27 16:39:36 +00:00
|
|
|
|
# 下载 Trojan-Go 二进制文件
|
2024-10-27 17:29:31 +00:00
|
|
|
|
wget -O trojan-go.zip https://git.aoun.ltd/18152827937/Trojan-GO/raw/commit/ea063e62859270d123379dc69db57f29db2b192f/trojan-go-linux-amd64.zip
|
2024-10-27 16:39:36 +00:00
|
|
|
|
unzip trojan-go.zip -d trojan-go
|
2024-10-27 12:05:32 +00:00
|
|
|
|
sudo mv trojan-go/trojan-go /usr/local/bin/trojan-go
|
|
|
|
|
rm -rf trojan-go.zip trojan-go
|
|
|
|
|
|
|
|
|
|
# 2. 配置代理参数
|
|
|
|
|
- name: 🔧 配置 Trojan-Go 代理
|
|
|
|
|
run: |
|
2024-10-27 12:21:18 +00:00
|
|
|
|
# 将多行 JSON 配置内容从 Secrets 中写入 trojan-go-config.json 文件
|
|
|
|
|
echo "$TROJAN_GO_CONFIG" > trojan-go-config.json
|
2024-10-27 16:52:24 +00:00
|
|
|
|
#打印配置文件内容
|
|
|
|
|
cat trojan-go-config.json
|
2024-10-27 12:21:18 +00:00
|
|
|
|
env:
|
|
|
|
|
TROJAN_GO_CONFIG: ${{ secrets.TROJAN_GO_CONFIG }}
|
2024-10-28 02:40:42 +00:00
|
|
|
|
|
|
|
|
|
# 3. 启动 Trojan-Go 代理
|
2024-10-27 17:01:29 +00:00
|
|
|
|
- name: 🔍 启动并保持 Trojan-Go 运行
|
|
|
|
|
run: |
|
2024-10-27 17:08:33 +00:00
|
|
|
|
nohup trojan-go -config trojan-go-config.json > /tmp/trojan-go.log 2>&1 & disown
|
2024-10-27 17:13:51 +00:00
|
|
|
|
sleep 5 # 等待代理启动
|
2024-10-27 17:04:12 +00:00
|
|
|
|
# 检查 Trojan-Go 是否在运行
|
|
|
|
|
if pgrep -x "trojan-go" > /dev/null
|
|
|
|
|
then
|
|
|
|
|
echo "Trojan-Go 已成功启动并在运行中。"
|
|
|
|
|
else
|
2024-10-27 17:08:33 +00:00
|
|
|
|
echo "启动失败,检查日志文件 /tmp/trojan-go.log 以获取更多信息。" && cat /tmp/trojan-go.log && exit 1
|
2024-10-27 17:04:12 +00:00
|
|
|
|
fi
|
2024-10-28 02:40:42 +00:00
|
|
|
|
|
|
|
|
|
# 4. 使用代理克隆仓库
|
2024-10-27 12:05:32 +00:00
|
|
|
|
- name: 🚀 使用代理克隆仓库
|
|
|
|
|
env:
|
|
|
|
|
REPO_URL: https://github.com/coolsnowwolf/lede
|
|
|
|
|
REPO_BRANCH: master
|
|
|
|
|
ALL_PROXY: "socks5://127.0.0.1:1080"
|
|
|
|
|
run: |
|
2024-10-27 17:22:49 +00:00
|
|
|
|
echo "检查代理设置:$ALL_PROXY"
|
|
|
|
|
echo "开始尝试克隆仓库..."
|
|
|
|
|
|
2024-10-27 17:13:51 +00:00
|
|
|
|
# 尝试多次克隆仓库,直到成功
|
2024-10-27 17:22:49 +00:00
|
|
|
|
n=1
|
|
|
|
|
max_retries=5
|
|
|
|
|
while [ "$n" -le "$max_retries" ]
|
2024-10-27 17:13:51 +00:00
|
|
|
|
do
|
2024-10-27 17:22:49 +00:00
|
|
|
|
echo "正在尝试第 $n 次克隆仓库..."
|
|
|
|
|
git clone --depth 1 "$REPO_URL" -b "$REPO_BRANCH" && break
|
|
|
|
|
echo "第 $n 次克隆失败,将在5秒后重试..."
|
2024-10-27 17:13:51 +00:00
|
|
|
|
n=$((n+1))
|
|
|
|
|
sleep 5
|
|
|
|
|
done
|
2024-10-27 17:22:49 +00:00
|
|
|
|
|
|
|
|
|
# 检查克隆是否成功
|
|
|
|
|
if [ "$n" -gt "$max_retries" ]; then
|
|
|
|
|
echo "克隆仓库失败,请检查网络或代理设置。"
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
echo "仓库克隆成功!"
|
|
|
|
|
fi
|
2024-10-27 12:29:10 +00:00
|
|
|
|
|
|
|
|
|
# 1. 不使用代理的步骤
|
|
|
|
|
- name: 🌐 Step without Proxy
|
|
|
|
|
run: |
|
2024-10-27 12:33:24 +00:00
|
|
|
|
echo "Checking IP without proxy:"
|
|
|
|
|
# 使用 curl 检查 IP 地址, 如果请求失败则输出提示信息,提示可能是因为没有代理
|
|
|
|
|
curl -s https://httpbin.org/ip || echo "Request failed, likely due to no proxy."
|
|
|
|
|
|
2024-10-27 13:02:50 +00:00
|
|
|
|
# 2. 使用代理的步骤
|
2024-10-27 12:29:10 +00:00
|
|
|
|
- name: 🌐 Step with Proxy
|
|
|
|
|
env:
|
|
|
|
|
ALL_PROXY: "socks5://127.0.0.1:1080"
|
|
|
|
|
run: |
|
2024-10-27 12:33:24 +00:00
|
|
|
|
echo "Checking IP with proxy:"
|
2024-10-27 13:02:50 +00:00
|
|
|
|
# 使用 --socks5 明确指定代理模式
|
|
|
|
|
curl --socks5 127.0.0.1:1080 -s https://httpbin.org/ip || echo "Request failed, even with proxy."
|
2024-10-27 16:43:26 +00:00
|
|
|
|
|
|
|
|
|
- name: 🌐 Step with Proxy (using ALL_PROXY only)
|
|
|
|
|
env:
|
|
|
|
|
ALL_PROXY: "socks5://127.0.0.1:1080"
|
|
|
|
|
run: |
|
|
|
|
|
echo "Checking IP with proxy using ALL_PROXY:"
|
|
|
|
|
curl -s https://httpbin.org/ip || echo "Request failed, even with proxy."
|
|
|
|
|
|
2024-10-27 17:20:58 +00:00
|
|
|
|
- name: 🌐 Step with Proxy (using curl with debug)
|
2024-10-27 17:29:31 +00:00
|
|
|
|
env:
|
|
|
|
|
ALL_PROXY: "socks5://127.0.0.1:1080"
|
2024-10-27 16:43:26 +00:00
|
|
|
|
run: |
|
2024-10-27 17:20:58 +00:00
|
|
|
|
echo "Checking IP with proxy using curl:"
|
|
|
|
|
curl -s --max-time 10 https://httpbin.org/ip || echo "Request failed, even with proxy."
|
2024-10-27 16:43:26 +00:00
|
|
|
|
|
2024-10-27 16:59:20 +00:00
|
|
|
|
# 最后一步:验证 Trojan-Go 代理是否还在运行
|
|
|
|
|
- name: 🔍 验证代理是否在运行
|
|
|
|
|
run: |
|
|
|
|
|
echo "Checking if Trojan-Go proxy is still running..."
|
|
|
|
|
if pgrep -x "trojan-go" > /dev/null
|
|
|
|
|
then
|
2024-10-27 17:08:33 +00:00
|
|
|
|
echo "Trojan-Go 仍在运行。"
|
2024-10-27 16:59:20 +00:00
|
|
|
|
else
|
2024-10-27 17:08:33 +00:00
|
|
|
|
echo "Trojan-Go 已停止运行,检查 /tmp/trojan-go.log 以获取更多信息。"
|
|
|
|
|
[ -f /tmp/trojan-go.log ] && cat /tmp/trojan-go.log || echo "日志文件不存在。"
|
|
|
|
|
exit 1
|
2024-10-27 16:59:20 +00:00
|
|
|
|
fi
|