Skip to content

Build-Coolsnowwolf

Build-Coolsnowwolf #4

Workflow file for this run

name: Build-Coolsnowwolf
on:
workflow_dispatch:
inputs:
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: 'lede'
REPO_BRANCH: 'master'
UPLOAD_RELEASE: true
UPLOAD_BIN_DIR: true
UPLOAD_PACKAGES: true
UPLOAD_SYSUPGRADE: true
UPLOAD_WETRANSFER: true
UPLOAD_COWTRANSFER: true
jobs:
lean_openwrt:
runs-on: ubuntu-20.04
if: github.event.repository.owner.id == github.event.sender.id || ! github.event.sender.id
name: coolsnowwolf-openwrt-${{github.event.inputs.target}}
permissions:
contents: write
env:
IP: ${{github.event.inputs.ip}}
DEPENDS: ${{github.event.inputs.depends}}
# VERSION: ${{github.event.inputs.version}}
PARTSIZE: ${{github.event.inputs.partsize}}
FREE_DISK: ${{github.event.inputs.free_disk}}
TARGET_DEVICE: ${{github.event.inputs.target}}
# TARGET_DEVICE: ${{matrix.target}}
# strategy:
# fail-fast: false
# matrix:
# target: ["x86_64", "r1-plus-lts"]
# target: ["newifi-d2", "phicomm_k2p" ,"asus_rt-n16", "armvirt-64-default", "x86_64"]
# target: ["newifi-d2", "x86_64", "r1-plus-lts", "phicomm_k2p", "armvirt-64-default", "asus_rt-n16"]
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: |
# 关闭 swap 分区并删除 swap 文件
[ -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
# 转换分配给新文件系统的 /mnt 目录的空间大小为字节
export MNT_LOOP_BYTES=$((($(df --block-size=1024 --output=avail /mnt | tail -1) - 1024*1024*1) * 1024))
# 创建 /mnt 目录的卷
sudo fallocate -l $MNT_LOOP_BYTES /mnt/mnt.img
# 将 /mnt 目录关联到一个未使用的循环设备
export MNT_LOOP_DEVNAME=$(sudo losetup -Pf --show /mnt/mnt.img)
# 标记循环设备为物理卷
sudo pvcreate -f $MNT_LOOP_DEVNAME
# 创建卷组并添加根目录和 /mnt 目录的物理卷
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}')
# 在逻辑卷上创建 Btrfs 文件系统
sudo mkfs.btrfs -L combinedisk $LV_DEVNAME
# 挂载逻辑卷到指定目录,并使用 Zstandard 压缩算法
sudo mount -o compress=zstd $LV_DEVNAME $GITHUB_WORKSPACE
# 更改目录权限为 runner:runner 用户,确保执行者具有适当权限
sudo chown -R runner:runner $GITHUB_WORKSPACE
# 创建临时目录(如果不存在)
mkdir -m 0777 -p $GITHUB_WORKSPACE/tmp
# 将 /tmp 目录下的内容复制到临时目录中(如果发生错误,仍继续执行)
sudo cp -rp /tmp/* $GITHUB_WORKSPACE/tmp || true
# 将临时目录绑定到 /tmp 目录
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 ) &
# sudo bash -c 'bash <(curl -s is.gd/build_environment)'
fi
sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
- name: 部署
continue-on-error: true
# run: wget -qO- git.io/lean_openwrt | bash
run: wget -qO- is.gd/lean_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: coolsnowwolf-Cache
tag_name: coolsnowwolf-Cache
name: ${{env.EMOJI}} coolsnowwolf-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: coolsnowwolf-firmware
tag_name: ${{env.STRDATE}}-coolsnowwolf
name: ${{env.EMOJI}} ${{env.STRDATE}} coolsnowwolf-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: .*coolsnowwolf$
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}