Build OpenWrt #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 版权 (c) 2019-2020 P3TERX <https://p3terx.com> | |
# | |
# 这是一个自由软件,遵循 MIT 许可证。 | |
# 有关更多信息,请参见 /LICENSE。 | |
# | |
# https://github.com/P3TERX/Actions-OpenWrt | |
# 描述:使用 GitHub Actions 构建 OpenWrt | |
# | |
name: Build OpenWrt # 工作流名称:构建 OpenWrt | |
on: | |
repository_dispatch: # 当收到 repository_dispatch 事件时触发 | |
workflow_dispatch: # 允许手动触发工作流 | |
inputs: | |
ssh: | |
description: 'SSH 连接到 Actions' | |
required: false | |
default: 'false' | |
env: | |
REPO_URL: https://github.com/coolsnowwolf/lede # 仓库 URL | |
REPO_BRANCH: master # 分支名称 | |
FEEDS_CONF: feeds.conf.default # 自定义 feeds 配置文件 | |
CONFIG_FILE: .config # 配置文件 | |
DIY_P1_SH: diy-part1.sh # 自定义脚本 1 | |
DIY_P2_SH: diy-part2.sh # 自定义脚本 2 | |
UPLOAD_BIN_DIR: false # 是否上传 bin 目录 | |
UPLOAD_FIRMWARE: true # 是否上传固件 | |
UPLOAD_COWTRANSFER: false # 是否上传到 cowtransfer | |
UPLOAD_WETRANSFER: false # 是否上传到 WeTransfer | |
UPLOAD_RELEASE: false # 是否发布 release | |
TZ: Asia/Shanghai # 时区设置 | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 # 运行环境为 Ubuntu 20.04 | |
steps: | |
- name: Check Server Performance # 检查服务器性能 | |
run: | | |
echo "警告⚠" | |
echo "分配的服务器性能有限,若选择的插件过多,务必注意CPU性能!" | |
echo -e "已知CPU型号(降序): 7763,8370C,8272CL,8171M,E5-2673\n" | |
echo "--------------------------CPU信息--------------------------" | |
echo "CPU物理数量: $(cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l)" | |
echo "CPU核心数量: $(nproc)" | |
echo -e "CPU型号信息:$(cat /proc/cpuinfo | grep -m1 name | awk -F: '{print $2}')\n" | |
echo "--------------------------内存信息--------------------------" | |
echo "已安装内存详细信息:" | |
echo -e "$(sudo lshw -short -C memory | grep GiB)\n" | |
echo "--------------------------硬盘信息--------------------------" | |
echo "硬盘数量: $(ls /dev/sd* | grep -v [1-9] | wc -l)" && df -hT | |
- name: Initialization environment # 初始化环境 | |
env: | |
DEBIAN_FRONTEND: noninteractive # 禁用交互式提示 | |
run: | | |
docker rmi `docker images -q` | |
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc /etc/mysql /etc/php | |
sudo -E apt-get -y purge azure-cli* docker* ghc* zulu* hhvm* llvm* firefox* google* dotnet* aspnetcore* powershell* openjdk* adoptopenjdk* mysql* php* mongodb* moby* snap* || true | |
sudo -E apt-get -qq update | |
sudo -E apt-get -qq install libfuse-dev $(curl -fsSL git.io/depends-ubuntu-2204) | |
sudo -E apt-get -qq autoremove --purge | |
sudo -E apt-get -qq clean | |
sudo timedatectl set-timezone "$TZ" | |
sudo mkdir -p /workdir | |
sudo chown $USER:$GROUPS /workdir | |
- name: Checkout # 检出代码 | |
uses: actions/checkout@main | |
- name: Initialization environment # 初始化环境 | |
env: | |
DEBIAN_FRONTEND: noninteractive # 禁用交互式提示 | |
run: | | |
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc | |
sudo -E apt-get -qq update | |
sudo -E apt-get -qq install $(curl -fsSL git.io/depends-ubuntu-2004) | |
sudo -E apt-get -qq autoremove --purge | |
sudo -E apt-get -qq clean | |
sudo timedatectl set-timezone "$TZ" | |
sudo mkdir -p /workdir | |
sudo chown $USER:$GROUPS /workdir | |
- name: Clone source code # 克隆源代码 | |
working-directory: /workdir | |
run: | | |
df -hT $PWD | |
git clone $REPO_URL -b $REPO_BRANCH openwrt | |
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt | |
- name: Load custom feeds # 加载自定义 feeds | |
run: | | |
[ -e $FEEDS_CONF ] && mv $FEEDS_CONF openwrt/feeds.conf.default | |
chmod +x $DIY_P1_SH | |
cd openwrt | |
$GITHUB_WORKSPACE/$DIY_P1_SH | |
- name: 添加ddms-go源码 | |
run: | | |
cd openwrt | |
git clone https://github.com/sirpdboy/luci-app-ddns-go.git package/ddns-go | |
- name: 添加argon源码 | |
run: | | |
cd openwrt/package/lean | |
rm -rf luci-theme-argon | |
git clone -b 18.06 https://github.com/jerrykuku/luci-theme-argon.git luci-theme-argon | |
- name: Update feeds # 更新 feeds | |
run: cd openwrt && ./scripts/feeds update -a | |
- name: Install feeds # 安装 feeds | |
run: cd openwrt && ./scripts/feeds install -a | |
- name: Load custom configuration # 加载自定义配置 | |
run: | | |
[ -e files ] && mv files openwrt/files | |
[ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config | |
chmod +x $DIY_P2_SH | |
cd openwrt | |
$GITHUB_WORKSPACE/$DIY_P2_SH | |
- name: SSH connection to Actions # 连接到 Actions 的 SSH | |
uses: P3TERX/ssh2actions@v1.0.0 | |
if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh') | |
env: | |
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | |
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
- name: Download package # 下载包 | |
id: package | |
run: | | |
cd openwrt | |
make defconfig | |
make download -j8 | |
find dl -size -1024c -exec ls -l {} \; | |
find dl -size -1024c -exec rm -f {} \; | |
- name: Compile the firmware # 编译固件 | |
id: compile | |
run: | | |
cd openwrt | |
echo -e "$(nproc) thread compile" | |
make -j$(nproc) || make -j1 || make -j1 V=s | |
echo "status=success" >> $GITHUB_OUTPUT | |
grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' > DEVICE_NAME | |
[ -s DEVICE_NAME ] && echo "DEVICE_NAME=_$(cat DEVICE_NAME)" >> $GITHUB_ENV | |
echo "FILE_DATE=_$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV | |
- name: Check space usage # 检查空间使用情况 | |
if: (!cancelled()) | |
run: df -hT | |
- name: Upload bin directory # 上传 bin 目录 | |
uses: actions/upload-artifact@main | |
if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true' | |
with: | |
name: OpenWrt_bin${{ env.DEVICE_NAME }}${{ env.FILE_DATE }} | |
path: openwrt/bin | |
- name: Organize files # 整理文件 | |
id: organize | |
if: env.UPLOAD_FIRMWARE == 'true' && !cancelled() | |
run: | | |
cd openwrt/bin/targets/*/* | |
rm -rf packages | |
echo "FIRMWARE=$PWD" >> $GITHUB_ENV | |
echo "status=success" >> $GITHUB_OUTPUT | |
- name: Upload firmware directory # 上传固件目录 | |
uses: actions/upload-artifact@main | |
if: steps.organize.outputs.status == 'success' && !cancelled() | |
with: | |
name: OpenWrt_firmware${{ env.DEVICE_NAME }}${{ env.FILE_DATE }} | |
path: ${{ env.FIRMWARE }} | |
- name: Upload firmware to cowtransfer # 上传固件到 cowtransfer | |
id: cowtransfer | |
if: steps.organize.outputs.status == 'success' && env.UPLOAD_COWTRANSFER == 'true' && !cancelled() | |
run: | | |
curl -fsSL git.io/file-transfer | sh | |
./transfer cow --block 2621440 -s -p 64 --no-progress ${FIRMWARE} 2>&1 | tee cowtransfer.log | |
echo "::warning file=cowtransfer.com::$(cat cowtransfer.log | grep https)" | |
echo "url=$(cat cowtransfer.log | grep https | cut -f3 -d" ")" >> $GITHUB_OUTPUT | |
- name: Upload firmware to WeTransfer # 上传固件到 WeTransfer | |
id: wetransfer | |
if: steps.organize.outputs.status == 'success' && env.UPLOAD_WETRANSFER == 'true' && !cancelled() | |
run: | | |
curl -fsSL git.io/file-transfer | sh | |
./transfer wet -s -p 16 --no-progress ${FIRMWARE} 2>&1 | tee wetransfer.log | |
echo "::warning file=wetransfer.com::$(cat wetransfer.log | grep https)" | |
echo "url=$(cat wetransfer.log | grep https | cut -f3 -d" ")" >> $GITHUB_OUTPUT | |
- name: Generate release tag # 生成发布标签 | |
id: tag | |
if: env.UPLOAD_RELEASE == 'true' && !cancelled() | |
run: | | |
echo "release_tag=$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT | |
touch release.txt | |
[ $UPLOAD_COWTRANSFER = true ] && echo "🔗 [Cowtransfer](${{ steps.cowtransfer.outputs.url }})" >> release.txt | |
[ $UPLOAD_WETRANSFER = true ] && echo "🔗 [WeTransfer](${{ steps.wetransfer.outputs.url }})" >> release.txt | |
echo "status=success" >> $GITHUB_OUTPUT | |
- name: Upload firmware to release # 上传固件到发布 | |
uses: softprops/action-gh-release@v1 | |
if: steps.tag.outputs.status == 'success' && !cancelled() | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.tag.outputs.release_tag }} | |
body_path: release.txt | |
files: ${{ env.FIRMWARE }}/* | |
- name: Delete workflow runs # 删除工作流运行 | |
uses: GitRML/delete-workflow-runs@main | |
with: | |
retain_days: 1 | |
keep_minimum_runs: 3 | |
- name: Remove old Releases # 删除旧的发布版本 | |
uses: dev-drprasad/delete-older-releases@v0.1.0 | |
if: env.UPLOAD_RELEASE == 'true' && !cancelled() | |
with: | |
keep_latest: 3 | |
delete_tags: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |