gitea-action-test/.github/workflows/LEDE-介绍更新.yml
LIRUI d981d14966
All checks were successful
LEDE-介绍更新 / job_1 (push) Successful in 1m31s
1115.1
2024-11-15 23:51:59 +08:00

149 lines
6.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: LEDE-介绍更新
on:
push:
#branches: # 仅在 main 分支发生更改时触发工作流程
# - main
#paths-ignore: # 忽略 README.md 文件的更改
# - 'README.md'
#workflow_dispatch: # 手动触发工作流程
jobs:
job_1:
runs-on: ubuntu-latest
steps:
# 检出代码
- name: 🛒 检出代码
uses: https://git.aoun.ltd/actions/checkout@v4
# 4. 使用代理克隆仓库
- name: 🚀 使用代理克隆仓库
env:
REPO_URL: https://github.com/coolsnowwolf/lede
REPO_BRANCH: master
ALL_PROXY: "socks5://192.168.1.8: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: |
cd lede
grep '"DISTRIB_REVISION=' */*/default-settings/files/zzz-default-settings | cut -d"'" -f2
# 获取 DISTRIB_REVISION 值
DISTRIB_REVISION=$(grep '"DISTRIB_REVISION=' */*/default-settings/files/zzz-default-settings | cut -d"'" -f2)
# 将值设置为环境变量
echo "distrib_revision=$DISTRIB_REVISION" >> $GITHUB_ENV
# 在日志中显示 DISTRIB_REVISION 的值
echo "DISTRIB_REVISION: $DISTRIB_REVISION"
# 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.6
# 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=$FULL_KERNEL_VERSION" >> $GITHUB_ENV
echo "完整的内核版本为:$FULL_KERNEL_VERSION"
#输出示例完整的内核版本为6.6.58
else
echo "未找到对应的内核版本文件 lede/include/kernel-$KERNEL_PATCHVER"
exit 1
fi
# 7. 更新和安装 feeds
- name: 🔄 更新和安装 feeds
env:
ALL_PROXY: "socks5://192.168.1.8:1080"
run: |
cd lede
./scripts/feeds update -a
./scripts/feeds install -a
# 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 版本信息,将空格替换为下划线,并构建为目标格式
LUCI_VERSION="LuCI_${LUCI_BRANCH}_branch_(git--${LUCI_COMMIT})"
# 替换字符,以确保徽章 URL 正确
LUCI_VERSION_FORMATTED=$(echo "$LUCI_VERSION" | sed 's/ /_/g; s/-/--/g')
echo "LUCI_VERSION_FORMATTED=$LUCI_VERSION_FORMATTED" >> $GITHUB_ENV
echo "LuCI 版本信息:$LUCI_VERSION_FORMATTED"
# 更新 README.md 文件
- name: ✏️ 更新 README.md 文件
env:
FULL_KERNEL_VERSION: "${{ env.FULL_KERNEL_VERSION }}"
LUCI_VERSION: "${{ env.LUCI_VERSION }}"
run: |
# 生成要插入的新内容
LATEST_VERSION="R$(date +'%y.%m.%d')--$(date +'%H%M')"
ARCHITECTURE="x86__64"
FILE_SIZE="1024MB"
RELEASE_DATE="$(date +'%Y--%m--%d')"
KERNEL_VERSION="${FULL_KERNEL_VERSION}"
DISTRIB_REVISION="${{ env.distrib_revision }}"
#LuCI 版本
LUCI_VERSION="${LUCI_VERSION_FORMATTED}"
NEW_CONTENT="<!--action-tag-start-->\n\n"
NEW_CONTENT+="![Latest Version](https://img.shields.io/badge/固件版本-${DISTRIB_REVISION}-brightgreen)\n"
NEW_CONTENT+="![Based on OpenWrt](https://img.shields.io/badge/内核版本-${KERNEL_VERSION}-00bfff)\n"
NEW_CONTENT+="![LuCI Version](https://img.shields.io/badge/LuCI_版本-${LUCI_VERSION}-blueviolet)\n"
NEW_CONTENT+="![Architecture](https://img.shields.io/badge/适用架构-${ARCHITECTURE}-ff69b4)\n"
NEW_CONTENT+="![File Size](https://img.shields.io/badge/文件大小-${FILE_SIZE}-orange)\n"
NEW_CONTENT+="![Release Date](https://img.shields.io/badge/发布日期-${RELEASE_DATE}-blue)\n\n"
NEW_CONTENT+="<!--action-tag-end-->"
# 替换标记范围内的内容
sed -i "/<!--action-tag-start-->/, /<!--action-tag-end-->/c\\$NEW_CONTENT" README.md
# 显示更新后的 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