nanopi-openwrt/.github/workflows/lo-test.yml

285 lines
14 KiB
YAML

name: build
on:
repository_dispatch:
workflow_dispatch:
inputs:
device:
description: 'select device to build'
default: 'r2s'
required: false
jobs:
build_packages:
name: Build ${{ github.event.client_payload.device || github.event.inputs.device }} packages
runs-on: ubuntu-18.04
env:
DEVICE: ${{ github.event.client_payload.device || github.event.inputs.device }}
BRANCH: ${{ github.event.client_payload.branch }}
TG: ${{ secrets.TELEGRAM_BOT_TOKEN }}
if: github.repository_owner=='klever1988'
steps:
- name: Space cleanup
env:
DEBIAN_FRONTEND: noninteractive
run: |
nohup sh -c '
sudo apt update;
sudo apt -y --no-upgrade --no-install-recommends install pv jq build-essential cmake asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib g++-multilib p7zip p7zip-full msmtp libssl-dev texinfo libreadline-dev libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint ccache curl wget vim nano python2.7 python3 python3-pip python-ply python3-ply haveged lrzsz device-tree-compiler scons antlr3 gperf intltool mkisofs rsync swig
sudo rm -rf /usr/share/dotnet /usr/local/lib/android/sdk
sudo sysctl vm.swappiness=0
' &
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Checkout
run: |
cd
curl -sL https://raw.githubusercontent.com/klever1988/nanopi-openwrt/zstd-bin/zstd | sudo tee /usr/bin/zstd > /dev/null
for i in {1..10}
do
curl -sL --fail https://github.com/klever1988/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
[ $BRANCH != 'master' ] && BRANCH='openwrt-18.06-k5.4'
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
else
sudo chown $USER:$(id -gn) lede && git clone -b $BRANCH --single-branch https://github.com/immortalwrt/immortalwrt lede
fi
- name: Update feeds and packages
run: |
cd ~/lede
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/merge_packages.sh
. $GITHUB_WORKSPACE/patches.sh
cd
[ $BRANCH != 'master' ] && BRANCH='openwrt-18.06'
svn export https://github.com/openwrt/luci/branches/$BRANCH luci
echo > more_luci.txt
pushd luci
ls -d */ | xargs -n1 -i diff -q {} ../lede/feeds/luci/{} | grep Only | grep lede | grep -E applications\|themes | awk '{print $4}' | xargs -n1 -i echo CONFIG_PACKAGE_{}=m >> ~/lede/more_luci.txt
popd
- name: Custom configure file
run: |
cd ~/lede
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 -n1 -i echo CONFIG_PACKAGE_{}=m >> .config
cat $GITHUB_WORKSPACE/extra_packages.seed >> .config
cat more_luci.txt >> .config
make defconfig && cat .config
- name: Clean build cache
if: ${{ github.event.client_payload.package_clean == 'true' }}
run: |
cd ~/lede
df -h .
make package/clean
df -h .
- name: Build and deploy packages
run: |
cd ~/lede
while true; do make download -j && break || true; done
make -j$[`nproc`+1] IGNORE_ERRORS=1
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: Clean build cache
if: ${{ github.event.client_payload.package_clean == 'true' }}
run: |
cd ~/lede
df -h .
make package/clean
df -h .
- 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
rm -rf bin tmp
cd ..
mv artifact $GITHUB_WORKSPACE
- 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/repos/klever1988/sshactions/releases'
export cache_repo_id='39020554'
ret=$(curl -sH "$AUTH" "https://api.$cache_path/tags/cache")
echo $ret | jq -r '.assets[] | select(.name | contains ("'$DEVICE'.img")).id' | \
xargs -n1 -i curl -X DELETE -H "$AUTH" "https://api.$cache_path/assets/{}"
echo $ret | jq -r '.assets[] | select(.name == "ib-'$DEVICE'.tar.xz").id' | \
xargs -n1 -i curl -X DELETE -H "$AUTH" "https://api.$cache_path/assets/{}"
#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
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'
- 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: klever1988/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}}
NGROK_TOKEN: ${{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-18.04
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
curl -L https://github.com/klever1988/sshactions/releases/download/cache/ib-$DEVICE.tar.xz | tar -Jxvf -
mv *imagebuilder* ib && cd ib
. $GITHUB_WORKSPACE/merge_files.sh
mkdir -p files/local_feed && sudo mount --bind packages files/local_feed
sed -i '/luci-lib-base/d;/luci-lib-ipkg/d' include/target.mk
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
PACKAGES=$(cd packages; cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep CONFIG_PACKAGE | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -n1 -i sh -c 'ls {}* 2>/dev/null' | grep -v luci-app | sed 's/\([^_]*\)_.*ipk/\1/g' | 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-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-18.04
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
curl -L https://github.com/klever1988/sshactions/releases/download/cache/ib-$DEVICE.tar.xz | tar -Jxvf -
mv *imagebuilder* ib && cd ib
. $GITHUB_WORKSPACE/merge_files.sh
sed -i '/local/d;s/#//' files/etc/opkg/distfeeds.conf
sed -i '/luci-lib-base/d;/luci-lib-ipkg/d' include/target.mk
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
PACKAGES=$(cd packages; cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep CONFIG_PACKAGE | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -n1 -i sh -c 'ls {}_* 2>/dev/null' | grep -v luci-app | sed 's/\([^_]*\)_.*ipk/\1/g' | xargs echo)
LUCI=$(cd packages; cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep luci-app | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -n1 -i sh -c 'ls {}_* 2>/dev/null' | grep -v docker | sed 's/\([^_]*\)_.*ipk/\1/g' | xargs echo)
LP=$(cd packages; echo $LUCI | sed 's/-app-/-i18n-/g;s/ /\n/g' | xargs -n1 -i sh -c 'ls {}-zh-cn* 2>/dev/null' | sed 's/zh-.*.ipk/zh-cn/' | 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=$(cd packages; cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep luci-app | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -n1 -i sh -c 'ls {}_* 2>/dev/null' | sed 's/\([^_]*\)_.*ipk/\1/g' | xargs echo)
LP=$(cd packages; echo $LUCI | sed 's/-app-/-i18n-/g;s/ /\n/g' | xargs -n1 -i sh -c 'ls {}-zh-cn* 2>/dev/null' | sed 's/zh-.*.ipk/zh-cn/' | 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}} 自动发布