gitea-action-test/.github/workflows/CCC.yml

168 lines
6.1 KiB
YAML
Raw Normal View History

2024-10-28 07:54:39 +00:00
name: 获取完整内核版本
on:
push:
branches:
- main
jobs:
clone_with_proxy:
runs-on: ubuntu-latest
steps:
2024-10-28 08:02:46 +00:00
# 检出代码
- name: 🛒 检出代码
uses: https://git.aoun.ltd/actions/checkout@v4
# 打印当前目录
- name: 📂 打印当前目录
run: |
ls -la
pwd
2024-10-28 07:54:39 +00:00
# 1. 下载并安装 Trojan-Go
- name: 📦 解压并安装 Trojan-Go
run: |
# 下载 Trojan-Go 二进制文件
wget -O trojan-go.zip https://git.aoun.ltd/18152827937/Trojan-GO/raw/commit/ea063e62859270d123379dc69db57f29db2b192f/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: 🔍 启动并保持 Trojan-Go 运行
run: |
nohup trojan-go -config trojan-go-config.json > /tmp/trojan-go.log 2>&1 & disown
sleep 5 # 等待代理启动
# 检查 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"
run: |
echo "检查代理设置:$ALL_PROXY"
echo "开始尝试克隆仓库..."
# 尝试多次克隆仓库,直到成功
n=1
max_retries=5
while [ "$n" -le "$max_retries" ]
do
echo "正在尝试第 $n 次克隆仓库..."
git clone --depth 1 "$REPO_URL" -b "$REPO_BRANCH" && break
echo "第 $n 次克隆失败将在5秒后重试..."
n=$((n+1))
sleep 5
done
# 检查克隆是否成功
if [ "$n" -gt "$max_retries" ]; then
echo "克隆仓库失败,请检查网络或代理设置。"
exit 1
else
echo "仓库克隆成功!"
fi
# 5. 获取内核主版本号
- name: 📄 获取内核主版本号
run: |
KERNEL_PATCHVER=$(grep "KERNEL_PATCHVER" lede/target/linux/x86/Makefile | awk -F ':=' '{print $2}' | xargs)
echo "KERNEL_PATCHVER=$KERNEL_PATCHVER" >> $GITHUB_ENV
echo "内核主版本号:$KERNEL_PATCHVER"
# 6. 获取完整内核版本
- name: 📄 获取完整内核版本
run: |
if [ -f "lede/include/kernel-$KERNEL_PATCHVER" ]; then
PATCH_VERSION=$(grep "LINUX_VERSION-$KERNEL_PATCHVER" "lede/include/kernel-$KERNEL_PATCHVER" | awk -F '=' '{print $2}' | xargs)
FULL_KERNEL_VERSION="$KERNEL_PATCHVER$PATCH_VERSION"
echo "完整的内核版本为:$FULL_KERNEL_VERSION"
else
echo "未找到对应的内核版本文件 lede/include/kernel-$KERNEL_PATCHVER"
exit 1
fi
2024-10-28 07:57:58 +00:00
# 7. 更新和安装 feeds
- name: 🔄 更新和安装 feeds
2024-10-28 08:34:08 +00:00
env:
ALL_PROXY: "socks5://127.0.0.1:1080"
2024-10-28 07:57:58 +00:00
run: |
cd lede
./scripts/feeds update -a
./scripts/feeds install -a
2024-10-28 07:54:39 +00:00
# 8. 获取 LuCI 版本和分支信息
- name: 📝 获取 LuCI 版本和分支信息
run: |
cd lede/feeds/luci
LUCI_BRANCH=$(git rev-parse --abbrev-ref HEAD)
LUCI_COMMIT=$(git rev-parse --short HEAD)
LUCI_VERSION="LuCI $LUCI_BRANCH branch (git-$LUCI_COMMIT)"
2024-10-28 08:20:03 +00:00
echo "LuCI 版本信息:$LUCI_VERSION"
# 更新 README.md 文件
- name: ✏️ 更新 README.md 文件
env:
OPENWRT_VERSION: "${{ env.FULL_KERNEL_VERSION }}"
run: |
2024-10-28 08:45:12 +00:00
# 定义变量
LATEST_VERSION="R$(date +'%y.%m.%d_%H%M')"
2024-10-28 08:40:02 +00:00
ARCHITECTURE="x86_64"
2024-10-28 08:45:12 +00:00
FILE_SIZE="1024MB"
RELEASE_DATE="$(date +'%Y.%m.%d')"
2024-10-28 08:40:02 +00:00
BUILD_STATUS="成功"
FIRMWARE_TYPE="稳定版"
OPENWRT_VERSION="${OPENWRT_VERSION}"
2024-10-28 08:45:12 +00:00
# URL 编码函数
url_encode() {
local data
data=$(echo -n "$1" | od -An -tx1 | tr ' ' % | tr -d '\n')
echo "$data"
}
# 对变量进行 URL 编码
LATEST_VERSION_ENCODED=$(url_encode "$LATEST_VERSION")
RELEASE_DATE_ENCODED=$(url_encode "$RELEASE_DATE")
OPENWRT_VERSION_ENCODED=$(url_encode "$OPENWRT_VERSION")
2024-10-28 08:20:03 +00:00
# 更新 README.md 文件中的内容
2024-10-28 08:45:12 +00:00
sed -i "s/{{LATEST_VERSION}}/${LATEST_VERSION_ENCODED}/g" README.md
sed -i "s/{{ARCHITECTURE}}/${ARCHITECTURE}/g" README.md
sed -i "s/{{FILE_SIZE}}/${FILE_SIZE}/g" README.md
sed -i "s/{{RELEASE_DATE}}/${RELEASE_DATE_ENCODED}/g" README.md
sed -i "s/{{BUILD_STATUS}}/${BUILD_STATUS}/g" README.md
sed -i "s/{{FIRMWARE_TYPE}}/${FIRMWARE_TYPE}/g" README.md
sed -i "s/{{OPENWRT_VERSION}}/${OPENWRT_VERSION_ENCODED}/g" README.md
2024-10-28 08:40:02 +00:00
2024-10-28 08:20:03 +00:00
# 显示更新后的 README.md 内容
cat README.md
# 配置 Git 用户信息并提交更改
- name: 📤 提交并推送更改
#env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name '298977887'
git config --global user.email '298977887@qq.com'
git add README.md
git commit -m "🤖 更新 README.md"
git push origin HEAD:main