gitea-action-test/.github/workflows/BBB.yml
LIRUI 620ecd082f
All checks were successful
Clone Repository with Trojan-Go Proxy / clone_with_proxy (push) Successful in 41s
1028
2024-10-28 01:08:33 +08:00

125 lines
4.9 KiB
YAML

name: Clone Repository with Trojan-Go Proxy
on:
push:
branches:
- main
jobs:
clone_with_proxy:
runs-on: ubuntu-latest
steps:
# 1. 安装 Trojan-Go 客户端
#- name: 🚀 安装 Trojan-Go
# uses: actions/checkout@v2 # 检出仓库代码,包括已添加的 trojan-go-linux-amd64.zip
#- name: 🛒 检出代码
# uses: actions/checkout@v3
- name: 📦 解压并安装 Trojan-Go
run: |
# 下载 Trojan-Go 二进制文件
wget -O trojan-go.zip https://git.aoun.ltd/18152827937/gitea-action-test/raw/commit/3b1e1b5029bf493a237d466397345e0e54cacd6b/trojan-go-linux-amd64.zip
unzip trojan-go.zip -d trojan-go
sudo mv trojan-go/trojan-go /usr/local/bin/trojan-go
rm -rf trojan-go.zip trojan-go
# 2. 配置代理参数
- name: 🔧 配置 Trojan-Go 代理
run: |
# 将多行 JSON 配置内容从 Secrets 中写入 trojan-go-config.json 文件
echo "$TROJAN_GO_CONFIG" > trojan-go-config.json
#打印配置文件内容
cat trojan-go-config.json
env:
TROJAN_GO_CONFIG: ${{ secrets.TROJAN_GO_CONFIG }}
# 3. 启动 Trojan-Go 并检测代理是否可用
#- name: 🔍 测试代理的连通性
# run: |
# nohup trojan-go -config trojan-go-config.json &
# sleep 10 # 等待代理启动
# sudo apt-get update && sudo apt-get install -y lsof
# # 检查代理是否在监听
# lsof -i :1080 || echo "Trojan-Go did not start on port 1080"
- name: 🔍 启动并保持 Trojan-Go 运行
run: |
nohup trojan-go -config trojan-go-config.json > /tmp/trojan-go.log 2>&1 & disown
sleep 10 # 等待代理启动
# 检查 Trojan-Go 是否在运行
if pgrep -x "trojan-go" > /dev/null
then
echo "Trojan-Go 已成功启动并在运行中。"
else
echo "启动失败,检查日志文件 /tmp/trojan-go.log 以获取更多信息。" && cat /tmp/trojan-go.log && exit 1
fi
# 4. 使用代理克隆仓库
- name: 🚀 使用代理克隆仓库
env:
REPO_URL: https://github.com/coolsnowwolf/lede
REPO_BRANCH: master
ALL_PROXY: "socks5://127.0.0.1:1080"
http_proxy: "socks5://127.0.0.1:1080"
https_proxy: "socks5://127.0.0.1:1080"
run: |
echo "Checking ALL_PROXY: $ALL_PROXY"
git clone --depth 1 $REPO_URL -b $REPO_BRANCH
# 1. 不使用代理的步骤
- name: 🌐 Step without Proxy
run: |
echo "Checking IP without proxy:"
# 使用 curl 检查 IP 地址, 如果请求失败则输出提示信息,提示可能是因为没有代理
curl -s https://httpbin.org/ip || echo "Request failed, likely due to no proxy."
# 2. 使用代理的步骤
- name: 🌐 Step with Proxy
env:
ALL_PROXY: "socks5://127.0.0.1:1080"
http_proxy: "socks5://127.0.0.1:1080"
https_proxy: "socks5://127.0.0.1:1080"
run: |
echo "Checking IP with proxy:"
# 使用 --socks5 明确指定代理模式
curl --socks5 127.0.0.1:1080 -s https://httpbin.org/ip || echo "Request failed, even with proxy."
- name: 🌐 Step with Proxy (using ALL_PROXY only)
env:
ALL_PROXY: "socks5://127.0.0.1:1080"
http_proxy: "socks5://127.0.0.1:1080"
https_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."
- name: 🌐 Step with Proxy (using wget)
env:
ALL_PROXY: "socks5://127.0.0.1:1080"
http_proxy: "socks5://127.0.0.1:1080"
https_proxy: "socks5://127.0.0.1:1080"
run: |
echo "Checking IP with proxy using wget:"
wget -qO- https://httpbin.org/ip || echo "Request failed, even with proxy."
- name: 🌐 Step with Proxy (git clone test)
env:
ALL_PROXY: "socks5://127.0.0.1:1080"
http_proxy: "socks5://127.0.0.1:1080"
https_proxy: "socks5://127.0.0.1:1080"
run: |
echo "Testing proxy with git clone:"
git clone https://github.com/httpbin/httpbin.git || echo "git clone failed, likely due to proxy issue."
# 最后一步:验证 Trojan-Go 代理是否还在运行
- name: 🔍 验证代理是否在运行
run: |
echo "Checking if Trojan-Go proxy is still running..."
if pgrep -x "trojan-go" > /dev/null
then
echo "Trojan-Go 仍在运行。"
else
echo "Trojan-Go 已停止运行,检查 /tmp/trojan-go.log 以获取更多信息。"
[ -f /tmp/trojan-go.log ] && cat /tmp/trojan-go.log || echo "日志文件不存在。"
exit 1
fi