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 }} TG: ${{ secrets.TELEGRAM_BOT_TOKEN }} DEPLOY_SSHKEY: ${{ secrets.SSH_KEY }} if: github.repository_owner=='klever1988' steps: - name: Space cleanup env: DEBIAN_FRONTEND: noninteractive run: | sudo sysctl vm.swappiness=0 nohup sudo rm -rf /usr/share/dotnet /usr/local/lib/android/sdk & sudo -E apt update nohup sudo -E apt -y --no-install-recommends install jq build-essential 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 python python3 python3-pip python-ply python3-ply haveged lrzsz device-tree-compiler scons antlr3 gperf intltool rsync swig & - uses: actions/checkout@v2 with: fetch-depth: 1 - name: Checkout run: | cd sudo 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 20g 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 && git config --local user.email "action@github.com" && git config --local user.name "GitHub Action" git remote set-branches --add origin openwrt-18.06 git fetch && git reset --hard origin/openwrt-18.06-k5.4 && git merge -X theirs --no-edit origin/openwrt-18.06 else sudo chown $USER:$(id -gn) lede && (cd lede && git init && git remote add -t openwrt-18.06-k5.4 -f origin https://github.com/immortalwrt/immortalwrt && git checkout openwrt-18.06-k5.4) 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 fi ./scripts/feeds update -a ./scripts/feeds install -a . $GITHUB_WORKSPACE/patches.sh . $GITHUB_WORKSPACE/merge_packages.sh rm -rf package/base; mkdir -p package/base; cd ../ svn export https://github.com/openwrt/packages/branches/openwrt-18.06 packages pushd packages ls -d */ | xargs -n1 -i diff -q {} ../lede/feeds/packages/{} | grep Only | grep lede | grep -v -E lang\|devel\|ovn | awk '{print $3 $4}' | tr -d ':' | xargs -n1 -i mv {} ../lede/package/base/ sed -i 's/include ..\/..\//include $(TOPDIR)\/feeds\/packages\//' ../lede/package/base/*/Makefile ../lede/feeds/packages/devel/ninja/ninja-cmake.mk popd svn export https://github.com/openwrt/luci/branches/openwrt-18.06 luci pushd luci ls -d */ | xargs -n1 -i diff -q {} ../lede/feeds/luci/{} | grep Only | grep lede | grep -E applications\|themes | awk '{print $3 $4}' | tr -d ':' | xargs -n1 -i mv {} ../lede/package/base/ sed -i 's/include ..\/..\//include $(TOPDIR)\/feeds\/luci\//' ../lede/package/base/luci-*/Makefile popd sed -i 's/..\/..\//$(TOPDIR)\/feeds\/packages\//' package/feeds/packages/baidupcs-web/Makefile sed -i 's/..\/..\//$(TOPDIR)\/feeds\/packages\//' package/feeds/packages/filebrowser/Makefile - name: Custom configure file run: | cd ~/lede cat $GITHUB_WORKSPACE/$DEVICE.config.seed | sed '/CONFIG_PACKAGE_luci-app-/d' > .config - name: Build and deploy packages run: | cd ~/lede if [ ! -d build_dir ]; then if [[ $DEVICE =~ ('r2s'|'r4s') ]]; then sdk_src='https://downloads.openwrt.org/snapshots/targets/rockchip/armv8/openwrt-sdk-rockchip-armv8_gcc-8.4.0_musl.Linux-x86_64.tar.xz' elif [[ $DEVICE == 'r1s' ]]; then sdk_src='https://downloads.openwrt.org/snapshots/targets/sunxi/cortexa53/openwrt-sdk-sunxi-cortexa53_gcc-8.4.0_musl.Linux-x86_64.tar.xz' elif [ $DEVICE == 'r1s-h3' ]; then sdk_src='https://downloads.openwrt.org/snapshots/targets/sunxi/cortexa7/openwrt-sdk-sunxi-cortexa7_gcc-8.4.0_musl_eabi.Linux-x86_64.tar.xz' fi mkdir sdk && wget -qO- $sdk_src | tar -xJf - -C sdk rm -rf build_dir staging_dir; mv sdk/*/build_dir ./ && rsync -a --ignore-existing sdk/*/staging_dir/ ./staging_dir/ rm -rf sdk fi sed -i '/182.140.223.146/d' scripts/download.pl sed -i '/\.cn\//d' scripts/download.pl sed -i '/tencent/d' scripts/download.pl make defconfig && make tools/upx/compile -j$(($(nproc) + 1)) sed -i '/\(tools\|toolchain\)\/Makefile/d' Makefile cat $GITHUB_WORKSPACE/extra_packages.seed >> .config echo -e '# CONFIG_SIGNED_PACKAGES is not set\n' >> .config find package/ -type d -name luci-app-* | rev | cut -d'/' -f1 | rev | xargs -n1 -i echo CONFIG_PACKAGE_{}=y >> .config find feeds/luci/applications -type d -name luci-app-* | rev | cut -d'/' -f1 | rev | xargs -n1 -i echo CONFIG_PACKAGE_{}=y >> .config make defconfig && cat .config while true; do make download -j && break || true; done make target/linux/compile -j$(($(nproc) + 1)) make package/compile -j$(($(nproc) + 1)) IGNORE_ERRORS=y make package/index sed -i "s/\-[a-z0-9]\{32\})/)/" bin/targets/*/*/packages/Packages bin/targets/*/*/packages/Packages.manifest gzip -f bin/targets/*/*/packages/Packages cat $GITHUB_WORKSPACE/$DEVICE.config.seed | sed '/CONFIG_PACKAGE_luci-app-/d' > .config echo -e '# CONFIG_SIGNED_PACKAGES is not set\n' >> .config find package/ -type d -name luci-app-* | rev | cut -d'/' -f1 | rev | xargs -n1 -i echo "# CONFIG_PACKAGE_{} is not set" >> .config find feeds/luci/applications -type d -name luci-app-* | rev | cut -d'/' -f1 | rev | xargs -n1 -i echo "# CONFIG_PACKAGE_{} is not set" >> .config make defconfig mkdir -p files/local_feed/core files/local_feed/base files/local_feed/luci sudo mount --bind bin/targets/*/*/packages/ files/local_feed/core sudo mount --bind bin/packages/*/base/ files/local_feed/base sudo mount --bind bin/packages/*/luci/ files/local_feed/luci pushd bin/ && . ../files/etc/opkg/distfeeds.conf | tee ../files/etc/opkg/distfeeds.conf && popd make -j$(($(nproc) + 1)) sudo umount files/local_feed/core files/local_feed/base files/local_feed/luci rm files/etc/opkg/distfeeds.conf 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 mkdir -p ./release cd lede cp -rf $(find ./bin/targets/ -type f -name "*.buildinfo" -o -name "*.manifest") ../artifact/buildinfo/ cp -rf .config ../artifact/buildinfo/ mv $(ls -1 ./bin/targets/*/*/*img.gz) ../release/$DEVICE-slim.img.gz 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 release $GITHUB_WORKSPACE cd $GITHUB_WORKSPACE/release/ && md5sum $DEVICE-slim.img.gz > $DEVICE-slim.img.md5 - name: Deliver buildinfo uses: actions/upload-artifact@v2 with: name: OpenWrt_buildinfo path: ./artifact/buildinfo/ - 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}} 自动发布 - name: Save cache state if: env.TG run: | cd sleep 120 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/{}" #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 - name: Send tg notification uses: appleboy/telegram-action@master if: env.TG with: to: ${{ secrets.TELEGRAM_CHAT_ID }} token: ${{ secrets.TELEGRAM_BOT_TOKEN }} args: The ${{env.DEVICE}} build ran completed at ${{job.status}}. - name: Debug via tmate uses: klever1988/ssh2actions@main if: ${{ failure() && env.TG }} with: mode: ngrok 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.NGROK_TOKEN}} 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 sysctl vm.swappiness=0 nohup sudo rm -rf /usr/share/dotnet /usr/local/lib/android/sdk & cd sudo 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 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 cd lede cat $GITHUB_WORKSPACE/$DEVICE.config.seed > .config echo -e '# CONFIG_SIGNED_PACKAGES is not set\n' >> .config make defconfig && make -j$(($(nproc) + 1)) mkdir -p $GITHUB_WORKSPACE/release mv $(ls -1 ./bin/targets/*/*/*img.gz) $GITHUB_WORKSPACE/release/$DEVICE.img.gz cd $GITHUB_WORKSPACE/release/ && md5sum $DEVICE.img.gz > $DEVICE.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}} 自动发布 - name: Debug via tmate uses: klever1988/ssh2actions@main if: ${{ failure() }} with: mode: ngrok 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.NGROK_TOKEN}}