r1p-lts #3990
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
name: build | |
on: | |
repository_dispatch: | |
workflow_dispatch: | |
inputs: | |
device: | |
description: 'select device to build' | |
default: 'r2s' | |
required: false | |
branch: | |
description: 'seleclt openwrt branch' | |
default: 'master' | |
required: false | |
jobs: | |
build_packages: | |
name: Build ${{ github.event.client_payload.device || github.event.inputs.device }} packages | |
runs-on: ubuntu-latest | |
env: | |
DEVICE: ${{ github.event.client_payload.device || github.event.inputs.device }} | |
BRANCH: ${{ github.event.client_payload.branch || github.event.inputs.branch }} | |
TG: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
if: github.repository_owner=='stupidloud' | |
steps: | |
- name: Space cleanup | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
run: | | |
nohup sh -c ' | |
sudo sysctl vm.swappiness=0 | |
sudo apt update; | |
sudo apt -y --no-install-recommends install pv jq \ | |
ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \ | |
bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext gcc-multilib g++-multilib \ | |
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 libreadline-dev libssl-dev libtool lrzsz \ | |
mkisofs msmtp nano ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 python3-pyelftools \ | |
libpython3-dev qemu-utils rsync scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip \ | |
vim wget xmlto xxd zlib1g-dev | |
' & | |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android/sdk /opt/hostedtoolcache | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 1 | |
- name: Checkout | |
run: | | |
cd | |
curl -sL https://raw.githubusercontent.com/stupidloud/nanopi-openwrt/zstd-bin/zstd | sudo tee /usr/bin/zstd > /dev/null | |
for i in {1..20} | |
do | |
curl -sL --fail https://github.com/stupidloud/sshactions/releases/download/cache/lede.$DEVICE.img.zst.0$i || break | |
done | zstdmt -d -o lede.img || (truncate -s 30g lede.img && mkfs.btrfs -M lede.img) | |
LOOP_DEVICE=$(losetup -f) && echo "LOOP_DEVICE=$LOOP_DEVICE" >> $GITHUB_ENV | |
sudo losetup -P --direct-io $LOOP_DEVICE lede.img | |
mkdir lede && sudo mount -o nossd,compress=zstd $LOOP_DEVICE lede | |
if [ -d 'lede/.git' ]; then | |
cd lede && rm -f zerospace && git config --local user.email "action@github.com" && git config --local user.name "GitHub Action" | |
git fetch && git reset --hard origin/$BRANCH && git clean -df | |
else | |
sudo chown $USER:$(id -gn) lede && git clone -b $BRANCH --single-branch https://github.com/coolsnowwolf/lede lede | |
fi | |
- name: Update feeds and packages | |
run: | | |
cd ~/lede | |
rm -rf ./tmp && rm -rf ./feeds && rm -rf ./pacakges/feeds | |
if [ -d 'feeds' ]; then | |
pushd feeds/packages; git restore .; popd | |
pushd feeds/luci; git restore .; popd | |
pushd feeds/routing; git restore .; popd | |
pushd feeds/telephony; git restore .; popd | |
fi | |
./scripts/feeds update -a | |
./scripts/feeds install -a | |
. $GITHUB_WORKSPACE/scripts/merge_packages.sh | |
. $GITHUB_WORKSPACE/scripts/patches.sh | |
cd | |
svn export https://github.com/openwrt/luci/branches/master luci | |
pushd luci | |
ls -d */ | xargs -ri diff -q {} ../lede/feeds/luci/{} | grep Only | grep lede | grep -E applications\|themes | awk '{print $4}' | xargs -ri echo CONFIG_PACKAGE_{}=m > ~/lede/more_luci.txt | |
popd | |
- name: Custom configure file | |
run: | | |
cd ~/lede && rm -rf tmp/ | |
cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | sed 's/\(CONFIG_PACKAGE_luci-app-[^A-Z]*=\)y/\1m/' > .config | |
find package/ -type d -name luci-app-* | rev | cut -d'/' -f1 | rev | xargs -ri echo CONFIG_PACKAGE_{}=m >> .config | |
cat $GITHUB_WORKSPACE/extra_packages.seed >> .config | |
cat more_luci.txt >> .config | |
make defconfig && sed -i -E 's/# (CONFIG_.*_COMPRESS_UPX) is not set/\1=y/' .config && make defconfig | |
cat .config | |
- name: Debug via tmate | |
uses: stupidloud/ssh2actions@main | |
if: ${{ github.event.client_payload.debug == 'true' }} | |
with: | |
mode: ssh | |
env: | |
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | |
SSH_PASSWORD: ${{secrets.SSH_PASSWORD}} | |
SSH_PUBKEY: ${{secrets.SSH_PUBKEY}} | |
TUNNEL_KEY: ${{secrets.TUNNEL_KEY}} | |
TUNNEL_HOST: ${{secrets.TUNNEL_HOST}} | |
- name: Clean build cache | |
if: ${{ github.event.client_payload.package_clean == 'true' || github.event.inputs.device != '' }} | |
run: | | |
cd ~/lede | |
df -h . | |
make clean || true | |
df -h . | |
- name: Build and deploy packages | |
timeout-minutes: 1440 | |
run: | | |
ulimit -SHn 65000 | |
cd ~/lede | |
while true; do make download -j && break || true; done | |
make -j$[`nproc`+1] IGNORE_ERRORS=1 tools/compile toolchain/compile buildinfo target/compile package/compile package/install target/install | |
if [ ! -e ~/lede/bin/targets/*/*/*imagebuilder*xz ]; then make IGNORE_ERRORS=1 V=sc; fi | |
mv `ls ~/lede/bin/targets/*/*/*imagebuilder*xz` ~/ib-$DEVICE.tar.xz | |
echo "=======================" | |
echo "Space usage:" | |
echo "=======================" | |
df -h | |
echo "=======================" | |
du -h --max-depth=1 ./ --exclude=build_dir --exclude=bin | |
du -h --max-depth=1 ./build_dir | |
du -h --max-depth=1 ./bin | |
- name: Prepare artifact | |
run: | | |
cd | |
mkdir -p ./artifact/buildinfo | |
cd lede | |
cp -rf $(find ./bin/targets/ -type f -name "*.buildinfo" -o -name "*.manifest") ../artifact/buildinfo/ | |
cp -rf .config ../artifact/buildinfo/ | |
echo "strDate=$(TZ=UTC-8 date +%Y-%m-%d)" >> $GITHUB_ENV | |
echo "strDevice=$(echo $DEVICE | awk '{print toupper($0)}')" >> $GITHUB_ENV | |
cd .. | |
mv artifact $GITHUB_WORKSPACE | |
- name: Clean build cache | |
if: ${{ github.event.client_payload.package_clean == 'true' }} | |
run: | | |
cd ~/lede | |
df -h . | |
make clean | |
rm -rf bin tmp | |
df -h . | |
- name: Deliver buildinfo | |
uses: actions/upload-artifact@v2 | |
with: | |
name: OpenWrt_buildinfo | |
path: ./artifact/buildinfo/ | |
- name: Save cache state | |
if: env.TG | |
run: | | |
cd | |
sleep 60 | |
sudo mount -o remount,compress=no,nodatacow,nodatasum lede | |
cd lede/; pv /dev/zero > zerospace || true; sync; rm -f zerospace; cd - | |
sleep 60 | |
sudo umount lede | |
sudo losetup -d $LOOP_DEVICE | |
export AUTH="Authorization: token ${{ secrets.SEC_TOKEN }}" | |
export cache_path='github.com/repositories/233224580/releases' | |
export cache_repo_id='39020554' | |
#zstdmt -c --adapt --long lede.img | parallel --wc --block 1.99G --pipe \ | |
#'curl -s --data-binary @- -H "$AUTH" -H "Content-Type: application/octet-stream" https://uploads.$cache_path/$cache_repo_id/assets?name=lede.'$DEVICE'.img.zst.0{#} > /dev/null' | |
zstdmt -c --long lede.img | split --numeric=1 -b 2000m - lede.$DEVICE.img.zst. | |
#for f in *img.zst* | |
#do | |
# while true; do curl --data-binary @$f -H "$AUTH" -H 'Content-Type: application/octet-stream' "https://uploads.$cache_path/$cache_repo_id/assets?name=$f" && break || true; done | |
#done | |
while true; do | |
ret=$(curl -sH "$AUTH" "https://api.$cache_path/tags/cache") | |
echo $ret | jq -r '.assets[] | select(.name | contains ("'$DEVICE'.img")).id' | \ | |
xargs -ri curl -X DELETE -H "$AUTH" "https://api.$cache_path/assets/{}" | |
echo $ret | jq -r '.assets[] | select(.name == "ib-'$DEVICE'.tar.xz").id' | \ | |
xargs -ri curl -X DELETE -H "$AUTH" "https://api.$cache_path/assets/{}" | |
ls *img.zst* ib-$DEVICE.tar.xz | parallel --wc 'while true; do curl -T {} -H "$AUTH" -H "Content-Type: application/octet-stream" "https://uploads.$cache_path/$cache_repo_id/assets?name={}" && break || true; done' | |
set +e | |
for i in {1..20}; do curl -sL --fail https://github.com/stupidloud/sshactions/releases/download/cache/lede.$DEVICE.img.zst.0$i || break; done | zstdmt -d -o /dev/null | |
if [ $? -eq 0 ]; then break; fi | |
done | |
set -e | |
- name: Send tg notification | |
if: env.TG | |
run: | | |
curl -k --data chat_id="${{secrets.TELEGRAM_CHAT_ID}}" --data "text=The ${{env.DEVICE}} build ran completed at ${{job.status}}." "https://api.telegram.org/bot${{secrets.TELEGRAM_BOT_TOKEN}}/sendMessage" | |
- name: Debug via tmate | |
uses: stupidloud/ssh2actions@main | |
if: ${{ failure() && env.TG }} | |
with: | |
mode: ssh | |
env: | |
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | |
SSH_PASSWORD: ${{secrets.SSH_PASSWORD}} | |
SSH_PUBKEY: ${{secrets.SSH_PUBKEY}} | |
TUNNEL_KEY: ${{secrets.TUNNEL_KEY}} | |
TUNNEL_HOST: ${{secrets.TUNNEL_HOST}} | |
generate_slim_firmware: | |
needs: build_packages | |
name: Generate ${{ github.event.client_payload.device || github.event.inputs.device }} slim firmware | |
runs-on: ubuntu-latest | |
env: | |
DEVICE: ${{ github.event.client_payload.device || github.event.inputs.device }} | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 1 | |
- name: Generate firmware | |
run: | | |
sudo apt update && sudo apt install qemu-utils | |
sudo sysctl vm.swappiness=0 | |
ulimit -SHn 65000 | |
curl -L https://github.com/stupidloud/sshactions/releases/download/cache/ib-$DEVICE.tar.xz | tar -Jxvf - | |
mv *imagebuilder* ib && cd ib | |
. $GITHUB_WORKSPACE/scripts/merge_files.sh | |
mkdir -p files/local_feed && sudo mount --bind packages files/local_feed | |
sed -i 's/luci-app-[^ ]*//g' include/target.mk $(find target/ -name Makefile) | |
sed -i 's/$(OPKG) install $(BUILD_PACKAGES)/$(OPKG) install --force-overwrite $(BUILD_PACKAGES)/' Makefile | |
ls packages/*.ipk | xargs -n1 basename > package.files | |
PACKAGES=$(cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep CONFIG_PACKAGE | grep '=y' | grep -v CONFIG_PACKAGE_luci-app | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -ri grep -o {} package.files | sort -u | xargs echo) | |
PACKAGES="$PACKAGES `grep -o luci-i18n-opkg-zh-cn package.files || true`" | |
make image PACKAGES="$PACKAGES $LUCI $LP luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn" FILES="files" | |
mkdir -p $GITHUB_WORKSPACE/release | |
mv $(ls -1 ./bin/targets/*/*/*img.gz | head -1) $GITHUB_WORKSPACE/release/$DEVICE-slim.img.gz | |
cd $GITHUB_WORKSPACE/release/ && md5sum $DEVICE-slim.img.gz > $DEVICE-slim.img.gz.md5 | |
gzip -dc $DEVICE-slim.img.gz | md5sum | sed "s/-/$DEVICE-slim.img/" > $DEVICE-slim.img.md5 | |
echo "strDate=$(TZ=UTC-8 date +%Y-%m-%d)" >> $GITHUB_ENV | |
echo "strDevice=$(echo $DEVICE | awk '{print toupper($0)}')" >> $GITHUB_ENV | |
- name: Upload release asset | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: ./release/* | |
tag: ${{env.strDate}} | |
file_glob: true | |
overwrite: true | |
release_name: ${{env.strDate}} 自动发布 | |
generate_firmware: | |
needs: build_packages | |
if: always() | |
name: Generate ${{ github.event.client_payload.device || github.event.inputs.device }} firmware | |
runs-on: ubuntu-latest | |
env: | |
DEVICE: ${{ github.event.client_payload.device || github.event.inputs.device }} | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 1 | |
- name: Generate firmware | |
run: | | |
sudo apt update && sudo apt install qemu-utils | |
sudo sysctl vm.swappiness=0 | |
ulimit -SHn 65000 | |
curl -L https://github.com/stupidloud/sshactions/releases/download/cache/ib-$DEVICE.tar.xz | tar -Jxvf - | |
set -x | |
mv *imagebuilder* ib && cd ib | |
. $GITHUB_WORKSPACE/scripts/merge_files.sh | |
sed -i '/local/d;s/#//' files/etc/opkg/distfeeds.conf | |
sed -i 's/luci-app-[^ ]*//g' include/target.mk $(find target/ -name Makefile) | |
sed -i 's/$(OPKG) install $(BUILD_PACKAGES)/$(OPKG) install --force-overwrite $(BUILD_PACKAGES)/' Makefile | |
ls packages/*.ipk | xargs -n1 basename > package.files | |
PACKAGES=$(cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep CONFIG_PACKAGE | grep '=y' | grep -v CONFIG_PACKAGE_luci-app | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -ri grep -o {} package.files | sort -u | xargs echo) | |
PACKAGES="$PACKAGES `grep -o luci-i18n-opkg-zh-cn package.files || true`" | |
LUCI=$(cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep CONFIG_PACKAGE_luci-app | grep '=y' | grep -v docker | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -ri grep -o {} package.files | sort -u | xargs echo) | |
LP=$(echo $LUCI | sed 's/-app-/-i18n-/g;s/ /\n/g' | xargs -ri grep -o {}-zh-cn package.files | xargs echo) | |
make image PACKAGES="$PACKAGES $LUCI $LP luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn" FILES="files" | |
mkdir -p $GITHUB_WORKSPACE/release | |
mv $(ls -1 ./bin/targets/*/*/*img.gz | head -1) $GITHUB_WORKSPACE/release/$DEVICE.img.gz | |
cd $GITHUB_WORKSPACE/release/ && md5sum $DEVICE.img.gz > $DEVICE.img.gz.md5 | |
gzip -dc $DEVICE.img.gz | md5sum | sed "s/-/$DEVICE.img/" > $DEVICE.img.md5 | |
echo "strDate=$(TZ=UTC-8 date +%Y-%m-%d)" >> $GITHUB_ENV | |
echo "strDevice=$(echo $DEVICE | awk '{print toupper($0)}')" >> $GITHUB_ENV | |
if [[ ${{ github.event.client_payload.device || github.event.inputs.device }} == *"r1s"* ]]; then | |
exit 0 | |
fi | |
cd $GITHUB_WORKSPACE/ib | |
rm -rf bin/ | |
LUCI=$(cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep CONFIG_PACKAGE_luci-app | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -ri grep -o {} package.files | sort -u | xargs echo) | |
LP=$(echo $LUCI | sed 's/-app-/-i18n-/g;s/ /\n/g' | xargs -ri grep -o {}-zh-cn package.files | xargs echo | xargs echo) | |
make image PACKAGES="$PACKAGES $LUCI $LP luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn" FILES="files" | |
mv $(ls -1 ./bin/targets/*/*/*img.gz | head -1) $GITHUB_WORKSPACE/release/$DEVICE-with-docker.img.gz | |
cd $GITHUB_WORKSPACE/release/ && md5sum $DEVICE-with-docker.img.gz > $DEVICE-with-docker.img.gz.md5 | |
gzip -dc $DEVICE-with-docker.img.gz | md5sum | sed "s/-/$DEVICE-with-docker.img/" > $DEVICE-with-docker.img.md5 | |
- name: Upload release asset | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: ./release/* | |
tag: ${{env.strDate}} | |
file_glob: true | |
overwrite: true | |
release_name: ${{env.strDate}} 自动发布 |