Build-ImmortalWrt #36
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
#================================================= | |
# https://github.com/P3TERX/Actions-OpenWrt | |
# Description: Build OpenWrt using GitHub Actions | |
# Lisence: MIT | |
# Author: P3TERX | |
# Blog: https://p3terx.com | |
#================================================= | |
name: Build-ImmortalWrt | |
on: | |
# push: | |
# paths: [ immortalwrt_openwrt ] | |
# schedule: [ cron: 0 2 */7 * * ] | |
# watch: | |
# types: started | |
workflow_dispatch: | |
inputs: | |
repo: | |
description: '选择仓库:' | |
default: 'ImmortalWrt' | |
required: true | |
type: choice | |
options: [ immortalwrt, openwrt ] | |
branch: | |
description: '选择的分支:' | |
default: 'openwrt-21.02' | |
required: true | |
type: choice | |
options: [ openwrt-21.02, openwrt-23.05, openwrt-24.10, master, openwrt-18.06-k5.4, openwrt-18.06 ] | |
target: | |
description: '选择要生成的机型:' | |
default: 'r1-plus-lts' | |
required: true | |
type: choice | |
options: [ x86_64, r1-plus-lts, newifi-d2, asus_rt-n16, phicomm_k2p, armvirt-64-default, r4s, r2s, r2c ] | |
# version: | |
# description: '选择要生成版本:' | |
# default: 'plus' | |
# required: true | |
# type: choice | |
# options: [ pure, plus ] | |
ip: | |
description: '设置web登录IP:' | |
default: '192.168.2.1' | |
required: false | |
partsize: | |
description: '设置rootfs大小:' | |
default: '800' | |
required: false | |
free_disk: | |
description: '整理空间' | |
type: choice | |
default: 'no' | |
options: [ 'losetup', 'free-disk-space', 'plus', 'no' ] | |
required: false | |
depends: | |
description: '编译依赖选项' | |
type: choice | |
default: 'default' | |
options: [ default, ImmortalWrt ] | |
required: false | |
env: | |
TZ: Asia/Shanghai | |
REPO_FLODER: 'openwrt' | |
UPLOAD_RELEASE: true | |
UPLOAD_BIN_DIR: true | |
UPLOAD_PACKAGES: true | |
UPLOAD_SYSUPGRADE: true | |
UPLOAD_WETRANSFER: true | |
UPLOAD_COWTRANSFER: true | |
jobs: | |
immo-openwrt: | |
runs-on: ubuntu-20.04 | |
if: github.event.repository.owner.id == github.event.sender.id || ! github.event.sender.id | |
name: ${{github.event.inputs.repo}}-${{github.event.inputs.branch}}-${{github.event.inputs.target}} | |
permissions: | |
contents: write | |
env: | |
IP: ${{github.event.inputs.ip}} | |
REPO: ${{github.event.inputs.repo}} | |
DEPENDS: ${{github.event.inputs.depends}} | |
# VERSION: ${{github.event.inputs.version}} | |
PARTSIZE: ${{github.event.inputs.partsize}} | |
REPO_BRANCH: ${{github.event.inputs.branch}} | |
FREE_DISK: ${{github.event.inputs.free_disk}} | |
TARGET_DEVICE: ${{github.event.inputs.target}} | |
# strategy: | |
# fail-fast: false | |
# matrix: | |
# target: ["${{github.event.inputs.target}}"] | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: jlumbroso 整理磁盘 | |
continue-on-error: true | |
uses: jlumbroso/free-disk-space@main | |
if: env.FREE_DISK == 'plus' || env.FREE_DISK == 'free-disk-space' | |
with: | |
dotnet: true | |
android: true | |
haskell: true | |
tool-cache: true | |
swap-storage: true | |
large-packages: true | |
- name: losetup 整理磁盘 | |
continue-on-error: true | |
if: env.FREE_DISK == 'plus' || env.FREE_DISK == 'losetup' | |
run: | | |
[ -f /mnt/swapfile ] && sudo swapoff -a && sudo rm -f /mnt/swapfile | |
export ROOT_LOOP_BYTES=$((($(df --block-size=1024 --output=avail / | tail -1) - 1024*1024*7) * 1024)) | |
sudo fallocate -l $ROOT_LOOP_BYTES /root.img | |
export ROOT_LOOP_DEVNAME=$(sudo losetup -Pf --show /root.img) | |
sudo pvcreate -f $ROOT_LOOP_DEVNAME | |
export MNT_LOOP_BYTES=$((($(df --block-size=1024 --output=avail /mnt | tail -1) - 1024*1024*1) * 1024)) | |
sudo fallocate -l $MNT_LOOP_BYTES /mnt/mnt.img | |
export MNT_LOOP_DEVNAME=$(sudo losetup -Pf --show /mnt/mnt.img) | |
sudo pvcreate -f $MNT_LOOP_DEVNAME | |
sudo vgcreate Actions $ROOT_LOOP_DEVNAME $MNT_LOOP_DEVNAME | |
sudo lvcreate -n disk -l 100%FREE Actions | |
export LV_DEVNAME=$(sudo lvscan | awk -F "'" '{print $2}') | |
sudo mkfs.btrfs -L combinedisk $LV_DEVNAME | |
sudo mount -o compress=zstd $LV_DEVNAME $GITHUB_WORKSPACE | |
sudo chown -R runner:runner $GITHUB_WORKSPACE | |
mkdir -m 0777 -p $GITHUB_WORKSPACE/tmp | |
sudo cp -rp /tmp/* $GITHUB_WORKSPACE/tmp || true | |
sudo mount -B $GITHUB_WORKSPACE/tmp /tmp | |
- name: 系统信息 | |
run: | | |
echo "--------------------------CPU信息--------------------------" | |
echo "CPU物理数量:$(cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l)" | |
echo -e "CPU核心信息:$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c) \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 | |
Emoji=("🎉" "🤞" "✨" "🎁" "🎈" "🎄" "🎨" "💋" "🍓" "🍕" "🍉" "💐" "🌴" "🚀" "🗽" "⛅" "🌈" "🔥" "⛄" "🐶" "🏅" "🦄" "🐤") | |
RANDOM=$$$(date +%s); rand=$[$RANDOM % ${#Emoji[@]}] | |
echo "EMOJI=${Emoji[$rand]}" >>$GITHUB_ENV | |
- name: 安装编译依赖 | |
continue-on-error: true | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
run: | | |
if [[ $DEPENDS == 'ImmortalWrt' ]]; then | |
wget -qO- is.gd/build_environment | sudo bash | |
else | |
( sudo -E apt-get -qq update | |
sudo -E apt-get -qq install ack antlr3 aria2 asciidoc autoconf automake autopoint binutils \ | |
bison build-essential bzip2 ccache clang cmake cpio curl device-tree-compiler fastjar flex \ | |
g++ gawk gcc-multilib gettext git gperf haveged help2man intltool libc6-dev-i386 libelf-dev \ | |
libglib2.0-dev libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev \ | |
libpython3-dev libreadline-dev libssl-dev libtool lrzsz mkisofs msmtp nano ninja-build p7zip \ | |
p7zip-full patch pkgconf python2.7 python3 python3-distutils python3-pyelftools python3-pip \ | |
python3-ply python3-docutils python3-pyelftools quilt re2c rename rsync scons squashfs-tools \ | |
subversion swig texinfo uglifyjs unzip upx-ucl vim wget xmlto xxd zip zlib1g-dev | |
sudo -E apt-get -qq purge android* azure-cli dotnet* firefox ghc* google* hhvm llvm* mysql* \ | |
openjdk* php* powershell zulu* | |
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc | |
sudo -E apt-get -qq autoremove --purge | |
sudo -E apt-get -qq clean ) & | |
fi | |
sudo -E timedatectl set-timezone "Asia/Shanghai" | |
- name: 部署 | |
continue-on-error: true | |
# run: wget -qO- git.io/J6IXO | bash | |
run: wget -qO- is.gd/immortalwrt_openwrt | bash | |
- name: Cache | |
uses: stupidloud/cachewrtbuild@main | |
continue-on-error: true | |
if: env.CACHE_ACTIONS == 'true' | |
with: | |
ccache: 'true' | |
clean: ${{env.CLEAN}} | |
mixkey: ${{env.CACHE_NAME}} | |
prefix: ${{github.workspace}}/${{env.REPO_FLODER}} | |
- name: tools | |
continue-on-error: true | |
if: env.CACHE_ACTIONS == 'true' && !cancelled() | |
id: tools | |
run: cd $REPO_FLODER && (make -j$(nproc) toolchain/compile || make -j1 V=s toolchain/compile) | |
- name: 保存 Cache | |
id: fetch_cache | |
if: (env.FETCH_CACHE == 'true' || steps.tools.conclusion == 'success') && !cancelled() | |
run: wget -qO- git.io/lean_openwrt | bash | |
- name: Cache 上传到 Release | |
continue-on-error: true | |
if: steps.fetch_cache.conclusion == 'success' || env.OUTPUT_RELEASE == 'true' && !cancelled() | |
uses: softprops/[email protected] | |
with: | |
files: output/* | |
token: ${{secrets.GITHUB_TOKEN}} | |
body: ${{env.REPO}}-Cache | |
tag_name: ${{env.REPO}}-Cache | |
name: ${{env.EMOJI}} ${{env.REPO}}-Cache ${{env.EMOJI}} | |
- name: 下载软件包 | |
run: | | |
cd $REPO_FLODER | |
# make package/download -j16 | |
n=0; while true; do make package/download -j && break || (n=$((n+1)); [ $n -eq 3 ] && break); done | |
find dl -size -1024c -exec ls -l {} \; | |
find dl -size -1024c -exec rm -f {} \; | |
- name: 固件编译 | |
timeout-minutes: 1440 | |
continue-on-error: true | |
id: compile | |
run: cd $REPO_FLODER && make -j$(nproc) || make -j1 V=s | |
- name: 上传 Bin | |
uses: actions/[email protected] | |
if: steps.organize.conclusion == 'success' && env.UPLOAD_BIN_DIR == 'true' && !cancelled() | |
with: | |
path: ${{env.REPO_FLODER}}/bin | |
name: OpenWrt-${{env.TARGET_DEVICE}}-bin | |
- name: 筛选固件 | |
id: organize | |
if: steps.compile.conclusion == 'success' && !cancelled() | |
run: | | |
echo "=======================" | |
echo "磁盘使用情况:" | |
echo "=======================" | |
df -hT | |
cd $REPO_FLODER | |
echo "=======================" | |
du -h --max-depth=1 ./bin | |
du -h --max-depth=1 ./build_dir | |
du -h --max-depth=1 ./staging_dir | |
du -h --max-depth=1 ./ --exclude=bin --exclude=build_dir --exclude=staging_dir --exclude=bin | |
ls bin/targets/*/*/ | |
sf=${CACHE_NAME%%-*}-${REPO_BRANCH#*-}-$(TZ=UTC-8 date +%m-%d) | |
ARCH=`awk -F'"' '/ARCH_PACKAGES/{print $2}' .config` | |
[[ $FIRMWARE_TYPE ]] && cp -v $(find bin/targets/ -type f -name "*${FIRMWARE_TYPE}*") ../firmware && echo "upload_firmware=true" >>$GITHUB_ENV || true | |
tar -zcPf ../firmware/$sf-$ARCH-packages.tar.gz bin/packages/ && echo "upload_packages=true" >>$GITHUB_ENV || true | |
cd ../firmware && md5sum * >$sf-$TARGET_DEVICE-md5-config.txt || true | |
sed '/^$/d' ../$REPO_FLODER/.config >>$sf-$TARGET_DEVICE-md5-config.txt || true | |
echo "FIRMWARE=$PWD" >>$GITHUB_ENV | |
echo "STRDATE=$(TZ=UTC-8 date +%Y-%m-%d)" >>$GITHUB_ENV | |
- name: 上传 Packages | |
uses: actions/[email protected] | |
if: env.upload_packages == 'true' && env.UPLOAD_PACKAGES == 'true' && !cancelled() | |
with: | |
path: firmware/*packages.tar.gz | |
name: OpenWrt-${{env.TARGET_DEVICE}}-package | |
- name: 上传 Firmware | |
uses: actions/[email protected] | |
if: env.upload_firmware == 'true' && env.UPLOAD_SYSUPGRADE == 'true' && !cancelled() | |
with: | |
path: firmware/*${{env.FIRMWARE_TYPE}}* | |
name: OpenWrt-${{env.TARGET_DEVICE}}-firmware | |
- name: 上传到奶牛快传 | |
id: cowtransfer | |
if: env.upload_firmware == 'true' && 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=↓↓奶牛快传下载地址↓↓::$(grep https cowtransfer.log)" | |
- name: 上传到 WeTransfer | |
id: wetransfer | |
if: env.upload_firmware == 'true' && env.UPLOAD_WETRANSFER == 'true' && !cancelled() | |
run: | | |
wget -qO- git.io/file-transfer | sh ./transfer wet -s -p 16 --no-progress $FIRMWARE 2>&1 | tee wetransfer.log | |
echo "::warning file=↓↓wetransfer下载地址↓↓::$(grep https wetransfer.log)" | |
pwd | |
- name: Firmware 上传到 Release | |
if: env.upload_firmware == 'true' && env.UPLOAD_RELEASE == 'true' && !cancelled() | |
uses: softprops/[email protected] | |
with: | |
files: firmware/* | |
token: ${{secrets.GITHUB_TOKEN}} | |
body: ${{env.REPO}}-firmware | |
tag_name: ${{env.STRDATE}}-${{env.REPO}} | |
name: ${{env.EMOJI}} ${{env.STRDATE}} ${{env.REPO}}-firmware ${{env.EMOJI}} | |
- name: Save cache state | |
continue-on-error: true | |
if: env.SAVE_CACHE == 'true' && !cancelled() | |
run: | | |
echo "上传到github" | |
export cache_repo_id='654643315' | |
export cache_path='github.com/repos/hong0980/OpenWrt-Cache/releases' | |
ls output | parallel --wc ' | |
while true; do | |
curl -T {} \ | |
-H "Content-Type: application/octet-stream" \ | |
-H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \ | |
"https://uploads.${cache_path}/${cache_repo_id}/assets?name={}" && break || true | |
done' | |
- name: Delete Releases | |
if: (!cancelled()) | |
uses: dev-drprasad/[email protected] | |
with: | |
keep_latest: 15 | |
delete_tags: true | |
delete_tag_pattern: ^.*immortalwrt$ | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |